SUMO - Simulation of Urban MObility
GenericSAXHandler Class Reference

A handler which converts occuring elements and attributes into enums. More...

#include <GenericSAXHandler.h>

Inheritance diagram for GenericSAXHandler:
DefaultHandler NIImporter_ITSUMO::Handler NIImporter_MATSim::EdgesHandler NIImporter_MATSim::NodesHandler NIImporter_OpenDrive SUMOSAXHandler AGActivityGenHandler GUISettingsHandler MSLaneSpeedTrigger MSTriggeredRerouter MSTriggeredXMLReader NIImporter_OpenStreetMap::EdgesHandler NIImporter_OpenStreetMap::NodesHandler NIImporter_SUMO NIXMLConnectionsHandler NIXMLEdgesHandler NIXMLNodesHandler NIXMLTrafficLightsHandler NIXMLTypesHandler ODDistrictHandler PCLoaderOSM PCLoaderOSM::EdgesHandler PCLoaderOSM::NodesHandler PCLoaderXML PCNetProjectionLoader PCTypeDefHandler RODFDetectorHandler ROJTRTurnDefLoader RONetHandler ROTypedXMLRoutesLoader SAXWeightsHandler SUMORouteHandler

Public Member Functions

void characters (const XMLCh *const chars, const XERCES3_SIZE_t length)
 The inherited method called when characters occured.
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 The inherited method called when a tag is being closed.
 GenericSAXHandler (StringBijection< int >::Entry *tags, int terminatorTag, StringBijection< int >::Entry *attrs, int terminatorAttr, const std::string &file)
 Constructor.
const std::string & getFileName () const
 returns the current file name
void registerParent (const int tag, GenericSAXHandler *handler)
 Assigning a parent handler which is enabled when the specified tag is closed.
void setFileName (const std::string &name)
 Sets the current file name.
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 The inherited method called when a new tag opens.
virtual ~GenericSAXHandler ()
 Destructor.
SAX ErrorHandler callbacks
void warning (const SAXParseException &exception)
 Handler for XML-warnings.
void error (const SAXParseException &exception)
 Handler for XML-errors.
void fatalError (const SAXParseException &exception)
 Handler for XML-errors.

Protected Member Functions

std::string buildErrorMessage (const SAXParseException &exception)
 Builds an error message.
virtual void myCharacters (int element, const std::string &chars)
 Callback method for characters to implement by derived classes.
virtual void myEndElement (int element)
 Callback method for a closing tag to implement by derived classes.
virtual void myStartElement (int element, const SUMOSAXAttributes &attrs)
 Callback method for an opening tag to implement by derived classes.

Private Member Functions

XMLCh * convert (const std::string &name) const
 converts from c++-string into unicode
int convertTag (const std::string &tag) const
 Converts a tag from its string into its numerical representation.

Private Attributes

std::vector< std::string > myCharactersVector
 A list of character strings obtained so far to build the complete characters string at the end.
std::string myFileName
 The name of the currently parsed file.
GenericSAXHandlermyParentHandler
 The handler to give control back to.
int myParentIndicator
 The tag indicating that control should be given back.

attributes parsing

typedef std::map< int, XMLCh * > AttrMap
AttrMap myPredefinedTags
std::map< int, std::string > myPredefinedTagsMML
 the map from ids to their string representation

elements parsing

typedef std::map< std::string,
int
TagMap
TagMap myTagMap

Detailed Description

A handler which converts occuring elements and attributes into enums.

Normally, when using a standard SAX-handler, we would have to compare the incoming XMLCh*-element names with the ones we can parse. The same applies to parsing the attributes. This was assumed to be very time consuming, that's why we derive our handlers from this class.

The idea behind this second handler layer was avoid repeated conversion from strings/whatever to XMLCh* and back again. The usage is quite straight forward, the only overhead is the need to define the enums - both elements and attributes within "SUMOXMLDefinitions". Still, it maybe helps to avoid typos.

This class implements the SAX-callback and offers a new set of callbacks which must be implemented by derived classes. Instead of XMLCh*-values, element names are supplied to the derived classes as enums (int).

Also, this class allows to retrieve attributes using enums (int) within the implemented "myStartElement" method.

