source: trunk/VUT/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/schema/SchemaValidator.hpp @ 358

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

xerces added

Line 
1/*
2 * Copyright 2001-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 * $Log: SchemaValidator.hpp,v $
19 * Revision 1.27  2004/09/08 13:56:57  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.26  2004/03/01 21:06:38  knoaman
23 * Fix for UPA checking
24 *
25 * Revision 1.25  2004/01/29 11:52:31  cargilld
26 * Code cleanup changes to get rid of various compiler diagnostic messages.
27 *
28 * Revision 1.24  2003/12/03 20:00:27  neilg
29 * PSVI fix:  cannot allow validator to reset its element content buffer before exposing it to the application
30 *
31 * Revision 1.23  2003/11/28 21:18:32  knoaman
32 * Make use of canonical representation in PSVIElement
33 *
34 * Revision 1.22  2003/11/27 22:52:37  knoaman
35 * PSVIElement implementation
36 *
37 * Revision 1.21  2003/11/27 06:10:31  neilg
38 * PSVIAttribute implementation
39 *
40 * Revision 1.20  2003/11/24 05:13:20  neilg
41 * expose validator that actually validated attribute.  Clean up union handling
42 *
43 * Revision 1.19  2003/10/05 02:09:37  neilg
44 * the validator now keeps track of the current complex and simple type (including if this is an xsi:type).  This allows both the validator and the scanner to know what the current type is, without the need to modify the element declaration each time an xsi:type is seen
45 *
46 * Revision 1.18  2003/08/14 03:01:04  knoaman
47 * Code refactoring to improve performance of validation.
48 *
49 * Revision 1.17  2003/05/18 14:02:08  knoaman
50 * Memory manager implementation: pass per instance manager.
51 *
52 * Revision 1.16  2003/05/16 21:43:21  knoaman
53 * Memory manager implementation: Modify constructors to pass in the memory manager.
54 *
55 * Revision 1.15  2003/05/16 03:15:51  knoaman
56 * Partial implementation of the configurable memory manager.
57 *
58 * Revision 1.14  2003/05/15 18:57:27  knoaman
59 * Partial implementation of the configurable memory manager.
60 *
61 * Revision 1.13  2003/01/20 19:04:48  knoaman
62 * Fix for particle derivation checking.
63 *
64 * Revision 1.12  2003/01/13 20:16:51  knoaman
65 * [Bug 16024] SchemaSymbols.hpp conflicts C++ Builder 6 dir.h
66 *
67 * Revision 1.11  2003/01/09 22:34:54  tng
68 * [Bug 14955] error validating parser.
69 *
70 * Revision 1.10  2002/11/07 21:57:37  tng
71 * Fix the following Schema Test Failures:
72 * 1. Typo when comparing miscFlags with FIXED
73 * 2. If xsi:type is specified, need to validate using that xsitype validator even if the type was any
74 * 3. Need to check ID/IDREFs for element value
75 * 4. Need to duplicate attribute id for wildcard scenario.
76 *
77 * Revision 1.9  2002/11/04 14:49:42  tng
78 * C++ Namespace Support.
79 *
80 * Revision 1.8  2002/09/04 18:17:41  tng
81 * Do not set IDREF to used during prevalidation.
82 *
83 * Revision 1.7  2002/07/11 18:55:45  knoaman
84 * Add a flag to the preContentValidation method to indicate whether to validate
85 * default/fixed attributes or not.
86 *
87 * Revision 1.6  2002/06/17 18:09:29  tng
88 * DOM L3: support "datatype-normalization"
89 *
90 * Revision 1.5  2002/05/22 20:54:14  knoaman
91 * Prepare for DOM L3 :
92 * - Make use of the XMLEntityHandler/XMLErrorReporter interfaces, instead of using
93 * EntityHandler/ErrorHandler directly.
94 * - Add 'AbstractDOMParser' class to provide common functionality for XercesDOMParser
95 * and DOMBuilder.
96 *
97 * Revision 1.4  2002/04/19 13:33:23  knoaman
98 * Fix for bug 8236.
99 *
100 * Revision 1.3  2002/04/01 15:47:06  knoaman
101 * Move Element Consistency checking (ref to global declarations) to SchemaValidator.
102 *
103 * Revision 1.2  2002/03/25 20:25:32  knoaman
104 * Move particle derivation checking from TraverseSchema to SchemaValidator.
105 *
106 * Revision 1.1.1.1  2002/02/01 22:22:47  peiyongz
107 * sane_include
108 *
109 * Revision 1.8  2001/11/13 13:25:08  tng
110 * Deprecate function XMLValidator::checkRootElement.
111 *
112 * Revision 1.7  2001/06/05 16:51:21  knoaman
113 * Add 'const' to getGrammar - submitted by Peter A. Volchek.
114 *
115 * Revision 1.6  2001/05/11 15:17:48  tng
116 * Schema: Nillable fixes.
117 *
118 * Revision 1.5  2001/05/11 13:27:37  tng
119 * Copyright update.
120 *
121 * Revision 1.4  2001/05/03 20:34:45  tng
122 * Schema: SchemaValidator update
123 *
124 * Revision 1.3  2001/04/19 18:17:40  tng
125 * Schema: SchemaValidator update, and use QName in Content Model
126 *
127 * Revision 1.2  2001/03/30 16:35:20  tng
128 * Schema: Whitespace normalization.
129 *
130 * Revision 1.1  2001/03/21 21:56:33  tng
131 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
132 *
133 */
134
135
136
137#if !defined(SCHEMAVALIDATOR_HPP)
138#define SCHEMAVALIDATOR_HPP
139
140#include <xercesc/framework/XMLValidator.hpp>
141#include <xercesc/framework/XMLBuffer.hpp>
142#include <xercesc/util/ValueStackOf.hpp>
143#include <xercesc/validators/common/ContentSpecNode.hpp>
144#include <xercesc/validators/schema/SchemaGrammar.hpp>
145#include <xercesc/validators/schema/XSDErrorReporter.hpp>
146
147XERCES_CPP_NAMESPACE_BEGIN
148
149class GrammarResolver;
150class DatatypeValidator;
151class SchemaElementDecl;
152
153//
154//  This is a derivative of the abstract validator interface. This class
155//  implements a validator that supports standard XML Schema semantics.
156//  This class handles scanning the of the schema, and provides
157//  the standard validation services against the Schema info it found.
158//
159class VALIDATORS_EXPORT SchemaValidator : public XMLValidator
160{
161public:
162    // -----------------------------------------------------------------------
163    //  Constructors and Destructor
164    // -----------------------------------------------------------------------
165    SchemaValidator
166    (
167          XMLErrorReporter* const errReporter = 0
168          , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
169    );
170    virtual ~SchemaValidator();
171
172    // -----------------------------------------------------------------------
173    //  Implementation of the XMLValidator interface
174    // -----------------------------------------------------------------------
175    virtual int checkContent
176    (
177        XMLElementDecl* const   elemDecl
178        , QName** const         children
179        , const unsigned int    childCount
180    );
181
182    virtual void faultInAttr
183    (
184                XMLAttr&    toFill
185        , const XMLAttDef&  attDef
186    )   const;
187
188    virtual void preContentValidation(bool reuseGrammar,
189                                      bool validateDefAttr = false);
190
191    virtual void postParseValidation();
192
193    virtual void reset();
194
195    virtual bool requiresNamespaces() const;
196
197    virtual void validateAttrValue
198    (
199        const   XMLAttDef*                  attDef
200        , const XMLCh* const                attrValue
201        , bool                              preValidation = false
202        , const XMLElementDecl*             elemDecl = 0
203    );
204
205    virtual void validateElement
206    (
207        const   XMLElementDecl*             elemDef
208    );
209
210    virtual Grammar* getGrammar() const;
211    virtual void setGrammar(Grammar* aGrammar);
212
213    // -----------------------------------------------------------------------
214    //  Virtual DTD handler interface.
215    // -----------------------------------------------------------------------
216    virtual bool handlesDTD() const;
217
218    // -----------------------------------------------------------------------
219    //  Virtual Schema handler interface. handlesSchema() always return false.
220    // -----------------------------------------------------------------------
221    virtual bool handlesSchema() const;
222
223    // -----------------------------------------------------------------------
224    //  Schema Validator methods
225    // -----------------------------------------------------------------------
226    void normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* const value, XMLBuffer& toFill);
227
228    // -----------------------------------------------------------------------
229    //  Setter methods
230    // -----------------------------------------------------------------------
231    void setGrammarResolver(GrammarResolver* grammarResolver);
232
233    void setXsiType(const XMLCh* const        prefix
234      , const XMLCh* const        localPart
235       , const unsigned int        uriId);
236
237    void setNillable(bool isNil);
238    void setErrorReporter(XMLErrorReporter* const errorReporter);
239    void setExitOnFirstFatal(const bool newValue);
240    void setDatatypeBuffer(const XMLCh* const value);
241    void clearDatatypeBuffer();
242
243    // -----------------------------------------------------------------------
244    //  Getter methods
245    // -----------------------------------------------------------------------
246    ComplexTypeInfo* getCurrentTypeInfo() const;
247    DatatypeValidator *getCurrentDatatypeValidator() const;
248    DatatypeValidator *getMostRecentAttrValidator() const;
249    bool getErrorOccurred() const;
250    bool getIsElemSpecified() const;
251    const XMLCh* getNormalizedValue() const;
252
253private:
254    // -----------------------------------------------------------------------
255    //  Unimplemented constructors and operators
256    // -----------------------------------------------------------------------
257    SchemaValidator(const SchemaValidator&);
258    SchemaValidator& operator=(const SchemaValidator&);
259
260    // -----------------------------------------------------------------------
261    //  Element Consitency Checking methods
262    // -----------------------------------------------------------------------
263    void checkRefElementConsistency(SchemaGrammar* const currentGrammar,
264                                    const ComplexTypeInfo* const curTypeInfo,
265                                    const XercesGroupInfo* const curGroup = 0);
266
267    // -----------------------------------------------------------------------
268    //  Particle Derivation Checking methods
269    // -----------------------------------------------------------------------
270    void checkParticleDerivation(SchemaGrammar* const currentGrammar,
271                                 const ComplexTypeInfo* const typeInfo);
272    void checkParticleDerivationOk(SchemaGrammar* const currentGrammar,
273                                   ContentSpecNode* const curNode,
274                                   const int derivedScope,
275                                   ContentSpecNode* const baseNode,
276                                   const int baseScope,
277                                   const ComplexTypeInfo* const baseInfo = 0,
278                                   const bool toCheckOccurrence = true);
279    ContentSpecNode* checkForPointlessOccurrences(ContentSpecNode* const specNode,
280                                                  const ContentSpecNode::NodeTypes nodeType,
281                                                  ValueVectorOf<ContentSpecNode*>* const nodes);
282    void gatherChildren(const ContentSpecNode::NodeTypes parentNodeType,
283                        ContentSpecNode* const specNode,
284                        ValueVectorOf<ContentSpecNode*>* const nodes);
285    bool isOccurrenceRangeOK(const int min1, const int max1, const int min2, const int max2);
286    void checkNSCompat(const ContentSpecNode* const derivedSpecNode,
287                       const ContentSpecNode* const baseSpecNode,
288                       const bool toCheckOccurence);
289    bool wildcardEltAllowsNamespace(const ContentSpecNode* const baseSpecNode,
290                                    const unsigned int derivedURI);
291    void checkNameAndTypeOK(SchemaGrammar* const currentGrammar,
292                            const ContentSpecNode* const derivedSpecNode,
293                            const int derivedScope,
294                            const ContentSpecNode* const baseSpecNode,
295                            const int baseScope,
296                            const ComplexTypeInfo* const baseInfo = 0);
297    SchemaElementDecl* findElement(const int scope,
298                                   const unsigned int uriIndex,
299                                   const XMLCh* const name,
300                                   SchemaGrammar* const grammar,
301                                   const ComplexTypeInfo* const typeInfo = 0);
302    void checkICRestriction(const SchemaElementDecl* const derivedElemDecl,
303                            const SchemaElementDecl* const baseElemDecl,
304                            const XMLCh* const derivedElemName,
305                            const XMLCh* const baseElemName);
306    void checkTypesOK(const SchemaElementDecl* const derivedElemDecl,
307                      const SchemaElementDecl* const baseElemDecl,
308                      const XMLCh* const derivedElemName);
309    void checkRecurseAsIfGroup(SchemaGrammar* const currentGrammar,
310                               ContentSpecNode* const derivedSpecNode,
311                               const int derivedScope,
312                               const ContentSpecNode* const baseSpecNode,
313                               const int baseScope,
314                               ValueVectorOf<ContentSpecNode*>* const nodes,
315                               const ComplexTypeInfo* const baseInfo);
316    void checkRecurse(SchemaGrammar* const currentGrammar,
317                      const ContentSpecNode* const derivedSpecNode,
318                      const int derivedScope,
319                      ValueVectorOf<ContentSpecNode*>* const derivedNodes,
320                      const ContentSpecNode* const baseSpecNode,
321                      const int baseScope,
322                      ValueVectorOf<ContentSpecNode*>* const baseNodes,
323                      const ComplexTypeInfo* const baseInfo,
324                      const bool toLax = false);
325    void checkNSSubset(const ContentSpecNode* const derivedSpecNode,
326                       const ContentSpecNode* const baseSpecNode);
327    bool isWildCardEltSubset(const ContentSpecNode* const derivedSpecNode,
328                             const ContentSpecNode* const baseSpecNode);
329    void checkNSRecurseCheckCardinality(SchemaGrammar* const currentGrammar,
330                                        const ContentSpecNode* const derivedSpecNode,
331                                        ValueVectorOf<ContentSpecNode*>* const derivedNodes,
332                                        const int derivedScope,
333                                        ContentSpecNode* const baseSpecNode,
334                                        const bool toCheckOccurence);
335    void checkRecurseUnordered(SchemaGrammar* const currentGrammar,
336                               const ContentSpecNode* const derivedSpecNode,
337                               ValueVectorOf<ContentSpecNode*>* const derivedNodes,
338                               const int derivedScope,
339                               ContentSpecNode* const baseSpecNode,
340                               ValueVectorOf<ContentSpecNode*>* const baseNodes,
341                               const int baseScope,
342                               const ComplexTypeInfo* const baseInfo);
343    void checkMapAndSum(SchemaGrammar* const currentGrammar,
344                        const ContentSpecNode* const derivedSpecNode,
345                        ValueVectorOf<ContentSpecNode*>* const derivedNodes,
346                        const int derivedScope,
347                        ContentSpecNode* const baseSpecNode,
348                        ValueVectorOf<ContentSpecNode*>* const baseNodes,
349                        const int baseScope,
350                        const ComplexTypeInfo* const baseInfo);
351    ContentSpecNode* getNonUnaryGroup(ContentSpecNode* const pNode);
352
353    // -----------------------------------------------------------------------
354    //  Private data members
355    //
356    // -----------------------------------------------------------------------
357    //  The following comes from or set by the Scanner
358    //  fSchemaGrammar
359    //      The current schema grammar used by the validator
360    //
361    //  fGrammarResolver
362    //      All the schema grammar stored
363    //
364    //  fXsiType
365    //      Store the Schema Type Attribute Value if schema type is specified
366    //
367    //  fNil
368    //      Indicates if Nillable has been set
369    // -----------------------------------------------------------------------
370    //  The following used internally in the validator
371    //
372    //  fCurrentDatatypeValidator
373    //      The validator used for validating the content of elements
374    //      with simple types
375    //
376    //  fDatatypeBuffer
377    //      Buffer for simple type element string content
378    //
379    //  fTrailing
380    //      Previous chunk had a trailing space
381    //
382    //  fSeenId
383    //      Indicate if an attribute of ID type has been seen already, reset per element.
384    //
385    //  fSchemaErrorReporter
386    //      Report schema process errors
387    //
388    //  fTypeStack
389    //      Stack of complex type declarations.
390    //
391    //  fMostRecentAttrValidator
392    //      DatatypeValidator that validated attribute most recently processed
393    //
394    //  fErrorOccurred
395    //      whether an error occurred in the most recent operation
396    // -----------------------------------------------------------------------
397    MemoryManager*                  fMemoryManager;
398    SchemaGrammar*                  fSchemaGrammar;
399    GrammarResolver*                fGrammarResolver;
400    QName*                          fXsiType;
401    bool                            fNil;
402    DatatypeValidator*              fCurrentDatatypeValidator;
403    XMLBuffer*                      fNotationBuf;
404    XMLBuffer                       fDatatypeBuffer;
405    bool                            fTrailing;
406    bool                            fSeenId;
407    XSDErrorReporter                fSchemaErrorReporter;
408    ValueStackOf<ComplexTypeInfo*>* fTypeStack;
409    DatatypeValidator *             fMostRecentAttrValidator;
410    bool                            fErrorOccurred;
411    bool                            fElemIsSpecified;
412};
413
414
415// ---------------------------------------------------------------------------
416//  SchemaValidator: Setter methods
417// ---------------------------------------------------------------------------
418inline void SchemaValidator::setGrammarResolver(GrammarResolver* grammarResolver) {
419    fGrammarResolver = grammarResolver;
420}
421
422inline void SchemaValidator::setXsiType(const XMLCh* const        prefix
423      , const XMLCh* const        localPart
424       , const unsigned int        uriId)
425{
426    delete fXsiType;
427    fXsiType = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager);
428}
429
430inline void SchemaValidator::setNillable(bool isNil) {
431    fNil = isNil;
432}
433
434inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) {
435
436    fSchemaErrorReporter.setExitOnFirstFatal(newValue);
437}
438
439inline void SchemaValidator::setDatatypeBuffer(const XMLCh* const value)
440{
441    fDatatypeBuffer.append(value);
442}
443
444inline void SchemaValidator::clearDatatypeBuffer()
445{
446    fDatatypeBuffer.reset();
447}
448
449// ---------------------------------------------------------------------------
450//  SchemaValidator: Getter methods
451// ---------------------------------------------------------------------------
452inline ComplexTypeInfo* SchemaValidator::getCurrentTypeInfo() const {
453    if (fTypeStack->empty())
454        return 0;
455    return fTypeStack->peek();
456}
457
458inline DatatypeValidator * SchemaValidator::getCurrentDatatypeValidator() const
459{
460    return fCurrentDatatypeValidator;
461}
462inline DatatypeValidator *SchemaValidator::getMostRecentAttrValidator() const
463{
464    return fMostRecentAttrValidator;
465}
466
467// ---------------------------------------------------------------------------
468//  Virtual interface
469// ---------------------------------------------------------------------------
470inline Grammar* SchemaValidator::getGrammar() const {
471    return fSchemaGrammar;
472}
473
474inline void SchemaValidator::setGrammar(Grammar* aGrammar) {
475    fSchemaGrammar = (SchemaGrammar*) aGrammar;
476}
477
478inline void SchemaValidator::setErrorReporter(XMLErrorReporter* const errorReporter) {
479
480    XMLValidator::setErrorReporter(errorReporter);
481    fSchemaErrorReporter.setErrorReporter(errorReporter);
482}
483
484// ---------------------------------------------------------------------------
485//  SchemaValidator: DTD handler interface
486// ---------------------------------------------------------------------------
487inline bool SchemaValidator::handlesDTD() const
488{
489    // No DTD scanning
490    return false;
491}
492
493// ---------------------------------------------------------------------------
494//  SchemaValidator: Schema handler interface
495// ---------------------------------------------------------------------------
496inline bool SchemaValidator::handlesSchema() const
497{
498    return true;
499}
500
501// ---------------------------------------------------------------------------
502//  SchemaValidator: Particle derivation checking
503// ---------------------------------------------------------------------------
504inline bool
505SchemaValidator::isOccurrenceRangeOK(const int min1, const int max1,
506                                     const int min2, const int max2) {
507
508    if (min1 >= min2 &&
509        (max2 == SchemaSymbols::XSD_UNBOUNDED ||
510         (max1 != SchemaSymbols::XSD_UNBOUNDED && max1 <= max2))) {
511        return true;
512    }
513    return false;
514}
515
516inline bool SchemaValidator::getErrorOccurred() const
517{
518    return fErrorOccurred;
519}
520
521inline bool SchemaValidator::getIsElemSpecified() const
522{
523    return fElemIsSpecified;
524}
525
526inline const XMLCh* SchemaValidator::getNormalizedValue() const
527{
528    return fDatatypeBuffer.getRawBuffer();
529}
530
531XERCES_CPP_NAMESPACE_END
532
533#endif
Note: See TracBrowser for help on using the repository browser.