bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ncml_module::SaxParserWrapper Class Reference

Wrapper for libxml SAX parser C callbacks into C++. More...

#include <SaxParserWrapper.h>

Collaboration diagram for ncml_module::SaxParserWrapper:
Collaboration graph

Public Member Functions

void deferException (BESError &theErr)
 The remaining calls are for the internals of the parser, but need to be public.
 
int getCurrentParseLine () const
 
SaxParsergetParser () const
 
bool isExceptionState () const
 
bool parse (const std::string &ncmlFilename)
 Do a SAX parse of the ncmlFilename and pass the calls to wrapper parser.
 
void rethrowException ()
 
 SaxParserWrapper (SaxParser &parser)
 Create a wrapper for the given parser.
 

Detailed Description

Wrapper for libxml SAX parser C callbacks into C++.

On a parse(const string& ncmlFilename) call, the filename is parsed using the libxml C SAX parser and the C callbacks are passed onto our C++ parser via the SaxParser interface class.

Since the underlying libxml is C and uses its internal static memory pools which will be used by other parts of the BES, we have to be careful with exceptions. Any BESError thrown in a SaxParser callback is caught and deferred (stored in this). We enter an error state and ignore all further callbacks until the libxml parser exits cleanly. Then we recreate and rethrow the deferred exception.

Any other exception types (...) are also caught and a local BESInternalError is thrown at parse end, so be careful with which exceptions are thrown in SaxParser callbacks.

Author
mjohnson m.joh.nosp@m.nson.nosp@m.@open.nosp@m.dap..nosp@m.org

Definition at line 59 of file SaxParserWrapper.h.

Constructor & Destructor Documentation

◆ SaxParserWrapper()

SaxParserWrapper::SaxParserWrapper ( SaxParser & parser)
explicit

Create a wrapper for the given parser.

Parameters
parserMust exist for the duration of the life of the wrapper.

Definition at line 305 of file SaxParserWrapper.cc.

◆ ~SaxParserWrapper()

SaxParserWrapper::~SaxParserWrapper ( )
virtual

Definition at line 310 of file SaxParserWrapper.cc.

Member Function Documentation

◆ deferException()

void SaxParserWrapper::deferException ( BESError & theErr)

The remaining calls are for the internals of the parser, but need to be public.

If we get a BESError exception thrown in a SaxParser call, defer it by entering the EXCEPTION state and copying the exception. In EXCEPTION state, we don't pass on any callbacks to SaxParser. When the underlying C parser completes and cleans up its storage, then we recreate and throw the exception. NOTE: We can't store theErr itself since it will be destroyed by the exception system.

See also
rethrowException

Definition at line 343 of file SaxParserWrapper.cc.

◆ getCurrentParseLine()

int SaxParserWrapper::getCurrentParseLine ( ) const

Return the current line of the parse we're on, assuming we're not in an exception state and that we are parsing.

Definition at line 380 of file SaxParserWrapper.cc.

◆ getParser()

SaxParser & ncml_module::SaxParserWrapper::getParser ( ) const
inline

Definition at line 129 of file SaxParserWrapper.h.

◆ isExceptionState()

bool ncml_module::SaxParserWrapper::isExceptionState ( ) const
inline

Used by the callbacks to know whether we have a deferred exception.

Definition at line 150 of file SaxParserWrapper.h.

◆ parse()

bool SaxParserWrapper::parse ( const std::string & ncmlFilename)

Do a SAX parse of the ncmlFilename and pass the calls to wrapper parser.

Parameters
pathto the file to parse.
Exceptions
Canthrow BESError via SaxParser
Returns
successful parse

Definition at line 319 of file SaxParserWrapper.cc.

◆ rethrowException()

void SaxParserWrapper::rethrowException ( )

If there's a deferred exception, this will throw the right subclass type from the preserved state at deferral time.

Definition at line 354 of file SaxParserWrapper.cc.


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