handlers.hxx

00001 // handlers.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2005, 2006, 2007 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 
00018 #ifndef HANDLERS_HXX
00019 # define HANDLERS_HXX
00020 
00032 # include <iostream>
00033 # include <xercesc/sax2/Attributes.hpp>
00034 
00035 # include <vaucanson/xml/strings.hh>
00036 # include <vaucanson/xml/builders.hh>
00037 
00038 namespace vcsn
00039 {
00040   namespace xml
00041   {
00042     /*
00043      * ErrHandler
00044      */
00045     void
00046     ErrHandler::warning (const xercesc::SAXParseException& exc)
00047     {
00048       char* msg = xercesc::XMLString::transcode(exc.getMessage());
00049       std::cout << "Warning: " << msg << std::endl;
00050       xercesc::XMLString::release(&msg);
00051     }
00052 
00053     void
00054     ErrHandler::error (const xercesc::SAXParseException& exc)
00055     {
00056       char* msg = xercesc::XMLString::transcode(exc.getMessage());
00057       std::cout << "Error: " << msg << std::endl;
00058       xercesc::XMLString::release(&msg);
00059     }
00060 
00061     void
00062     ErrHandler::fatalError (const xercesc::SAXParseException& exc)
00063     {
00064       char* msg = xercesc::XMLString::transcode(exc.getMessage());
00065       std::cout << "Fatal error: " << msg << std::endl;
00066       xercesc::XMLString::release(&msg);
00067     }
00068 
00069     /*
00070      * Handler
00071      */
00072     Handler::Handler (xercesc::SAX2XMLReader* parser,
00073                       XMLEq& eq,
00074                       xercesc::DefaultHandler& root)
00075       : DefaultHandler(),
00076         parser_(parser),
00077         root_(root),
00078         eq_(eq)
00079     {
00080     }
00081 
00082     /*
00083      * UnsupHandler
00084      */
00085     UnsupHandler::UnsupHandler (xercesc::DefaultHandler& root,
00086                                 xercesc::SAX2XMLReader* parser)
00087       : DefaultHandler(),
00088         parser_(parser),
00089         root_(root),
00090         depth_(1)
00091     {
00092     }
00093 
00094     void
00095     UnsupHandler::startElement (const XMLCh* const,
00096                                 const XMLCh* const,
00097                                 const XMLCh* const,
00098                                 const xercesc::Attributes&)
00099     {
00100       depth_++;
00101     }
00102 
00103     void
00104     UnsupHandler::endElement (const XMLCh* const,
00105                               const XMLCh* const,
00106                               const XMLCh* const)
00107     {
00108       depth_--;
00109       if (depth_ <= 0)
00110       {
00111         parser_->setContentHandler(&root_);
00112         depth_ = 1;
00113       }
00114     }
00115 
00116     /*
00117      * AutHandler
00118      */
00119     template <typename T>
00120     AutHandler<T>::AutHandler (T& aut,
00121                                xercesc::SAX2XMLReader* parser,
00122                                XMLEq& eq)
00123       : DefaultHandler(),
00124         parser_(parser),
00125         eq_(eq),
00126         aut_(aut),
00127         end_(false),
00128         unsuph_(*this, parser),
00129         contenth_(*this, aut, parser, eq),
00130         typeh_(*this, aut, parser, eq)
00131     {
00132     }
00133 
00134     template <typename T>
00135     void
00136     AutHandler<T>::startElement (const XMLCh* const uri,
00137                                  const XMLCh* const localname,
00138                                  const XMLCh* const,
00139                                  const xercesc::Attributes& attrs)
00140     {
00141       using namespace xercesc;
00142       if (XMLString::equals(eq_.automaton, localname) && !end_)
00143       {
00144         const XMLCh* autname = builders::get_attribute(attrs, "name", uri);
00145         if (autname != 0)
00146           aut_.geometry().name() = xml2str(autname);
00147       }
00148       else // <labelType>, <content>
00149       {
00150         if (XMLString::equals(eq_.type, localname))
00151           parser_->setContentHandler(&typeh_);
00152         else
00153           if (XMLString::equals(eq_.content, localname))
00154             parser_->setContentHandler(&contenth_);
00155           else
00156             if (XMLString::equals(eq_.drawing, localname))
00157               parser_->setContentHandler(&unsuph_);
00158             else
00159               if (XMLString::equals(eq_.geometry, localname))
00160                 parser_->setContentHandler(&unsuph_);
00161               // else
00162               // <FSMXML>
00163       }
00164     }
00165 
00166     template <typename T>
00167     void
00168     AutHandler<T>::endElement (const XMLCh* const,
00169                                const XMLCh* const localname,
00170                                const XMLCh* const)
00171     {
00172       using namespace xercesc;
00173       if (XMLString::equals(eq_.automaton, localname))
00174         end_ = true;
00175     }
00176 
00177     template <typename T>
00178     bool
00179     AutHandler<T>::end ()
00180     {
00181       return end_;
00182     }
00183 
00184     /*
00185      * TypeHandler
00186      */
00187     template <typename T>
00188     TypeHandler<T>::TypeHandler (xercesc::DefaultHandler& root,
00189                                  T& aut,
00190                                  xercesc::SAX2XMLReader* parser,
00191                                  XMLEq& eq)
00192       : Handler(parser, eq, root),
00193         aut_(aut)
00194     {
00195     }
00196 
00197     template <typename T>
00198     void
00199     TypeHandler<T>::startElement (const XMLCh* const,
00200                                   const XMLCh* const localname,
00201                                   const XMLCh* const,
00202                                   const xercesc::Attributes& attrs)
00203     {
00204       using namespace xercesc;
00205       // Possible optimisation :
00206       // - using a simple boolean better than a comparison
00207       if (XMLString::equals(eq_.monoid, localname))
00208       {
00209         monoid_ = builders::create_monoid(aut_, attrs);
00210         monoidh_ = builders::monoidh_factory(*monoid_, attrs, *this, parser_, eq_);
00211         parser_->setContentHandler(monoidh_);
00212       }
00213       else // <semiring>, <numericalSemiring>
00214       {
00215         // Attach the alphabet to the autmaton
00216         series_set_t    series(aut_.structure().series().semiring(), *monoid_);
00217         aut_.attach(series);
00218 
00219         // parse semiring
00220         semiring_ = builders::create_semiring(aut_, attrs);
00221         semiringh_ = builders::semiringh_factory(aut_, attrs, *semiring_, *this, parser_, eq_);
00222         parser_->setContentHandler(semiringh_);
00223       }
00224     }
00225 
00226     template <typename T>
00227     void
00228     TypeHandler<T>::endElement (const XMLCh* const,
00229                                 const XMLCh* const localname,
00230                                 const XMLCh* const)
00231     {
00232       using namespace xercesc;
00233 
00234       // Attach the semiring to the automaton
00235       series_set_t      series(*semiring_, aut_.structure().series().monoid());
00236       aut_.attach(series);
00237 
00238       delete semiringh_;
00239       delete monoidh_;
00240       delete semiring_;
00241       delete monoid_;
00242       if (XMLString::equals(eq_.type, localname))
00243         parser_->setContentHandler(&root_);
00244   } // !xml
00245 
00246     /*
00247      * MonoidHandler
00248      */
00249     MonoidHandler::MonoidHandler (xercesc::DefaultHandler& root,
00250                                   xercesc::SAX2XMLReader* parser,
00251                                   XMLEq& eq)
00252       : Handler(parser, eq, root)
00253     {
00254     }
00255 
00256     /*
00257      * FreeMonoidHandler
00258      */
00259     template <typename T>
00260     FreeMonoidHandler<T>::FreeMonoidHandler (xercesc::DefaultHandler& root,
00261                                              T& monoid,
00262                                              xercesc::SAX2XMLReader* parser,
00263                                              XMLEq& eq)
00264       : MonoidHandler(root, parser, eq),
00265         monoid_(monoid)
00266     {
00267     }
00268 
00269     template <typename T>
00270     void
00271     FreeMonoidHandler<T>::startElement (const XMLCh* const,
00272                                         const XMLCh* const,
00273                                         const XMLCh* const,
00274                                         const xercesc::Attributes& attrs)
00275     {
00276       // Should necessary be a <generator> tag
00277       const XMLCh* value = builders::get_attribute(attrs, "value");
00278       std::string letter = xml2str(value);
00279       builders::insert_letter(monoid_, letter);
00280     }
00281 
00282     template <typename T>
00283     void
00284     FreeMonoidHandler<T>::endElement (const XMLCh* const,
00285                                       const XMLCh* const localname,
00286                                       const XMLCh* const)
00287     {
00288       if (xercesc::XMLString::equals(eq_.monoid, localname))
00289         parser_->setContentHandler(&root_);
00290     }
00291     /*
00292      * ProdMonoidHandler
00293      */
00294     template <typename T>
00295     ProdMonoidHandler<T>::ProdMonoidHandler (xercesc::DefaultHandler& root,
00296                                              T& monoid,
00297                                              xercesc::SAX2XMLReader* parser,
00298                                              XMLEq& eq)
00299       : MonoidHandler(root, parser, eq),
00300         monoid_(monoid),
00301         first_(true)
00302     {
00303     }
00304 
00305     template <typename T>
00306     void
00307     ProdMonoidHandler<T>::startElement (const XMLCh* const,
00308                                         const XMLCh* const,
00309                                         const XMLCh* const,
00310                                         const xercesc::Attributes& attrs)
00311     {
00312       if (first_)
00313       {
00314         monoidh_ = builders::monoidh_factory(monoid_.first_monoid(), attrs, *this, parser_, eq_);
00315         first_ = false;
00316       }
00317       else
00318       {
00319         delete monoidh_;
00320         monoidh_ = builders::monoidh_factory(monoid_.second_monoid(), attrs, *this, parser_, eq_);
00321       }
00322       parser_->setContentHandler(monoidh_);
00323     }
00324 
00325     template <typename T>
00326     void
00327     ProdMonoidHandler<T>::endElement (const XMLCh* const,
00328                                       const XMLCh* const,
00329                                       const XMLCh* const)
00330     {
00331       delete monoidh_;
00332       parser_->setContentHandler(&root_);
00333     }
00334 
00335     /*
00336      * SemiringHandler
00337      */
00338     SemiringHandler::SemiringHandler (xercesc::DefaultHandler& root,
00339                                       xercesc::SAX2XMLReader* parser,
00340                                       XMLEq& eq)
00341       : Handler(parser, eq, root)
00342     {
00343     }
00344     /*
00345      * SeriesSemiringHandler
00346      */
00347     template <typename T>
00348     SeriesSemiringHandler<T>::SeriesSemiringHandler (xercesc::DefaultHandler& root,
00349                                                      T& semiring,
00350                                                      xercesc::SAX2XMLReader* parser,
00351                                                      XMLEq& eq)
00352       : SemiringHandler(root, parser, eq),
00353         semiring_(semiring)
00354     {
00355     }
00356 
00357     template <typename T>
00358     void
00359     SeriesSemiringHandler<T>::startElement (const XMLCh* const,
00360                                             const XMLCh* const localname,
00361                                             const XMLCh* const,
00362                                             const xercesc::Attributes& attrs)
00363     {
00364       using namespace xercesc;
00365 
00366       if (XMLString::equals(eq_.monoid, localname))
00367       {
00368         monoidh_ = builders::monoidh_factory(const_cast
00369                                              <typename T::monoid_t&>
00370                                              (semiring_.monoid()), attrs, *this, parser_, eq_);
00371         parser_->setContentHandler(monoidh_);
00372       }
00373       else
00374       {
00375         semiringh_ = builders::semiringh_factory(semiring_, attrs, semiring_.semiring(),
00376                                                  *this, parser_, eq_);
00377         parser_->setContentHandler(semiringh_);
00378       }
00379     }
00380 
00381     template <typename T>
00382     void
00383     SeriesSemiringHandler<T>::endElement (const XMLCh* const,
00384                                           const XMLCh* const,
00385                                           const XMLCh* const)
00386     {
00387       delete monoidh_;
00388       delete semiringh_;
00389       parser_->setContentHandler(&root_);
00390     }
00391     /*
00392      * NumSemiringHandler
00393      */
00394     template <typename T>
00395     NumSemiringHandler<T>::NumSemiringHandler (xercesc::DefaultHandler& root,
00396                                                T& semiring,
00397                                                xercesc::SAX2XMLReader* parser,
00398                                                XMLEq& eq)
00399       : SemiringHandler(root, parser, eq),
00400         semiring_(semiring)
00401     {
00402     }
00403 
00404     template <typename T>
00405     void
00406     NumSemiringHandler<T>::startElement (const XMLCh* const,
00407                                             const XMLCh* const,
00408                                             const XMLCh* const,
00409                                             const xercesc::Attributes&)
00410     {
00411     }
00412 
00413     template <typename T>
00414     void
00415     NumSemiringHandler<T>::endElement (const XMLCh* const,
00416                                           const XMLCh* const,
00417                                           const XMLCh* const)
00418     {
00419       parser_->setContentHandler(&root_);
00420     }
00421 
00422     /*
00423      * ContentHandler
00424      */
00425     template <typename T>
00426     ContHandler<T>::ContHandler (xercesc::DefaultHandler& root,
00427                                  T& aut,
00428                                  xercesc::SAX2XMLReader* parser,
00429                                  XMLEq& eq)
00430       : Handler(parser, eq, root),
00431         aut_(aut),
00432         transh_(*this, aut, map_, parser, eq),
00433         statesh_(*this, aut, map_, parser, eq)
00434     {
00435     }
00436 
00437     template <typename T>
00438     void
00439     ContHandler<T>::startElement (const XMLCh* const,
00440                                   const XMLCh* const localname,
00441                                   const XMLCh* const,
00442                                   const xercesc::Attributes&)
00443     {
00444       using namespace xercesc;
00445 
00446       // Possible optimisation :
00447       // - using a simple boolean better than a comparaison
00448       if (XMLString::equals(eq_.states, localname))
00449         parser_->setContentHandler(&statesh_);
00450       else
00451         parser_->setContentHandler(&transh_);
00452     }
00453 
00454     template <typename T>
00455     void
00456     ContHandler<T>::endElement (const XMLCh* const,
00457                                 const XMLCh* const,
00458                                 const XMLCh* const)
00459     {
00460       parser_->setContentHandler(&root_);
00461     }
00462 
00463     /*
00464      * StatesHandler
00465      */
00466     template <typename T>
00467     StatesHandler<T>::StatesHandler (xercesc::DefaultHandler& root,
00468                                      T& aut,
00469                                      map_t& map,
00470                                      xercesc::SAX2XMLReader* parser,
00471                                      XMLEq& eq)
00472       : Handler(parser, eq, root),
00473         map_(map),
00474         aut_(aut),
00475         stateh_(*this, map_, parser, eq)
00476     {
00477     }
00478 
00479     template <typename T>
00480     void
00481     StatesHandler<T>::startElement (const XMLCh* const,
00482                                     const XMLCh* const,
00483                                     const XMLCh* const,
00484                                     const xercesc::Attributes& attrs)
00485     {
00486       hstate_t state = aut_.add_state();
00487       map_[xml2str(builders::get_attribute(attrs, "name"))] = state;
00488 
00489       stateh_.reset(&state);
00490       parser_->setContentHandler(&stateh_);
00491     }
00492 
00493     template <typename T>
00494     void
00495     StatesHandler<T>::endElement (const XMLCh* const,
00496                                   const XMLCh* const,
00497                                   const XMLCh* const)
00498     {
00499       parser_->setContentHandler(&root_);
00500     }
00501 
00502     /*
00503      * StateHandler
00504      */
00505     StateHandler::StateHandler (xercesc::DefaultHandler& root,
00506                                 map_t& map,
00507                                 xercesc::SAX2XMLReader* parser,
00508                                 XMLEq& eq)
00509       : Handler(parser, eq, root),
00510         map_(map),
00511         unsuph_(*this, parser)
00512     {
00513     }
00514 
00515     void
00516     StateHandler::startElement (const XMLCh* const,
00517                                 const XMLCh* const,
00518                                 const XMLCh* const,
00519                                 const xercesc::Attributes&)
00520     {
00521       // geometry / drawing
00522       parser_->setContentHandler(&unsuph_);
00523     }
00524 
00525     void
00526     StateHandler::endElement (const XMLCh* const,
00527                               const XMLCh* const localname,
00528                               const XMLCh* const)
00529     {
00530       if (xercesc::XMLString::equals(eq_.state, localname))
00531         parser_->setContentHandler(&root_);
00532     }
00533 
00534     void
00535     StateHandler::reset (hstate_t* state)
00536     {
00537       state_ = state;
00538     }
00539 
00540     /*
00541      * RegExpHandler
00542      */
00543     template <typename T>
00544     RegExpHandler<T>::RegExpHandler (xercesc::DefaultHandler& root,
00545                                      T& aut,
00546                                      xercesc::SAX2XMLReader* parser,
00547                                      XMLEq& eq)
00548       : Handler(parser, eq, root),
00549         aut_(aut),
00550         krat_exp_(aut.structure().series())
00551     {
00552     }
00553 
00554     template <typename T>
00555     typename RegExpHandler<T>::series_set_elt_t
00556     RegExpHandler<T>::get_series()
00557     {
00558       return krat_exp_;
00559     }
00560 
00561     template <typename T>
00562     SumHandler<T>::SumHandler (xercesc::DefaultHandler& root,
00563                                T& aut,
00564                                xercesc::SAX2XMLReader* parser,
00565                                XMLEq& eq)
00566       : RegExpHandler<T>(root, aut, parser, eq),
00567         first_(true)
00568     {
00569     }
00570     template <typename T>
00571     void
00572     SumHandler<T>::startElement (const XMLCh* const,
00573                                  const XMLCh* const localname,
00574                                  const XMLCh* const,
00575                                  const xercesc::Attributes& attrs)
00576     {
00577       if (first_)
00578       {
00579         lefth_ = builders::labelh_factory(*this, this->aut_,
00580                                           this->parser_, this->eq_,
00581                                           localname, attrs);
00582         this->parser_->setContentHandler(lefth_);
00583       }
00584       else
00585       {
00586         righth_ = builders::labelh_factory(*this, this->aut_,
00587                                           this->parser_, this->eq_,
00588                                           localname, attrs);
00589         this->parser_->setContentHandler(righth_);
00590       }
00591       first_ = false;
00592     }
00593     template <typename T>
00594     void
00595     SumHandler<T>::endElement (const XMLCh* const,
00596                                const XMLCh* const,
00597                                const XMLCh* const)
00598     {
00599       this->krat_exp_ = lefth_->get_series() + righth_->get_series();
00600       this->parser_->setContentHandler(&this->root_);
00601       delete lefth_;
00602       delete righth_;
00603     }
00604 
00605     template <typename T>
00606     ProdHandler<T>::ProdHandler (xercesc::DefaultHandler& root,
00607                                  T& aut,
00608                                  xercesc::SAX2XMLReader* parser,
00609                                  XMLEq& eq)
00610       : RegExpHandler<T>(root, aut, parser, eq),
00611         first_(true)
00612     {
00613     }
00614     template <typename T>
00615     void
00616     ProdHandler<T>::startElement (const XMLCh* const,
00617                                   const XMLCh* const localname,
00618                                   const XMLCh* const,
00619                                   const xercesc::Attributes& attrs)
00620     {
00621       if (first_)
00622       {
00623         lefth_ = builders::labelh_factory(*this, this->aut_,
00624                                           this->parser_, this->eq_,
00625                                           localname, attrs);
00626         this->parser_->setContentHandler(lefth_);
00627       }
00628       else
00629       {
00630         righth_ = builders::labelh_factory(*this, this->aut_,
00631                                           this->parser_, this->eq_,
00632                                           localname, attrs);
00633         this->parser_->setContentHandler(righth_);
00634       }
00635       first_ = false;
00636     }
00637     template <typename T>
00638     void
00639     ProdHandler<T>::endElement (const XMLCh* const,
00640                                 const XMLCh* const,
00641                                 const XMLCh* const)
00642     {
00643       this->krat_exp_ = lefth_->get_series() * righth_->get_series();
00644       this->parser_->setContentHandler(&this->root_);
00645       delete lefth_;
00646       delete righth_;
00647     }
00648 
00649     template <typename T>
00650     StarHandler<T>::StarHandler (xercesc::DefaultHandler& root,
00651                                  T& aut,
00652                                  xercesc::SAX2XMLReader* parser,
00653                                  XMLEq& eq)
00654       : RegExpHandler<T>(root, aut, parser, eq)
00655     {
00656     }
00657     template <typename T>
00658     void
00659     StarHandler<T>::startElement (const XMLCh* const,
00660                                   const XMLCh* const localname,
00661                                   const XMLCh* const,
00662                                   const xercesc::Attributes& attrs)
00663     {
00664       sonh_ = builders::labelh_factory(*this, this->aut_,
00665                                        this->parser_, this->eq_,
00666                                        localname, attrs);
00667       this->parser_->setContentHandler(sonh_);
00668     }
00669     template <typename T>
00670     void
00671     StarHandler<T>::endElement (const XMLCh* const,
00672                                 const XMLCh* const,
00673                                 const XMLCh* const)
00674     {
00675       this->krat_exp_ = sonh_->get_series().star();
00676       this->parser_->setContentHandler(&this->root_);
00677       delete sonh_;
00678     }
00679 
00680     template <typename T>
00681     WordHandler<T>::WordHandler (xercesc::DefaultHandler& root,
00682                                  T& aut,
00683                                  xercesc::SAX2XMLReader* parser,
00684                                  XMLEq& eq,
00685                                  typename RegExpHandler<T>::series_set_elt_t val)
00686       : RegExpHandler<T>(root, aut, parser, eq)
00687     {
00688       this->krat_exp_ = val;
00689     }
00690     template <typename T>
00691     void
00692     WordHandler<T>::startElement (const XMLCh* const,
00693                                   const XMLCh* const,
00694                                   const XMLCh* const,
00695                                   const xercesc::Attributes&)
00696     {
00697     }
00698     template <typename T>
00699     void
00700     WordHandler<T>::endElement (const XMLCh* const,
00701                                 const XMLCh* const,
00702                                 const XMLCh* const)
00703     {
00704       this->parser_->setContentHandler(&this->root_);
00705     }
00706     template <typename T>
00707     LabelHandler<T>::LabelHandler (xercesc::DefaultHandler& root,
00708                                    T& aut,
00709                                    xercesc::SAX2XMLReader* parser,
00710                                    XMLEq& eq)
00711       : RegExpHandler<T>(root, aut, parser, eq),
00712         used_(false)
00713     {
00714     }
00715     template <typename T>
00716     void
00717     LabelHandler<T>::startElement (const XMLCh* const,
00718                                    const XMLCh* const localname,
00719                                    const XMLCh* const,
00720                                    const xercesc::Attributes& attrs)
00721     {
00722       used_ = true;
00723       sonh_ = builders::labelh_factory(*this, this->aut_,
00724                                        this->parser_, this->eq_,
00725                                        localname, attrs);
00726       this->parser_->setContentHandler(sonh_);
00727     }
00728     template <typename T>
00729     void
00730     LabelHandler<T>::endElement (const XMLCh* const,
00731                                  const XMLCh* const,
00732                                  const XMLCh* const)
00733     {
00734       this->krat_exp_ = sonh_->get_series();
00735       this->parser_->setContentHandler(&this->root_);
00736     }
00737     template <typename T>
00738     bool
00739     LabelHandler<T>::used ()
00740     {
00741       return used_;
00742     }
00743     template <typename T>
00744     void
00745     LabelHandler<T>::reset ()
00746     {
00747       used_ = false;
00748       this->krat_exp_ = typename RegExpHandler<T>::series_set_elt_t(this->aut_.structure().series());
00749     }
00750 
00751     template <typename T>
00752     typename LabelHandler<T>::series_set_elt_t
00753     LabelHandler<T>::value ()
00754     {
00755       return this->krat_exp_;
00756     }
00757 
00758     /*
00759      * TransitionsHandler
00760      */
00761     template <typename T>
00762     TransitionsHandler<T>::TransitionsHandler (xercesc::DefaultHandler& root,
00763                                                T& aut,
00764                                                map_t& map,
00765                                                xercesc::SAX2XMLReader* parser,
00766                                                XMLEq& eq)
00767       : Handler(parser, eq, root),
00768         map_(map),
00769         aut_(aut),
00770         transh_(*this, aut, map, curattrs_, parser, eq)
00771     {
00772     }
00773 
00774     template <typename T>
00775     TransitionsHandler<T>::~TransitionsHandler()
00776     {
00777     }
00778 
00779     template <typename T>
00780     void
00781     TransitionsHandler<T>::startElement (const XMLCh* const,
00782                                          const XMLCh* const,
00783                                          const XMLCh* const,
00784                                          const xercesc::Attributes& attrs)
00785     {
00786       curattrs_.clear();
00787       for (unsigned int i = 0; i < attrs.getLength(); i++)
00788         curattrs_[xml2str(attrs.getLocalName(i))] =  xml2str(attrs.getValue(i));
00789       parser_->setContentHandler(&transh_);
00790     }
00791 
00792     template <typename T>
00793     void
00794     TransitionsHandler<T>::endElement (const XMLCh* const,
00795                                        const XMLCh* const,
00796                                        const XMLCh* const)
00797     {
00798       parser_->setContentHandler(&root_);
00799     }
00800 
00801 
00802     /*
00803      * TransitionHandler
00804      */
00805     template <typename T>
00806     TransitionHandler<T>::TransitionHandler (xercesc::DefaultHandler& root,
00807                                              T& aut,
00808                                              map_t& map,
00809                                              curattrs_t& attrs,
00810                                              xercesc::SAX2XMLReader* parser,
00811                                              XMLEq& eq)
00812       : Handler(parser, eq, root),
00813         attrs_(attrs),
00814         map_(map),
00815         aut_(aut),
00816         unsuph_(*this, parser),
00817         labelh_(*this, aut, parser, eq)
00818     {
00819     }
00820 
00821     template <typename T>
00822     void
00823     TransitionHandler<T>::startElement (const XMLCh* const,
00824                                         const XMLCh* const localname,
00825                                         const XMLCh* const,
00826                                         const xercesc::Attributes&)
00827     {
00828       if (xercesc::XMLString::equals(eq_.label, localname))
00829         parser_->setContentHandler(&labelh_);
00830       else
00831         if (xercesc::XMLString::equals(eq_.drawing, localname))
00832           parser_->setContentHandler(&unsuph_);
00833         else
00834           if (xercesc::XMLString::equals(eq_.geometry, localname))
00835             parser_->setContentHandler(&unsuph_);
00836     }
00837 
00838     template <typename T>
00839     TransitionHandler<T>::~TransitionHandler ()
00840     {
00841     }
00842 
00843     template <typename T>
00844     void
00845     TransitionHandler<T>::endElement (const XMLCh* const,
00846                                       const XMLCh* const localname,
00847                                       const XMLCh* const)
00848     {
00849       if (xercesc::XMLString::equals(eq_.transition, localname))
00850       {
00851         typename T::series_set_elt_t s =
00852           builders::get_series_transition(aut_, attrs_, labelh_);
00853 
00854         // no checks are made because the xsd ensure the existence of these keys
00855         hstate_t src = map_[attrs_["src"]];
00856         hstate_t dst = map_[attrs_["dst"]];
00857         htransition_t e = aut_.add_series_transition(src, dst, s);
00858       }
00859       else // tag == "initial" || tag == "final"
00860       {
00861         typename T::series_set_elt_t s =
00862           builders::get_series_transition(aut_, attrs_, labelh_);
00863 
00864         // no checks are made because the xsd ensure the existence of this key
00865         hstate_t state = map_[attrs_["state"]];
00866         if (xercesc::XMLString::equals(eq_.initial, localname))
00867           aut_.set_initial(state, s);
00868         else // tag == "final"
00869           aut_.set_final(state, s);
00870       }
00871       labelh_.reset();
00872       parser_->setContentHandler(&root_);
00873     }
00874   } // !xml
00875 } // !vcsn
00876 
00877 #endif /* !HANDLERS_HXX */

Generated on Sun Jul 29 19:35:19 2007 for Vaucanson by  doxygen 1.5.2