SUMO - Simulation of Urban MObility
XMLSubSys Class Reference

Utility methods for initialising, closing and using the XML-subsystem. More...

#include <XMLSubSys.h>

Static Public Member Functions

static void close ()
 Closes the xml-subsystem.
static
XERCES_CPP_NAMESPACE_QUALIFIER
SAX2XMLReader * 
getSAXReader (SUMOSAXHandler &handler)
 Builds a reader and assigns the handler to it.
static void init (bool enableValidation)
 Initialises the xml-subsystem, returns whether the initialisation succeeded.
static bool runParser (GenericSAXHandler &handler, const std::string &file)
 Runs the given handler on the given file; returns if everything's ok.
static void setHandler (GenericSAXHandler &handler)
 Sets the given handler for the default reader.

Static Protected Member Functions

static
XERCES_CPP_NAMESPACE_QUALIFIER
SAX2XMLReader * 
getSAXReader ()
 Builds a reader.
static void setFeature (XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader &reader, const std::string &feature, bool value)
 Sets the named feature of the given reader to the given value.

Static Private Attributes

static bool myEnableValidation
 Information whether built reader/parser shall validate XML-documents against schemata.
static unsigned int myNextFreeReader
 Information whether the reader is parsing.
static std::vector
< XERCES_CPP_NAMESPACE_QUALIFIER
SAX2XMLReader * > 
myReaders
 The XML Readers used for repeated parsing.

Detailed Description

Utility methods for initialising, closing and using the XML-subsystem.

The Xerces-parsers need an initialisation and should also be closed.

As we use xerces for both the input files and the configuration we would have to check whether the system was initialised before. Instead, we call XMLSubSys::init(bool) once at the beginning of our application and XMLSubSys::close() at the end.

Closing and initialising the XML subsystem is necessary. Still, we never encountered any problems with it. Once, after some modifications, SUMO crashed when closing the XML sub system. The reason was a memory leak within the microsim-module. On initialisation, a SAX2XMLReader is built which can be used during later process. It is destroyed when the subsystem is closed.

In addition to initialisation and shutdown, this module allows to build SAXReaders and/or running a given handler on a given file without dealing with the reader at all.

Todo:
make schema checking optional

Definition at line 73 of file XMLSubSys.h.


Member Function Documentation

void XMLSubSys::close ( ) [static]

Closes the xml-subsystem.

Deletes the built reader and calls XMLPlatformUtils::Terminate();

Definition at line 71 of file XMLSubSys.cpp.

References myReaders.

SAX2XMLReader * XMLSubSys::getSAXReader ( SUMOSAXHandler handler) [static]

Builds a reader and assigns the handler to it.

Tries to build a SAX2XMLReader using "getSAXReader()". If this fails, 0 is returned. Otherwise, the given handler is assigned to the reader as the current DefaultHandler and ErrorHandler.

Parameters:
[in]handlerThe handler to assign to the built reader
Returns:
The built Xerces-SAX-reader, 0 if something failed
See also:
getSAXReader()

Definition at line 81 of file XMLSubSys.cpp.

References getSAXReader().

SAX2XMLReader * XMLSubSys::getSAXReader ( ) [static, protected]

Builds a reader.

