Eclipse SUMO - Simulation of Urban MObility
XMLSubSys Class Reference

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

#include <XMLSubSys.h>

Collaboration diagram for XMLSubSys:

Static Public Member Functions

static void close ()
 Closes the xml-subsystem. More...
 
static SUMOSAXReadergetSAXReader (SUMOSAXHandler &handler)
 Builds a reader and assigns the handler to it. More...
 
static void init ()
 Initialises the xml-subsystem. More...
 
static bool isValidating (const bool net=false)
 Returns whether validation is enabled. More...
 
static bool runParser (GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
 Runs the given handler on the given file; returns if everything's ok. More...
 
static void setHandler (GenericSAXHandler &handler)
 Sets the given handler for the default reader. More...
 
static void setValidation (const std::string &validationScheme, const std::string &netValidationScheme)
 Enables or disables validation. More...
 

Static Private Attributes

static XERCES_CPP_NAMESPACE::SAX2XMLReader::ValSchemes myNetValidationScheme = XERCES_CPP_NAMESPACE::SAX2XMLReader::Val_Auto
 Information whether built reader/parser shall validate SUMO networks against schemata. More...
 
static int myNextFreeReader
 Information whether the reader is parsing. More...
 
static std::vector< SUMOSAXReader * > myReaders
 The XML Readers used for repeated parsing. More...
 
static XERCES_CPP_NAMESPACE::SAX2XMLReader::ValSchemes myValidationScheme = XERCES_CPP_NAMESPACE::SAX2XMLReader::Val_Auto
 Information whether built reader/parser shall validate XML-documents against schemata. More...
 

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 66 of file XMLSubSys.h.

Member Function Documentation

◆ close()

void XMLSubSys::close ( )
static

Closes the xml-subsystem.

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

Definition at line 90 of file XMLSubSys.cpp.

References myReaders.

Referenced by libsumo::Simulation::close(), and SystemFrame::close().

◆ getSAXReader()

SUMOSAXReader * 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 100 of file XMLSubSys.cpp.

References myValidationScheme.

Referenced by GUISettingsHandler::GUISettingsHandler(), NITypeLoader::load(), PCNetProjectionLoader::load(), main(), and SUMORouteLoader::SUMORouteLoader().

◆ init()

void XMLSubSys::init ( )
static

Initialises the xml-subsystem.

Calls XMLPlatformUtils::Initialize(). If this fails, the exception is caught and its content is reported using a ProcessError.

Exceptions
ProcessErrorIf the initialisation fails

Definition at line 47 of file XMLSubSys.cpp.

References myNextFreeReader, and StringUtils::transcode().

Referenced by libsumo::Simulation::load(), and main().

◆ isValidating()

bool XMLSubSys::isValidating ( const bool  net = false)
static

Returns whether validation is enabled.

Parameters
[in]netWhether validation of SUMO networks is reported

Definition at line 81 of file XMLSubSys.cpp.

References myNetValidationScheme, and myValidationScheme.

◆ runParser()

bool XMLSubSys::runParser ( GenericSAXHandler handler,
const std::string &  file,
const bool  isNet = false 
)
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
[in]isNetwhether a network gets loaded
Returns
true if the parsing was done without errors, false otherwise (error was printed)

Definition at line 112 of file XMLSubSys.cpp.

References MsgHandler::clear(), MsgHandler::getErrorInstance(), GenericSAXHandler::getFileName(), myNetValidationScheme, myNextFreeReader, myReaders, myValidationScheme, GenericSAXHandler::setFileName(), MsgHandler::wasInformed(), and WRITE_ERROR.

Referenced by NIImporter_SUMO::_loadNetwork(), NLBuilder::build(), GNEAdditionalHandler::buildRerouter(), GNENet::computeNetwork(), GUISettingsHandler::GUISettingsHandler(), GNEApplicationWindow::handleEvent_NetworkLoaded(), AGActivityGen::importInfoCity(), NITypeLoader::load(), NLBuilder::load(), NIImporter_OpenStreetMap::load(), NIImporter_Vissim::load(), ODDistrictCont::loadDistricts(), GUINet::loadEdgeData(), ShapeHandler::loadFiles(), PCLoaderOSM::loadIfSet(), PCLoaderXML::loadIfSet(), loadJTRDefinitions(), ODMatrix::loadMatrix(), loadNet(), ROLoader::loadNet(), NIImporter_ITSUMO::loadNetwork(), NIImporter_MATSim::loadNetwork(), NIImporter_OpenDrive::loadNetwork(), ODMatrix::loadRoutes(), ROLoader::loadWeights(), main(), MSCalibrator::MSCalibrator(), MSLaneSpeedTrigger::MSLaneSpeedTrigger(), GNEParametersDialog::ParametersOptions::onCmdLoadParameters(), GNETLSEditorFrame::TLSFile::onCmdLoadTLSProgram(), GNEApplicationWindow::onCmdOpenAdditionals(), GNEApplicationWindow::onCmdOpenDemandElements(), GUIApplicationWindow::onCmdOpenShapes(), ROLoader::openTypedRoutes(), NLTriggerBuilder::parseAndBuildRerouter(), GNETLSEditorFrame::parseTLSPrograms(), readDetectors(), and GenericSAXHandler::startElement().

◆ setHandler()

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 106 of file XMLSubSys.cpp.

References myNextFreeReader, and myReaders.

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

◆ setValidation()

void XMLSubSys::setValidation ( const std::string &  validationScheme,
const std::string &  netValidationScheme 
)
static

Enables or disables validation.

The setting is only valid for parsers created after the call. Existing parsers are not adapted.

Parameters
[in]validationSchemeWhether validation of XML-documents against schemata shall be enabled
[in]netValidationSchemeWhether validation of SUMO networks against schemata shall be enabled

Definition at line 58 of file XMLSubSys.cpp.

References myNetValidationScheme, and myValidationScheme.

Referenced by GNEAdditionalHandler::buildRerouter(), GNEApplicationWindow::handleEvent_NetworkLoaded(), NLBuilder::init(), main(), GNEApplicationWindow::onCmdOpenAdditionals(), GNEApplicationWindow::onCmdOpenDemandElements(), GNELoadThread::run(), and GUILoadThread::run().

Field Documentation

◆ myNetValidationScheme

XERCES_CPP_NAMESPACE::SAX2XMLReader::ValSchemes XMLSubSys::myNetValidationScheme = XERCES_CPP_NAMESPACE::SAX2XMLReader::Val_Auto
staticprivate

Information whether built reader/parser shall validate SUMO networks against schemata.

Definition at line 163 of file XMLSubSys.h.

Referenced by isValidating(), runParser(), and setValidation().

◆ myNextFreeReader

int XMLSubSys::myNextFreeReader
staticprivate

Information whether the reader is parsing.

Definition at line 157 of file XMLSubSys.h.

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

◆ myReaders

std::vector< SUMOSAXReader * > XMLSubSys::myReaders
staticprivate

The XML Readers used for repeated parsing.

Definition at line 154 of file XMLSubSys.h.

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

◆ myValidationScheme

XERCES_CPP_NAMESPACE::SAX2XMLReader::ValSchemes XMLSubSys::myValidationScheme = XERCES_CPP_NAMESPACE::SAX2XMLReader::Val_Auto
staticprivate

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

Definition at line 160 of file XMLSubSys.h.

Referenced by getSAXReader(), isValidating(), runParser(), and setValidation().


The documentation for this class was generated from the following files: