OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
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. More...
 
int 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. More...
 
SaxParsergetParser () const
 
bool isExceptionState () const
 Used by the callbacks to know whether we have a deferred exception. More...
 
bool parse (const string &ncmlFilename)
 Do a SAX parse of the ncmlFilename and pass the calls to wrapper parser. More...
 
void rethrowException ()
 If there's a deferred exception, this will throw the right subclass type from the preserved state at deferral time. More...
 
 SaxParserWrapper (SaxParser &parser)
 Create a wrapper for the given parser. More...
 
virtual ~SaxParserWrapper ()
 

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 63 of file SaxParserWrapper.h.

Constructor & Destructor Documentation

SaxParserWrapper::SaxParserWrapper ( SaxParser parser)

Create a wrapper for the given parser.

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

Definition at line 307 of file SaxParserWrapper.cc.

SaxParserWrapper::~SaxParserWrapper ( )
virtual

Definition at line 319 of file SaxParserWrapper.cc.

Member Function Documentation

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 367 of file SaxParserWrapper.cc.

References BESError::get_error_type(), BESError::get_file(), BESError::get_line(), and BESError::get_message().

Here is the call graph for this function:

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 413 of file SaxParserWrapper.cc.

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

Definition at line 127 of file SaxParserWrapper.h.

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

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

Definition at line 145 of file SaxParserWrapper.h.

Referenced by parse().

bool SaxParserWrapper::parse ( const 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 327 of file SaxParserWrapper.cc.

References isExceptionState(), and rethrowException().

Referenced by ncml_module::SimpleLocationParser::parseAndGetLocation(), and ncml_module::NCMLParser::parseInto().

Here is the call graph for this function:

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 379 of file SaxParserWrapper.cc.

References BES_FORBIDDEN_ERROR, BES_INTERNAL_ERROR, BES_INTERNAL_FATAL_ERROR, BES_NOT_FOUND_ERROR, and BES_SYNTAX_USER_ERROR.

Referenced by parse().


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