source: NonGTP/Xerces/xerces/include/xercesc/validators/schema/XSDDOMParser.hpp @ 358

Revision 358, 12.4 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: XSDDOMParser.hpp,v 1.12 2004/09/08 13:56:57 peiyongz Exp $
19 *
20 */
21
22#if !defined(XSDDOMPARSER_HPP)
23#define XSDDOMPARSER_HPP
24
25
26#include <xercesc/parsers/XercesDOMParser.hpp>
27#include <xercesc/validators/schema/XSDErrorReporter.hpp>
28#include <xercesc/validators/schema/XSDLocator.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32class DOMElement;
33class XMLValidator;
34
35
36/**
37  * This class is used to parse schema documents into DOM trees
38  */
39class PARSERS_EXPORT XSDDOMParser : public XercesDOMParser
40{
41public :
42
43    // -----------------------------------------------------------------------
44    //  Constructors and Detructor
45    // -----------------------------------------------------------------------
46
47    /** @name Constructors and Destructor */
48    //@{
49    /** Construct a XSDDOMParser, with an optional validator
50      *
51      * Constructor with an instance of validator class to use for
52      * validation. If you don't provide a validator, a default one will
53      * be created for you in the scanner.
54      *
55      * @param gramPool   Pointer to the grammar pool instance from
56      *                   external application.
57      *                   The parser does NOT own it.
58      *
59      * @param valToAdopt Pointer to the validator instance to use. The
60      *                   parser is responsible for freeing the memory.
61      */
62    XSDDOMParser
63    (
64          XMLValidator* const   valToAdopt = 0
65        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
66        , XMLGrammarPool* const gramPool = 0       
67    );
68
69    /**
70      * Destructor
71      */
72    ~XSDDOMParser();
73
74    //@}
75
76    // -----------------------------------------------------------------------
77    //  Implementation of the XMLDocumentHandler interface.
78    // -----------------------------------------------------------------------
79
80    /** @name Implementation of the XMLDocumentHandler interface. */
81    //@{
82
83    /** Handle a start element event
84      *
85      * This method is used to report the start of an element. It is
86      * called at the end of the element, by which time all attributes
87      * specified are also parsed. A new DOM Element node is created
88      * along with as many attribute nodes as required. This new element
89      * is added appended as a child of the current node in the tree, and
90      * then replaces it as the current node (if the isEmpty flag is false.)
91      *
92      * @param elemDecl A const reference to the object containing element
93      *                 declaration information.
94      * @param urlId    An id referring to the namespace prefix, if
95      *                 namespaces setting is switched on.
96      * @param elemPrefix A const pointer to a Unicode string containing
97      *                 the namespace prefix for this element. Applicable
98      *                 only when namespace processing is enabled.
99      * @param attrList A const reference to the object containing the
100      *                 list of attributes just scanned for this element.
101      * @param attrCount A count of number of attributes in the list
102      *                 specified by the parameter 'attrList'.
103      * @param isEmpty  A flag indicating whether this is an empty element
104      *                 or not. If empty, then no endElement() call will
105      *                 be made.
106      * @param isRoot   A flag indicating whether this element was the
107      *                 root element.
108      * @see DocumentHandler#startElement
109      */
110    virtual void startElement
111    (
112        const   XMLElementDecl&         elemDecl
113        , const unsigned int            urlId
114        , const XMLCh* const            elemPrefix
115        , const RefVectorOf<XMLAttr>&   attrList
116        , const unsigned int            attrCount
117        , const bool                    isEmpty
118        , const bool                    isRoot
119    );
120
121    /** Handle and end of element event
122      *
123      * This method is used to indicate the end tag of an element. The
124      * DOM parser pops the current element off the top of the element
125      * stack, and make it the new current element.
126      *
127      * @param elemDecl A const reference to the object containing element
128      *                 declaration information.
129      * @param urlId    An id referring to the namespace prefix, if
130      *                 namespaces setting is switched on.
131      * @param isRoot   A flag indicating whether this element was the
132      *                 root element.
133      * @param elemPrefix A const pointer to a Unicode string containing
134      *                 the namespace prefix for this element. Applicable
135      *                 only when namespace processing is enabled.
136      */
137    virtual void endElement
138    (
139        const   XMLElementDecl& elemDecl
140        , const unsigned int    urlId
141        , const bool            isRoot
142        , const XMLCh* const    elemPrefix
143    );
144
145    /** Handle document character events
146      *
147      * This method is used to report all the characters scanned by the
148      * parser. This DOM implementation stores this data in the appropriate
149      * DOM node, creating one if necessary.
150      *
151      * @param chars   A const pointer to a Unicode string representing the
152      *                character data.
153      * @param length  The length of the Unicode string returned in 'chars'.
154      * @param cdataSection  A flag indicating if the characters represent
155      *                      content from the CDATA section.
156      */
157    virtual void docCharacters
158    (
159        const   XMLCh* const    chars
160        , const unsigned int    length
161        , const bool            cdataSection
162    );
163
164    /** Handle a document comment event
165      *
166      * This method is used to report any comments scanned by the parser.
167      * A new comment node is created which stores this data.
168      *
169      * @param comment A const pointer to a null terminated Unicode
170      *                string representing the comment text.
171      */
172    virtual void docComment
173    (
174        const   XMLCh* const    comment
175    );
176
177    /** Handle a start entity reference event
178      *
179      * This method is used to indicate the start of an entity reference.
180      * If the expand entity reference flag is true, then a new
181      * DOM Entity reference node is created.
182      *
183      * @param entDecl A const reference to the object containing the
184      *                entity declaration information.
185      */
186    virtual void startEntityReference
187    (
188        const   XMLEntityDecl&  entDecl
189    );
190
191    /** Handle and end of entity reference event
192      *
193      * This method is used to indicate that an end of an entity reference
194      * was just scanned.
195      *
196      * @param entDecl A const reference to the object containing the
197      *                entity declaration information.
198      */
199    virtual void endEntityReference
200    (
201        const   XMLEntityDecl&  entDecl
202    );
203
204    /** Handle an ignorable whitespace vent
205      *
206      * This method is used to report all the whitespace characters, which
207      * are determined to be 'ignorable'. This distinction between characters
208      * is only made, if validation is enabled.
209      *
210      * Any whitespace before content is ignored. If the current node is
211      * already of type DOMNode::TEXT_NODE, then these whitespaces are
212      * appended, otherwise a new Text node is created which stores this
213      * data. Essentially all contiguous ignorable characters are collected
214      * in one node.
215      *
216      * @param chars   A const pointer to a Unicode string representing the
217      *                ignorable whitespace character data.
218      * @param length  The length of the Unicode string 'chars'.
219      * @param cdataSection  A flag indicating if the characters represent
220      *                      content from the CDATA section.
221      */
222    virtual void ignorableWhitespace
223    (
224        const   XMLCh* const    chars
225        , const unsigned int    length
226        , const bool            cdataSection
227    );
228
229    //@}
230
231    // -----------------------------------------------------------------------
232    //  Get methods
233    // -----------------------------------------------------------------------
234    bool getSawFatal() const;
235
236
237    // -----------------------------------------------------------------------
238    //  Set methods
239    // -----------------------------------------------------------------------
240    void setUserErrorReporter(XMLErrorReporter* const errorReporter);
241    void setUserEntityHandler(XMLEntityHandler* const entityHandler);
242
243
244    // -----------------------------------------------------------------------
245    //  XMLErrorReporter interface
246    // -----------------------------------------------------------------------
247    virtual void error
248    (
249        const   unsigned int        errCode
250        , const XMLCh* const        errDomain
251        , const ErrTypes            type
252        , const XMLCh* const        errorText
253        , const XMLCh* const        systemId
254        , const XMLCh* const        publicId
255        , const XMLSSize_t          lineNum
256        , const XMLSSize_t          colNum
257    );
258
259    // -----------------------------------------------------------------------
260    //  XMLEntityHandler interface
261    // -----------------------------------------------------------------------
262    virtual InputSource* resolveEntity
263    (
264        const   XMLCh* const    publicId
265        , const XMLCh* const    systemId
266        , const XMLCh* const    baseURI = 0
267    );
268
269    virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
270
271protected :
272    // -----------------------------------------------------------------------
273    //  Protected Helper methods
274    // -----------------------------------------------------------------------
275    virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
276                                            const XMLCh *qualifiedName);
277
278private:
279    // -----------------------------------------------------------------------
280    //  Unimplemented constructors and operators
281    // -----------------------------------------------------------------------
282    XSDDOMParser(const XSDDOMParser&);
283    XSDDOMParser& operator=(const XSDDOMParser&);
284
285    // -----------------------------------------------------------------------
286    //  Private Helper methods
287    // -----------------------------------------------------------------------
288    void startAnnotation
289    (
290        const   XMLElementDecl&         elemDecl
291        , const RefVectorOf<XMLAttr>&   attrList
292        , const unsigned int            attrCount
293    );
294    void startAnnotationElement
295    (
296        const   XMLElementDecl&         elemDecl
297        , const RefVectorOf<XMLAttr>&   attrList
298        , const unsigned int            attrCount
299    );
300    void endAnnotationElement
301    (
302        const XMLElementDecl& elemDecl
303        ,     bool            complete
304    );
305
306    // -----------------------------------------------------------------------
307    //  Private data members
308    // -----------------------------------------------------------------------
309    bool                         fSawFatal;
310    int                          fAnnotationDepth;
311    int                          fInnerAnnotationDepth;
312    int                          fDepth;
313    XMLErrorReporter*            fUserErrorReporter;
314    XMLEntityHandler*            fUserEntityHandler;
315    ValueVectorOf<unsigned int>* fURIs;
316    XMLBuffer                    fAnnotationBuf;
317    XSDErrorReporter             fXSDErrorReporter;
318    XSDLocator                   fXSLocator;
319};
320
321
322inline bool XSDDOMParser::getSawFatal() const
323{
324    return fSawFatal;
325}
326
327XERCES_CPP_NAMESPACE_END
328
329#endif
Note: See TracBrowser for help on using the repository browser.