source: NonGTP/Xerces/xercesc/validators/schema/XSDDOMParser.hpp @ 188

Revision 188, 14.4 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2002 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: XSDDOMParser.hpp,v 1.10 2004/01/29 11:52:31 cargilld Exp $
59 *
60 */
61
62#if !defined(XSDDOMPARSER_HPP)
63#define XSDDOMPARSER_HPP
64
65
66#include <xercesc/parsers/XercesDOMParser.hpp>
67#include <xercesc/validators/schema/XSDErrorReporter.hpp>
68#include <xercesc/validators/schema/XSDLocator.hpp>
69
70XERCES_CPP_NAMESPACE_BEGIN
71
72class DOMElement;
73class XMLValidator;
74
75
76/**
77  * This class is used to parse schema documents into DOM trees
78  */
79class PARSERS_EXPORT XSDDOMParser : public XercesDOMParser
80{
81public :
82
83    // -----------------------------------------------------------------------
84    //  Constructors and Detructor
85    // -----------------------------------------------------------------------
86
87    /** @name Constructors and Destructor */
88    //@{
89    /** Construct a XSDDOMParser, with an optional validator
90      *
91      * Constructor with an instance of validator class to use for
92      * validation. If you don't provide a validator, a default one will
93      * be created for you in the scanner.
94      *
95      * @param gramPool   Pointer to the grammar pool instance from
96      *                   external application.
97      *                   The parser does NOT own it.
98      *
99      * @param valToAdopt Pointer to the validator instance to use. The
100      *                   parser is responsible for freeing the memory.
101      */
102    XSDDOMParser
103    (
104          XMLValidator* const   valToAdopt = 0
105        , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
106        , XMLGrammarPool* const gramPool = 0       
107    );
108
109    /**
110      * Destructor
111      */
112    ~XSDDOMParser();
113
114    //@}
115
116    // -----------------------------------------------------------------------
117    //  Implementation of the XMLDocumentHandler interface.
118    // -----------------------------------------------------------------------
119
120    /** @name Implementation of the XMLDocumentHandler interface. */
121    //@{
122
123    /** Handle a start element event
124      *
125      * This method is used to report the start of an element. It is
126      * called at the end of the element, by which time all attributes
127      * specified are also parsed. A new DOM Element node is created
128      * along with as many attribute nodes as required. This new element
129      * is added appended as a child of the current node in the tree, and
130      * then replaces it as the current node (if the isEmpty flag is false.)
131      *
132      * @param elemDecl A const reference to the object containing element
133      *                 declaration information.
134      * @param urlId    An id referring to the namespace prefix, if
135      *                 namespaces setting is switched on.
136      * @param elemPrefix A const pointer to a Unicode string containing
137      *                 the namespace prefix for this element. Applicable
138      *                 only when namespace processing is enabled.
139      * @param attrList A const reference to the object containing the
140      *                 list of attributes just scanned for this element.
141      * @param attrCount A count of number of attributes in the list
142      *                 specified by the parameter 'attrList'.
143      * @param isEmpty  A flag indicating whether this is an empty element
144      *                 or not. If empty, then no endElement() call will
145      *                 be made.
146      * @param isRoot   A flag indicating whether this element was the
147      *                 root element.
148      * @see DocumentHandler#startElement
149      */
150    virtual void startElement
151    (
152        const   XMLElementDecl&         elemDecl
153        , const unsigned int            urlId
154        , const XMLCh* const            elemPrefix
155        , const RefVectorOf<XMLAttr>&   attrList
156        , const unsigned int            attrCount
157        , const bool                    isEmpty
158        , const bool                    isRoot
159    );
160
161    /** Handle and end of element event
162      *
163      * This method is used to indicate the end tag of an element. The
164      * DOM parser pops the current element off the top of the element
165      * stack, and make it the new current element.
166      *
167      * @param elemDecl A const reference to the object containing element
168      *                 declaration information.
169      * @param urlId    An id referring to the namespace prefix, if
170      *                 namespaces setting is switched on.
171      * @param isRoot   A flag indicating whether this element was the
172      *                 root element.
173      * @param elemPrefix A const pointer to a Unicode string containing
174      *                 the namespace prefix for this element. Applicable
175      *                 only when namespace processing is enabled.
176      */
177    virtual void endElement
178    (
179        const   XMLElementDecl& elemDecl
180        , const unsigned int    urlId
181        , const bool            isRoot
182        , const XMLCh* const    elemPrefix
183    );
184
185    /** Handle document character events
186      *
187      * This method is used to report all the characters scanned by the
188      * parser. This DOM implementation stores this data in the appropriate
189      * DOM node, creating one if necessary.
190      *
191      * @param chars   A const pointer to a Unicode string representing the
192      *                character data.
193      * @param length  The length of the Unicode string returned in 'chars'.
194      * @param cdataSection  A flag indicating if the characters represent
195      *                      content from the CDATA section.
196      */
197    virtual void docCharacters
198    (
199        const   XMLCh* const    chars
200        , const unsigned int    length
201        , const bool            cdataSection
202    );
203
204    /** Handle a document comment event
205      *
206      * This method is used to report any comments scanned by the parser.
207      * A new comment node is created which stores this data.
208      *
209      * @param comment A const pointer to a null terminated Unicode
210      *                string representing the comment text.
211      */
212    virtual void docComment
213    (
214        const   XMLCh* const    comment
215    );
216
217    /** Handle a start entity reference event
218      *
219      * This method is used to indicate the start of an entity reference.
220      * If the expand entity reference flag is true, then a new
221      * DOM Entity reference node is created.
222      *
223      * @param entDecl A const reference to the object containing the
224      *                entity declaration information.
225      */
226    virtual void startEntityReference
227    (
228        const   XMLEntityDecl&  entDecl
229    );
230
231    /** Handle and end of entity reference event
232      *
233      * This method is used to indicate that an end of an entity reference
234      * was just scanned.
235      *
236      * @param entDecl A const reference to the object containing the
237      *                entity declaration information.
238      */
239    virtual void endEntityReference
240    (
241        const   XMLEntityDecl&  entDecl
242    );
243
244    /** Handle an ignorable whitespace vent
245      *
246      * This method is used to report all the whitespace characters, which
247      * are determined to be 'ignorable'. This distinction between characters
248      * is only made, if validation is enabled.
249      *
250      * Any whitespace before content is ignored. If the current node is
251      * already of type DOMNode::TEXT_NODE, then these whitespaces are
252      * appended, otherwise a new Text node is created which stores this
253      * data. Essentially all contiguous ignorable characters are collected
254      * in one node.
255      *
256      * @param chars   A const pointer to a Unicode string representing the
257      *                ignorable whitespace character data.
258      * @param length  The length of the Unicode string 'chars'.
259      * @param cdataSection  A flag indicating if the characters represent
260      *                      content from the CDATA section.
261      */
262    virtual void ignorableWhitespace
263    (
264        const   XMLCh* const    chars
265        , const unsigned int    length
266        , const bool            cdataSection
267    );
268
269    //@}
270
271    // -----------------------------------------------------------------------
272    //  Get methods
273    // -----------------------------------------------------------------------
274    bool getSawFatal() const;
275
276
277    // -----------------------------------------------------------------------
278    //  Set methods
279    // -----------------------------------------------------------------------
280    void setUserErrorReporter(XMLErrorReporter* const errorReporter);
281    void setUserEntityHandler(XMLEntityHandler* const entityHandler);
282
283
284    // -----------------------------------------------------------------------
285    //  XMLErrorReporter interface
286    // -----------------------------------------------------------------------
287    virtual void error
288    (
289        const   unsigned int        errCode
290        , const XMLCh* const        errDomain
291        , const ErrTypes            type
292        , const XMLCh* const        errorText
293        , const XMLCh* const        systemId
294        , const XMLCh* const        publicId
295        , const XMLSSize_t          lineNum
296        , const XMLSSize_t          colNum
297    );
298
299    // -----------------------------------------------------------------------
300    //  XMLEntityHandler interface
301    // -----------------------------------------------------------------------
302    virtual InputSource* resolveEntity
303    (
304        const   XMLCh* const    publicId
305        , const XMLCh* const    systemId
306        , const XMLCh* const    baseURI = 0
307    );
308
309protected :
310    // -----------------------------------------------------------------------
311    //  Protected Helper methods
312    // -----------------------------------------------------------------------
313    virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
314                                            const XMLCh *qualifiedName);
315
316private:
317    // -----------------------------------------------------------------------
318    //  Unimplemented constructors and operators
319    // -----------------------------------------------------------------------
320    XSDDOMParser(const XSDDOMParser&);
321    XSDDOMParser& operator=(const XSDDOMParser&);
322
323    // -----------------------------------------------------------------------
324    //  Private Helper methods
325    // -----------------------------------------------------------------------
326    void startAnnotation
327    (
328        const   XMLElementDecl&         elemDecl
329        , const RefVectorOf<XMLAttr>&   attrList
330        , const unsigned int            attrCount
331    );
332    void startAnnotationElement
333    (
334        const   XMLElementDecl&         elemDecl
335        , const RefVectorOf<XMLAttr>&   attrList
336        , const unsigned int            attrCount
337    );
338    void endAnnotationElement
339    (
340        const XMLElementDecl& elemDecl
341        ,     bool            complete
342    );
343
344    // -----------------------------------------------------------------------
345    //  Private data members
346    // -----------------------------------------------------------------------
347    bool                         fSawFatal;
348    int                          fAnnotationDepth;
349    int                          fInnerAnnotationDepth;
350    int                          fDepth;
351    XMLErrorReporter*            fUserErrorReporter;
352    XMLEntityHandler*            fUserEntityHandler;
353    ValueVectorOf<unsigned int>* fURIs;
354    XMLBuffer                    fAnnotationBuf;
355    XSDErrorReporter             fXSDErrorReporter;
356    XSDLocator                   fXSLocator;
357};
358
359
360inline bool XSDDOMParser::getSawFatal() const
361{
362    return fSawFatal;
363}
364
365XERCES_CPP_NAMESPACE_END
366
367#endif
Note: See TracBrowser for help on using the repository browser.