Main Page | Class Hierarchy | Compound List | File List | Compound Members

BxBinxSaxParser.h

00001 /********************************************************************
00002  * Binx
00003  * $Id: BxBinxSaxParser_8h-source.html,v 1.1.1.1 2006/04/19 14:19:02 edikt2 Exp $
00004  *
00005  * Class for parsing the BinX document using the SAX engine
00006  *
00007  *
00008  * edikt::BinX
00009  * www.edikt.org
00010  * support@edikt.org
00011  *
00012  * Copyright (c) 2005 The University of Edinburgh.
00013  *
00014  ********************************************************************/
00015 
00016 #ifndef BXBINXSAXPARSER_H
00017 #define BXBINXSAXPARSER_H
00018 
00019 #include <xercesc/sax2/Attributes.hpp>
00020 #include <xercesc/sax2/DefaultHandler.hpp>
00021 
00022 XERCES_CPP_NAMESPACE_USE
00023 
00024 #include "BxDataset.h"
00025 #include "BxBinxParser.h"
00026 #include "BxSaxHandler.h"
00027 #include "BxDataObjectStack.h"
00028 
00029 /*
00030  * A BinX parser implementation supported by a SAX engine.
00031  * This class is an implementation of class BxBinxParser.
00032  *
00033  * <BR>
00034  * After parsing a BinX document, the whole meta-dataset is built in memory pointed to by
00035  * BxBinxParser::datasetRoot_.  The caller is responsible to obtain this pointer by calling getDataset()
00036  * method and destroy it after use.  Internally, this is used by the BxBinXFile class to parse
00037  * a BinX document and the dataset tree is destroyed by its destructor.
00038  * <BR>
00039  * \internal
00040     The original DOM parser relies on BxBinxSchema::search method for locating a tag element.
00041     This parser is more deterministic in the way to identify each element section. For example,
00042     It checks only for <defineType> in a <definitions> section, all other possibilities are
00043     rejected as invalid.  This strictly follows the BinX schema and can be used for validation
00044     as well as parsing.  Obviously the deterministic method is more efficient.  As the elements
00045     are recognised by the SAX parser which knows nothing about BinX, it is necessary to tell
00046     which context the current node resides so as to assign the following parsing to proper
00047     element recogniser.  This is done by function pointer replacement during parsing.  For
00048     example, after parsing <definitions> element, the function pointer for parsing next element
00049     is assigned to be parseDefinitionsStart which is responsible to identify <defineType> only.
00050  *
00051  * <BR><B>Since:</B>  BinX version 1.1.
00052  */
00053 class DECLSPEC BxBinxSaxParser : public BxBinxParser, DefaultHandler
00054 {
00055 public:
00056         // The default constructor
00057     BxBinxSaxParser();
00058 
00059         // The destructor
00060     virtual ~BxBinxSaxParser();
00061 
00062     // event handlers for SaxHandler
00063     void startDocument();
00064     void endDocument() {}
00065     void startElement(const XMLCh* const, const XMLCh* const localname, const XMLCh* const, const Attributes& attrs);
00066     void endElement(const XMLCh* const, const XMLCh* const localname, const XMLCh* const);
00067     void characters(const XMLCh* const, const unsigned int) {}
00068     void ignorableWhitespace(const XMLCh* const, const unsigned int) {}
00069     //  Handlers for the SAX ErrorHandler interface
00070     void warning(const SAXParseException& exception);
00071     void error(const SAXParseException& exception);
00072     void fatalError(const SAXParseException& exception);
00073     void resetErrors();
00074 
00075     virtual char* className() const { return "BxBinxSaxParser"; }
00076 
00077     virtual bool parse(const char* xmlFile);
00078 
00079 private:
00080         // Private operations
00081 
00082         /* Unimplemented constructor and assignment operator */
00083         // The copy constructor
00084     BxBinxSaxParser(const BxBinxSaxParser&);
00085 
00086         // The assignment operator
00087     void operator=(const BxBinxSaxParser&);
00088 
00089     bool parseFile(const char*);
00090 
00091     void parseXmlStart(const char*, const Attributes&);
00092     void parseBinxStart(const char*, const Attributes&);
00093     void parseDefinitionsStart(const char*, const Attributes&);
00094     void parseParametersStart(const char*, const Attributes&);
00095     void parseDatasetStart(const char*, const Attributes&);
00096     void parseArrayStart(const char*, const Attributes&);
00097     void parseUnionStart(const char*, const Attributes&);
00098 
00099     void parseXmlEnd(const char*);
00100     void parseBinxEnd(const char*);
00101     void parseDefinitionsEnd(const char*);
00102     void parseParametersEnd(const char*);
00103     void parseDatasetEnd(const char*);
00104     void parseArrayEnd(const char*);
00105     void parseUnionEnd(const char*);
00106 
00107     void parseCommonAttributes(const Attributes&, BxDataObject*);
00108     void parseStringAttributes(const Attributes&, BxDataObject*);
00109     void parseStructAttributes(const Attributes&, BxDataObject*);
00110     void dispatchDataObject();
00111     BxDataObject* createPrimitiveDataObject(const char*);
00112     char* getAttribute(const Attributes&, const char*);
00113 
00114     BxByteOrder makeByteOrder(char*);
00115 
00116 
00117         // Private data
00118 
00119     BxSaxHandler* pSaxHandler_;    //SAX event handler
00120     char* sDiscriminantValue_; //temporary string for discriminantValue attribute
00121     char* typeName_;    //temporarily save typeName for <defineType> element
00122     bool errors_;        //sax error handler recorder
00123     bool unknownElement_;   //set to true if unknown tag met
00124     int descendants_;   //keep how many descendants in unknown element
00125     PointerStack stack_; //stack to keep parsed tree
00126     BxByteOrder bo_;     //temporarily for byteOrder on <binx> level
00127 
00128     void (BxBinxSaxParser::*parseStart)(const char*, const Attributes&); //function pointer to parse each element
00129     void (BxBinxSaxParser::*parseEnd)(const char*); //function pointer to parse each element
00130 };
00131 
00132 #endif

Generated on Fri May 6 13:36:17 2005 for edikt::BinX by doxygen 1.3.3