frepple::utils::XMLInput Class Reference

This class will read in an XML-file and call the appropriate handler functions of the Object classes and objects. More...

#include <utils.h>

Inheritance diagram for frepple::utils::XMLInput:

List of all members.

Public Types

typedef pair< Attribute,
XMLElement
datapair

Public Member Functions

bool getAbortOnDataError () const
const AttributeListgetAttributes () const
const datapairgetCurrentElement () const
const datapairgetParentElement () const
ObjectgetParentObject () const
ObjectgetPreviousObject () const
void * getUserArea () const
PythonFunction getUserExit () const
void IgnoreElement ()
void invalidateCurrentObject ()
bool isObjectEnd ()
void parse (xercesc::InputSource &, Object *, bool=false)
void readto (Object *)
void setAbortOnDataError (bool i)
void setUserArea (void *v)
void setUserExit (PyObject *p)
void shutdown ()
 XMLInput (unsigned short maxNestedElmnts=20)
virtual ~XMLInput ()

Protected Member Functions

virtual void parse (Object *s, bool b=false)
- Protected Member Functions inherited from frepple::utils::NonCopyable
 NonCopyable ()
 ~NonCopyable ()

Detailed Description

This class will read in an XML-file and call the appropriate handler functions of the Object classes and objects.

This class is implemented based on the Xerces SAX XML parser. For debugging purposes a flag is defined at the start of the file "xmlparser.cpp". Uncomment the line and recompile to use it.

FrePPLe creates a new parser and loads the XML schema every time XML data need to be parsed. When this happens only a few times during a run this is good enough.
However, when the libary has to parse plenty of small XML messages this will create a significant overhead. The code would need to be enhanced to maintain a pool of parsers and cache their grammars.

Definition at line 4210 of file utils.h.


Member Typedef Documentation

Definition at line 4213 of file utils.h.


Constructor & Destructor Documentation

frepple::utils::XMLInput::XMLInput ( unsigned short  maxNestedElmnts = 20)
inline

Constructor.

Parameters:
maxNestedElmntsDefines the maximum depth of elements an XML document is allowed to have. The default is 20.

Definition at line 4362 of file utils.h.

virtual frepple::utils::XMLInput::~XMLInput ( )
inlinevirtual

Destructor.

Definition at line 4368 of file utils.h.


Member Function Documentation

bool frepple::utils::XMLInput::getAbortOnDataError ( ) const
inline

Returns the behavior of the parser in case of data errors.
When true is returned, the processing of the XML stream continues after a DataException. Other, more critical, exceptions types will still abort the parsing process.
False indicates that the processing of the XML stream is aborted.

Definition at line 4462 of file utils.h.

const AttributeList& frepple::utils::XMLInput::getAttributes ( ) const
inline

Return a pointer to an array of character pointer which point to the attributes. See the xerces documentation if this description doesn't satisfy you...

Definition at line 4374 of file utils.h.

const datapair& frepple::utils::XMLInput::getCurrentElement ( ) const
inline

Returns a reference to the current element.

Definition at line 4433 of file utils.h.

const datapair& frepple::utils::XMLInput::getParentElement ( ) const
inline

Returns a reference to the parent element.

Definition at line 4429 of file utils.h.

Object* frepple::utils::XMLInput::getParentObject ( ) const
inline

Clears the previously read object.

Definition at line 4422 of file utils.h.

Object* frepple::utils::XMLInput::getPreviousObject ( ) const
inline

Return a pointer to the previous object being read in.
In a typical use the returned pointer will require a dynamic_cast to a subclass type.
The typical usage is as follows:

          Operation o = dynamic_cast<Operation>(pIn.getPreviousObject());
          if (o) doSomeThing(o);
          else throw LogicException("Incorrect object type");
        

Definition at line 4419 of file utils.h.

void* frepple::utils::XMLInput::getUserArea ( ) const
inline

Returns the user definable pointer.

Definition at line 4449 of file utils.h.

PythonFunction frepple::utils::XMLInput::getUserExit ( ) const
inline

Return the Python callback function.

Definition at line 4470 of file utils.h.

void frepple::utils::XMLInput::IgnoreElement ( )
inline

Ignore an element.

Definition at line 4393 of file utils.h.

void frepple::utils::XMLInput::invalidateCurrentObject ( )
inline

Invalidates the current object.
This method is useful when, for instance, the object being parsed is being deleted.

Definition at line 4403 of file utils.h.

bool frepple::utils::XMLInput::isObjectEnd ( )
inline

Returns true if the current object is finishing with the current tag. This method should only be used in the endElement() method.

Definition at line 4397 of file utils.h.

void frepple::utils::XMLInput::parse ( xercesc::InputSource &  in,
Object pRoot,
bool  validate = false 
)

This is the core parsing function, which triggers the XML parser to start processing the input. It is normally called from the method parse(Object*) once a proper stream has been created.

See also:
parse(Object*)

Definition at line 473 of file xmlparser.cpp.

virtual void frepple::utils::XMLInput::parse ( Object s,
bool  b = false 
)
inlineprotectedvirtual

The real parsing job is delegated to subclasses. Subclass can then define the specifics for parsing a flat file, a string, a SOAP message, etc...

Exceptions:
RuntimeExceptionThrown in the following situations:
  • the XML-document is incorrectly formatted
  • the XML-parser librabry can't be initialized
  • no memory can be allocated to the xml-parser
DataExceptionThrown when the data can't be processed normally by the objects being created or updated.

Reimplemented in frepple::utils::XMLInputFile, and frepple::utils::XMLInputString.

Definition at line 4483 of file utils.h.

void frepple::utils::XMLInput::readto ( Object pPI)

Redirect event stream into a new Object.
It is also possible to pass a NULL pointer to the function. In that situation, we simple ignore the content of that element.
Important: The user is reponsible of making sure the argument object has a proper write-lock. The release of that lock is handled by the parser.

Definition at line 361 of file xmlparser.cpp.

void frepple::utils::XMLInput::setAbortOnDataError ( bool  i)
inline

Updates whether we ignore data exceptions or whether we abort the processing of the XML data stream.

Definition at line 4454 of file utils.h.

void frepple::utils::XMLInput::setUserArea ( void *  v)
inline

Updates the user definable pointer. This pointer is used to store status information between handler calls.

Definition at line 4445 of file utils.h.

void frepple::utils::XMLInput::setUserExit ( PyObject *  p)
inline

Specify a Python callback function that is for every object read from the input stream.

Definition at line 4467 of file utils.h.

void frepple::utils::XMLInput::shutdown ( )

Abort the parsing. The actual shutdown cannot be called inside a SAX handler function, so actual shutdown is deferred until the next iteration of the feed loop.

Definition at line 388 of file xmlparser.cpp.


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