Basically, GenericSAXHandler is not derived within SUMO directly, but via SUMOSAXHandler which knows all tags/attributes used by SUMO. It is still kept separate for an easier maintainability and later extensions.

Definition at line 83 of file GenericSAXHandler.h.


Member Typedef Documentation

typedef std::map<int, XMLCh*> GenericSAXHandler::AttrMap [private]

Definition at line 293 of file GenericSAXHandler.h.

typedef std::map<std::string, int> GenericSAXHandler::TagMap [private]

Definition at line 307 of file GenericSAXHandler.h.


Constructor & Destructor Documentation

GenericSAXHandler::GenericSAXHandler ( StringBijection< int >::Entry *  tags,
int  terminatorTag,
StringBijection< int >::Entry *  attrs,
int  terminatorAttr,
const std::string &  file 
)

Constructor.

This constructor gets the lists of known tag and attribute names with their enums (sumotags and sumoattrs in most cases). The end of the list is signaled by terminatorTag/terminatorAttr respectively.

The attribute names are converted into XMLCh* and stored within an internal container. This container is cleared within the destructor.

Parameters:
[in]tagsThe list of known tags
[in]terminatorTagThe tag which signales the end of tags (usually the last entry)
[in]attrsThe list of known attributes
[in]terminatorAttrThe attr which signales the end of attrs (usually the last entry)
[in]fileThe name of the processed file
Todo:
Why are both lists non-const and given as pointers?

Definition at line 52 of file GenericSAXHandler.cpp.

References convert(), myPredefinedTags, myPredefinedTagsMML, and myTagMap.

Destructor.

Definition at line 72 of file GenericSAXHandler.cpp.

References myPredefinedTags.


Member Function Documentation

std::string GenericSAXHandler::buildErrorMessage ( const SAXParseException &  exception) [protected]

Builds an error message.

The error message includes the file name and the line/column information as supported by the given SAXParseException

Parameters:
[in]exceptionThe name of the currently processed file
Returns:
A string describing the given exception

Definition at line 193 of file GenericSAXHandler.cpp.

References getFileName().

Referenced by error(), fatalError(), and warning().

void GenericSAXHandler::characters ( const XMLCh *const  chars,
const XERCES3_SIZE_t  length 
)

The inherited method called when characters occured.

The retrieved characters are converted into a string and appended into a private buffer. They are reported as soon as the element ends.

Todo:

recheck/describe what happens with characters when a new element is opened

describe characters processing in the class' head

Definition at line 176 of file GenericSAXHandler.cpp.

References myCharactersVector.

XMLCh * GenericSAXHandler::convert ( const std::string &  name) const [private]

converts from c++-string into unicode

Todo:
recheck encoding
Parameters:
[in]nameThe string to convert
Returns:
The string converted into a XMLCh-string

Definition at line 92 of file GenericSAXHandler.cpp.

Referenced by GenericSAXHandler().

int GenericSAXHandler::convertTag ( const std::string &  tag) const [private]

Converts a tag from its string into its numerical representation.

Returns the enum-representation stored for the given tag. If the tag is not known, SUMO_TAG_NOTHING is returned.

Parameters:
[in]tagThe string to convert
Returns:
The int-value that represents the string, SUMO_TAG_NOTHING if the named attribute is not known

Definition at line 183 of file GenericSAXHandler.cpp.

References myTagMap, and SUMO_TAG_NOTHING.

Referenced by endElement(), and startElement().

void GenericSAXHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)

The inherited method called when a tag is being closed.

This method calls the user-implemented methods myCharacters with the previously collected and converted characters.

Then, myEndElement is called, supplying it the qname converted to its enum- and string-representations.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 126 of file GenericSAXHandler.cpp.

References convertTag(), myCharacters(), myCharactersVector, myEndElement(), myParentHandler, myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.

void GenericSAXHandler::error ( const SAXParseException &  exception)

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Parameters:
[in]exceptionThe occured exception to process
Exceptions:
ProcessErrorOn any call

Definition at line 212 of file GenericSAXHandler.cpp.

References buildErrorMessage().

Referenced by NLHandler::getLanesFromIndices().

