18 #ifndef VCSN_XML_HANDLERS_HXX
19 # define VCSN_XML_HANDLERS_HXX
21 # include <xercesc/util/XMLString.hpp>
33 DocRegExpHandler<T>::DocRegExpHandler (xercesc::SAX2XMLReader* parser,
34 xercesc::DefaultHandler& root,
37 : Handler(parser, root, eq),
39 regexph_(parser, *this, regexp)
45 DocRegExpHandler<T>::start (
const XMLCh*
const,
46 const XMLCh*
const localname,
48 const xercesc::Attributes&)
50 using namespace xercesc;
51 if (XMLString::equals(eq_.fsmxml, localname))
55 parser_->setContentHandler(®exph_);
58 error::token(localname);
63 DocRegExpHandler<T>::end (
const XMLCh*
const,
73 DocAutHandler<T>::DocAutHandler (xercesc::SAX2XMLReader* parser,
74 xercesc::DefaultHandler& root,
77 : Handler(parser, root, eq),
79 auth_(parser, *this, aut)
85 DocAutHandler<T>::start (
const XMLCh*
const,
86 const XMLCh*
const localname,
88 const xercesc::Attributes&)
90 using namespace xercesc;
91 if (XMLString::equals(eq_.fsmxml, localname))
95 parser_->setContentHandler(&auth_);
98 error::token(localname);
101 template <
typename T>
103 DocAutHandler<T>::end (
const XMLCh*
const,
112 template <
typename T>
116 : Handler(parser, root),
118 typeh_(parser, *this, regexp),
119 contenth_(parser, *this, regexp, eq_.typedRegExp),
120 unsuph_(parser, *this)
124 template <
typename T>
127 const XMLCh*
const localname,
129 const xercesc::Attributes& attrs)
131 using namespace xercesc;
132 if (XMLString::equals(eq_.regExp, localname))
136 else if (XMLString::equals(eq_.drawing, localname))
137 parser_->setContentHandler(&unsuph_);
138 else if (XMLString::equals(eq_.geometry, localname))
139 parser_->setContentHandler(&unsuph_);
140 else if (XMLString::equals(eq_.valueType, localname))
141 parser_->setContentHandler(&typeh_);
142 else if (XMLString::equals(eq_.typedRegExp, localname))
144 contenth_.series(regexp_);
145 parser_->setContentHandler(&contenth_);
148 error::token(localname);
151 template <
typename T>
153 RegExpHandler<T>::end (
const XMLCh*
const,
154 const XMLCh*
const localname,
157 using namespace xercesc;
158 if (XMLString::equals(eq_.regExp, localname))
160 parser_->setContentHandler(&root_);
161 regexp_ = contenth_.series();
168 template <
typename T>
172 : Handler(parser, root),
174 typeh_(parser, *this, aut),
175 contenth_(parser, *this, aut),
176 unsuph_(parser, *this)
180 template <
typename T>
183 const XMLCh*
const localname,
185 const xercesc::Attributes& attrs)
187 using namespace xercesc;
188 if (XMLString::equals(eq_.automaton, localname))
190 const XMLCh* autname = tools::get_attribute(attrs,
"name", uri);
192 aut_.geometry().name() = xmlstr(autname);
195 else if (XMLString::equals(eq_.drawing, localname))
196 parser_->setContentHandler(&unsuph_);
197 else if (XMLString::equals(eq_.geometry, localname))
198 parser_->setContentHandler(&unsuph_);
199 else if (XMLString::equals(eq_.valueType, localname))
200 parser_->setContentHandler(&typeh_);
201 else if (XMLString::equals(eq_.content, localname))
202 parser_->setContentHandler(&contenth_);
204 error::token(localname);
207 template <
typename T>
209 AutHandler<T>::end (
const XMLCh*
const,
210 const XMLCh*
const localname,
213 using namespace xercesc;
214 if (XMLString::equals(eq_.automaton, localname))
215 parser_->setContentHandler(&root_);
221 template <
typename T>
225 : Handler(parser, root),
233 unsuph_(parser, *this)
237 template <
typename T>
240 const XMLCh*
const localname,
242 const xercesc::Attributes& attrs)
244 using namespace xercesc;
246 if (XMLString::equals(eq_.semiring, localname))
248 semiring_ = builders::create_semiring(param_, localname, attrs);
249 semiringh_ = builders::create_semiringh(*semiring_, attrs, parser_, *
this);
250 parser_->setContentHandler(semiringh_);
252 else if (XMLString::equals(eq_.monoid, localname))
254 monoid_ = builders::create_monoid(param_, localname, attrs, eq_);
255 monoidh_ = builders::create_monoidh(*monoid_, attrs, parser_, *
this);
256 parser_->setContentHandler(monoidh_);
258 else if (XMLString::equals(eq_.writingData, localname))
260 rep_ = builders::create_series_representation(param_, localname, attrs, eq_);
261 reph_ = builders::create_series_representationh(*rep_, attrs, parser_, *
this, eq_);
262 parser_->setContentHandler(reph_);
265 error::token(localname);
268 template <
typename T>
270 TypeHandler<T>::end(
const XMLCh*
const,
271 const XMLCh*
const localname,
274 using namespace xercesc;
280 typename T::series_set_t series(*semiring_, *monoid_, *rep_);
281 param_.attach(series);
285 typename T::series_set_t series(*semiring_, *monoid_);
286 param_.attach(series);
289 if (XMLString::equals(eq_.valueType, localname))
290 parser_->setContentHandler(&root_);
303 template <
typename T>
307 : Handler(parser, root),
309 statesh_(parser, *this, aut, map_),
310 transitionsh_(parser, *this, aut, map_)
314 template <
typename T>
317 const XMLCh*
const localname,
319 const xercesc::Attributes&)
321 using namespace xercesc;
322 if (XMLString::equals(eq_.states, localname))
323 parser_->setContentHandler(&statesh_);
324 else if (XMLString::equals(eq_.transitions, localname))
325 parser_->setContentHandler(&transitionsh_);
327 error::token(localname);
330 template <
typename T>
332 ContHandler<T>::end (
const XMLCh*
const,
333 const XMLCh*
const localname,
336 using namespace xercesc;
337 if (XMLString::equals(eq_.content, localname))
338 parser_->setContentHandler(&root_);
340 error::token(localname);
346 template <
typename T>
351 : Handler(parser, root),
358 template <
typename T>
361 const XMLCh*
const localname,
363 const xercesc::Attributes& attrs)
365 using namespace xercesc;
366 if (XMLString::equals(eq_.state, localname))
368 hstate_t state = aut_.add_state();
369 map_[xmlstr(tools::get_attribute(attrs, eq_.id))] = state;
372 parser_->setContentHandler(stateh_);
375 error::token(localname);
378 template <
typename T>
380 StatesHandler<T>::end (
const XMLCh*
const,
381 const XMLCh*
const localname,
384 using namespace xercesc;
385 if (XMLString::equals(eq_.states, localname))
386 parser_->setContentHandler(&root_);
388 error::token(localname);
395 template <
typename T>
400 : Handler(parser, root),
403 geometryh_(parser, *this, aut, state),
404 unsuph_(parser, *this)
408 template <
typename T>
411 const XMLCh*
const localname,
413 const xercesc::Attributes& attrs)
415 using namespace xercesc;
416 if (XMLString::equals(eq_.drawing, localname))
417 parser_->setContentHandler(&unsuph_);
418 else if (XMLString::equals(eq_.geometry, localname))
420 typedef typename T::geometry_t::states_geometry_map_t gmap_t;
424 if (tools::has_attribute(attrs, eq_.x))
426 std::istringstream xstr(xmlstr(tools::get_attribute(attrs, eq_.x)));
429 if (tools::has_attribute(attrs, eq_.y))
431 std::istringstream ystr(xmlstr(tools::get_attribute(attrs, eq_.y)));
434 gmap_t& map = aut_.geometry().states();
435 map[state_] = std::make_pair(x,y);
436 parser_->setContentHandler(&geometryh_);
439 error::token(localname);
442 template <
typename T>
444 StateHandler<T>::end (
const XMLCh*
const,
445 const XMLCh*
const localname,
448 using namespace xercesc;
449 if (XMLString::equals(eq_.state, localname))
450 parser_->setContentHandler(&root_);
452 error::token(localname);
458 template <
typename T>
463 : Handler(parser, root),
470 template <
typename T>
473 const XMLCh*
const localname,
475 const xercesc::Attributes& attrs)
477 using namespace xercesc;
478 if (XMLString::equals(eq_.transition, localname))
480 hstate_t src = map_[xmlstr(tools::get_attribute(attrs, eq_.source))];
481 hstate_t dst = map_[xmlstr(tools::get_attribute(attrs, eq_.target))];
484 parser_->setContentHandler(transitionh_);
486 else if (XMLString::equals(eq_.final, localname))
488 hstate_t state = map_[xmlstr(tools::get_attribute(attrs, eq_.state))];
490 transitionh_ =
new InitFinalHandler<T>(parser_, *
this, aut_, state,
false);
491 parser_->setContentHandler(transitionh_);
493 else if (XMLString::equals(eq_.initial, localname))
495 hstate_t state = map_[xmlstr(tools::get_attribute(attrs, eq_.state))];
497 transitionh_ =
new InitFinalHandler<T>(parser_, *
this, aut_, state,
true);
498 parser_->setContentHandler(transitionh_);
501 error::token(localname);
504 template <
typename T>
506 TransitionsHandler<T>::end (
const XMLCh*
const,
507 const XMLCh*
const localname,
510 using namespace xercesc;
511 if (XMLString::equals(eq_.transitions, localname))
512 parser_->setContentHandler(&root_);
514 error::token(localname);
521 template <
typename T>
527 : Handler(parser, root),
532 labelh_(parser, *this, s_, eq_.label),
533 unsuph_(parser, *this)
537 template <
typename T>
540 const XMLCh*
const localname,
542 const xercesc::Attributes&)
544 using namespace xercesc;
545 if (XMLString::equals(eq_.drawing, localname))
546 parser_->setContentHandler(&unsuph_);
547 else if (XMLString::equals(eq_.geometry, localname))
548 parser_->setContentHandler(&unsuph_);
549 else if (XMLString::equals(eq_.label, localname))
550 parser_->setContentHandler(&labelh_);
552 error::token(localname);
555 template <
typename T>
557 TransitionHandler<T>::end (
const XMLCh*
const,
558 const XMLCh*
const localname,
561 using namespace xercesc;
562 if (XMLString::equals(eq_.transition, localname))
564 parser_->setContentHandler(&root_);
565 aut_.add_series_transition(src_, dst_, labelh_.series());
568 error::token(localname);
574 template <
typename T>
580 : Handler(parser, root),
584 s_(aut.series().one_),
585 labelh_(parser, *this, s_, eq_.label),
586 unsuph_(parser, *this)
590 template <
typename T>
593 const XMLCh*
const localname,
595 const xercesc::Attributes&)
597 using namespace xercesc;
598 if (XMLString::equals(eq_.drawing, localname))
599 parser_->setContentHandler(&unsuph_);
600 else if (XMLString::equals(eq_.geometry, localname))
601 parser_->setContentHandler(&unsuph_);
602 else if (XMLString::equals(eq_.label, localname))
603 parser_->setContentHandler(&labelh_);
605 error::token(localname);
608 template <
typename T>
610 InitFinalHandler<T>::end (
const XMLCh*
const,
611 const XMLCh*
const localname,
614 using namespace xercesc;
615 if (XMLString::equals(eq_.initial, localname) && initial_)
617 parser_->setContentHandler(&root_);
618 aut_.set_initial(state_, labelh_.series());
620 else if (XMLString::equals(eq_.final, localname) && !initial_)
622 parser_->setContentHandler(&root_);
623 aut_.set_final(state_, labelh_.series());
626 error::token(localname);
632 template <
typename T>
637 : Handler(parser, root),
643 template <
typename T>
646 const XMLCh*
const localname,
648 const xercesc::Attributes&)
650 error::token(localname);
653 template <
typename T>
655 GeometryHandler<T>::end (
const XMLCh*
const,
656 const XMLCh*
const localname,
659 using namespace xercesc;
660 if (XMLString::equals(eq_.geometry, localname))
661 parser_->setContentHandler(&root_);
663 error::token(localname);
669 template <
typename T>
673 using namespace xercesc;
674 if (XMLString::equals(eq_.monElmt, localname))
675 return builders::create_monElmth(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()));
676 else if (XMLString::equals(eq_.star, localname))
677 return new StarHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()));
678 else if (XMLString::equals(eq_.leftExtMul, localname))
679 return new ExtMulHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()),
true);
680 else if (XMLString::equals(eq_.rightExtMul, localname))
681 return new ExtMulHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()),
false);
682 else if (XMLString::equals(eq_.sum, localname))
683 return new SumHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()));
684 else if (XMLString::equals(eq_.product, localname))
685 return new ProductHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()));
686 else if (XMLString::equals(eq_.one, localname))
687 return new AtomHandler<T>(parser_, *
this, algebra::identity_as<typename T::value_t>::of(param_.structure()), eq_.one);
688 else if (XMLString::equals(eq_.zero, localname))
689 return new AtomHandler<T>(parser_, *
this, algebra::zero_as<typename T::value_t>::of(param_.structure()), eq_.zero);
694 template <
typename T>
698 using namespace xercesc;
699 return builders::create_weighth(parser_, *
this,
700 algebra::identity_as<typename T::value_t>::of(param_.structure()), attrs);
705 #endif // !VCSN_XML_HANDLERS_HXX