Tries to build a SAX2XMLReader using XMLReaderFactory::createXMLReader. If this fails, 0 is returned. Otherwise the validation is set matching the value of "myEnableValidation". If validation is not wanted, a WFXMLScanner is used (see http://www.ibm.com/developerworks/library/x-xercesperf.html).

Returns:
The built Xerces-SAX-reader, 0 if something failed

Definition at line 127 of file XMLSubSys.cpp.

References myEnableValidation, setFeature(), and WRITE_ERROR.

Referenced by getSAXReader(), GUISettingsHandler::GUISettingsHandler(), init(), PCNetProjectionLoader::loadIfSet(), NILoader::loadXMLType(), MSRouteLoader::MSRouteLoader(), MSTriggeredXMLReader::myInit(), ROTypedXMLRoutesLoader::ROTypedXMLRoutesLoader(), and runParser().

void XMLSubSys::init ( bool  enableValidation) [static]

Initialises the xml-subsystem, returns whether the initialisation succeeded.

Calls XMLPlatformUtils::Initialize(). If this fails, the exception is caught and its content is reported using a ProcessError. Otherwise, a static SAX2XMLReader is built using "getSAXReader()" (stored in "myReader").

The information whether validationis wanted is stored in "myEnableValidation" for later usage.

Parameters:
[in]enableValidationWhether validation of XML-documents against schemata shall be enabled
Exceptions:
ProcessErrorIf the initialisation fails
See also:
getSAXReader()

Definition at line 58 of file XMLSubSys.cpp.

References getSAXReader(), myEnableValidation, myNextFreeReader, and myReaders.

Referenced by AGActivityGen::importInfoCity(), and main().

bool XMLSubSys::runParser ( GenericSAXHandler handler,
const std::string &  file 
) [static]

Runs the given handler on the given file; returns if everything's ok.

Uses the reader built on init() which is stored in myReader to parse the given file.

All exceptions are catched and reported to the error-instance of the MsgHandler. Also, if the reader could not be built, this is reported.

The method returns true if everything went ok. This means, that the reader could be built, no exception was caught, and nothing was reported to the error-instance of the MsgHandler.

Parameters:
[in]handlerThe handler to assign to the built reader
[in]fileThe file to run the parser at
Returns:
true if the parsing was done without errors, false otherwise (error was printed)

Definition at line 100 of file XMLSubSys.cpp.

References MsgHandler::getErrorInstance(), GenericSAXHandler::getFileName(), getSAXReader(), myNextFreeReader, myReaders, GenericSAXHandler::setFileName(), setHandler(), MsgHandler::wasInformed(), and WRITE_ERROR.

Referenced by NIImporter_SUMO::_loadNetwork(), NLBuilder::build(), GUISettingsHandler::GUISettingsHandler(), AGActivityGen::importInfoCity(), NLBuilder::load(), NIImporter_OpenStreetMap::load(), loadDistricts(), PCLoaderOSM::loadIfSet(), PCLoaderXML::loadIfSet(), loadJTRDefinitions(), loadNet(), ROLoader::loadNet(), NIImporter_ITSUMO::loadNetwork(), NIImporter_MATSim::loadNetwork(), NIImporter_OpenDrive::loadNetwork(), ROLoader::loadWeights(), main(), MSLaneSpeedTrigger::MSLaneSpeedTrigger(), MSTriggeredRerouter::MSTriggeredRerouter(), readDetectors(), and GenericSAXHandler::startElement().

void XMLSubSys::setFeature ( XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader &  reader,
const std::string &  feature,
bool  value 
) [static, protected]

Sets the named feature of the given reader to the given value.

The given feature name is translated into an XMLCh* and set.

Parameters:
[in]readerThe reader to set the feature of
[in]featureName of the feature to set
[in]valueValue of the feature to set

Definition at line 146 of file XMLSubSys.cpp.

Referenced by getSAXReader().

void XMLSubSys::setHandler ( GenericSAXHandler handler) [static]

Sets the given handler for the default reader.

Uses the reader built on init() which is stored in myReader.

Parameters:
[in]handlerThe handler to assign to the built reader

Definition at line 93 of file XMLSubSys.cpp.

References myNextFreeReader, and myReaders.

Referenced by GenericSAXHandler::endElement(), GenericSAXHandler::registerParent(), and runParser().


Field Documentation

Information whether built reader/parser shall validate XML-documents against schemata.

Definition at line 180 of file XMLSubSys.h.

Referenced by getSAXReader(), and init().

unsigned int XMLSubSys::myNextFreeReader [static, private]

Information whether the reader is parsing.

Definition at line 177 of file XMLSubSys.h.

Referenced by init(), runParser(), and setHandler().

std::vector< SAX2XMLReader * > XMLSubSys::myReaders [static, private]

The XML Readers used for repeated parsing.

Definition at line 174 of file XMLSubSys.h.

Referenced by close(), init(), runParser(), and setHandler().


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