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:

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 ()
 

Static Public Member Functions

static char * transcodeUTF8 (const XMLCh *)
 

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 4323 of file utils.h.

Member Typedef Documentation

Definition at line 4326 of file utils.h.

Constructor & Destructor Documentation

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

Constructor.

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

Definition at line 78 of file xmlparser.cpp.

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

Destructor.

Definition at line 4484 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 4578 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 4490 of file utils.h.

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

Returns a reference to the current element.

Definition at line 4549 of file utils.h.

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

Returns a reference to the parent element.

Definition at line 4545 of file utils.h.

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

Clears the previously read object.

Definition at line 4538 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 4535 of file utils.h.

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

Returns the user definable pointer.

Definition at line 4565 of file utils.h.

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

Return the Python callback function.

Definition at line 4586 of file utils.h.

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

Ignore an element.

Definition at line 4509 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 4519 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 4513 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 500 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 4605 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 388 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 4570 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 4561 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 4583 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 415 of file xmlparser.cpp.

char * frepple::utils::XMLInput::transcodeUTF8 ( const XMLCh *  xercesChars)
static

Transcode the Xerces XML characters to our UTF8 encoded buffer. This method uses a statically allocated buffer, and subsequent calls to this method will overwrite the previous results.

Definition at line 66 of file xmlparser.cpp.


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