void GenericSAXHandler::fatalError ( const SAXParseException &  exception)

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Exceptions:
ProcessErrorOn any call
Parameters:
[in]exceptionThe occured exception to process

Definition at line 218 of file GenericSAXHandler.cpp.

References buildErrorMessage().

void GenericSAXHandler::myCharacters ( int  element,
const std::string &  chars 
) [protected, virtual]

Callback method for characters to implement by derived classes.

Called by "endElement" (see there).

Parameters:
[in]elementThe opened element, given as a int
[in]charsThe complete embedded character string ProcessError These method may throw a ProcessError if something fails

Reimplemented in NIImporter_OpenDrive, NIImporter_SUMO, PCNetProjectionLoader, NIImporter_ITSUMO::Handler, PCLoaderXML, RORDLoader_SUMOBase, and ROJTRTurnDefLoader.

Definition at line 228 of file GenericSAXHandler.cpp.

Referenced by endElement().

void GenericSAXHandler::myEndElement ( int  element) [protected, virtual]

Callback method for a closing tag to implement by derived classes.

Called by "endElement" (see there).

Parameters:
[in]elementThe closed element, given as a int ProcessError These method may throw a ProcessError if something fails

Reimplemented in NIImporter_OpenDrive, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_OpenStreetMap::NodesHandler, PCLoaderOSM::EdgesHandler, SAXWeightsHandler, MSTriggeredRerouter, PCLoaderOSM::NodesHandler, NIImporter_SUMO, NIImporter_ITSUMO::Handler, MSLaneSpeedTrigger, NLHandler, RORDLoader_SUMOBase, NIXMLEdgesHandler, ODDistrictHandler, RORDGenerator_ODAmounts, MSRouteHandler, NIXMLTrafficLightsHandler, SUMORouteHandler, and RORDLoader_TripDefs.

Definition at line 232 of file GenericSAXHandler.cpp.

Referenced by endElement().

void GenericSAXHandler::registerParent ( const int  tag,
GenericSAXHandler handler 
)

Assigning a parent handler which is enabled when the specified tag is closed.

Definition at line 168 of file GenericSAXHandler.cpp.

References myParentHandler, myParentIndicator, and XMLSubSys::setHandler().

Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger(), and NLTriggerBuilder::parseAndBuildRerouter().

void GenericSAXHandler::setFileName ( const std::string &  name)
void GenericSAXHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attrs 
)

The inherited method called when a new tag opens.

The method parses the supplied XMLCh*-qname using the internal name/enum-map to obtain the enum representation of the attribute name.

Then, "myStartElement" is called supplying the enumeration value, the string-representation of the name and the attributes.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 105 of file GenericSAXHandler.cpp.

References convertTag(), FileHelpers::getConfigurationRelative(), getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), myCharactersVector, myPredefinedTags, myPredefinedTagsMML, myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.

void GenericSAXHandler::warning ( const SAXParseException &  exception)

Handler for XML-warnings.

The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.

Parameters:
[in]exceptionThe occured exception to process

Definition at line 206 of file GenericSAXHandler.cpp.

References buildErrorMessage(), and WRITE_WARNING.


Field Documentation

std::vector<std::string> GenericSAXHandler::myCharactersVector [private]

A list of character strings obtained so far to build the complete characters string at the end.

Definition at line 314 of file GenericSAXHandler.h.

Referenced by characters(), endElement(), and startElement().

std::string GenericSAXHandler::myFileName [private]

The name of the currently parsed file.

Definition at line 323 of file GenericSAXHandler.h.

Referenced by getFileName(), and setFileName().

The handler to give control back to.

Definition at line 317 of file GenericSAXHandler.h.

Referenced by endElement(), and registerParent().

The tag indicating that control should be given back.

Definition at line 320 of file GenericSAXHandler.h.

Referenced by endElement(), and registerParent().

std::map<int, std::string> GenericSAXHandler::myPredefinedTagsMML [private]

the map from ids to their string representation

Definition at line 299 of file GenericSAXHandler.h.

Referenced by GenericSAXHandler(), and startElement().

Definition at line 310 of file GenericSAXHandler.h.

Referenced by convertTag(), and GenericSAXHandler().


The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines