Ignore:
Timestamp:
Dec 4, 2012, 6:02:04 PM (6 years ago)
Author:
cameron
Message:

Script for generating link files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icXML/icXML-devel/src/xercesc/validators/schema/SchemaValidator.hpp

    r2722 r2747  
    1 /*
    2  * Licensed to the Apache Software Foundation (ASF) under one or more
    3  * contributor license agreements.  See the NOTICE file distributed with
    4  * this work for additional information regarding copyright ownership.
    5  * The ASF licenses this file to You under the Apache License, Version 2.0
    6  * (the "License"); you may not use this file except in compliance with
    7  * the License.  You may obtain a copy of the License at
    8  *
    9  *      http://www.apache.org/licenses/LICENSE-2.0
    10  *
    11  * Unless required by applicable law or agreed to in writing, software
    12  * distributed under the License is distributed on an "AS IS" BASIS,
    13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  * See the License for the specific language governing permissions and
    15  * limitations under the License.
    16  */
    17 
    18 /*
    19  * $Id: SchemaValidator.hpp 932887 2010-04-11 13:04:59Z borisk $
    20  */
    21 
    22 #if !defined(XERCESC_INCLUDE_GUARD_SCHEMAVALIDATOR_HPP)
    23 #define XERCESC_INCLUDE_GUARD_SCHEMAVALIDATOR_HPP
    24 
    25 #include <icxercesc/framework/XMLValidator.hpp>
    26 #include <icxercesc/framework/XMLBuffer.hpp>
    27 #include <xercesc/util/ValueStackOf.hpp>
    28 #include <xercesc/validators/common/ContentSpecNode.hpp>
    29 #include <xercesc/validators/schema/SchemaGrammar.hpp>
    30 #include <xercesc/validators/schema/XSDErrorReporter.hpp>
    31 
    32 XERCES_CPP_NAMESPACE_BEGIN
    33 
    34 class GrammarResolver;
    35 class DatatypeValidator;
    36 class SchemaElementDecl;
    37 
    38 //
    39 //  This is a derivative of the abstract validator interface. This class
    40 //  implements a validator that supports standard XML Schema semantics.
    41 //  This class handles scanning the of the schema, and provides
    42 //  the standard validation services against the Schema info it found.
    43 //
    44 class VALIDATORS_EXPORT SchemaValidator : public XMLValidator
    45 {
    46 public:
    47     // -----------------------------------------------------------------------
    48     //  Constructors and Destructor
    49     // -----------------------------------------------------------------------
    50     SchemaValidator
    51     (
    52           XMLErrorReporter* const errReporter = 0
    53           , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    54     );
    55     virtual ~SchemaValidator();
    56 
    57     // -----------------------------------------------------------------------
    58     //  Implementation of the XMLValidator interface
    59     // -----------------------------------------------------------------------
    60     virtual bool checkContent
    61     (
    62         XMLElementDecl* const   elemDecl
    63         , QName** const         children
    64         , XMLSize_t             childCount
    65         , XMLSize_t*            indexFailingChild
    66     );
    67 
    68     virtual void faultInAttr
    69     (
    70                 XMLAttr&    toFill
    71         , const XMLAttDef&  attDef
    72     )   const;
    73 
    74     virtual void preContentValidation(bool reuseGrammar,
    75                                       bool validateDefAttr = false);
    76 
    77     virtual void postParseValidation();
    78 
    79     virtual void reset();
    80 
    81     virtual bool requiresNamespaces() const;
    82 
    83     virtual void validateAttrValue
    84     (
    85         const   XMLAttDef*                  attDef
    86         , const XMLCh* const                attrValue
    87         , bool                              preValidation = false
    88         , const XMLElementDecl*             elemDecl = 0
    89     );
    90 
    91     virtual void validateElement
    92     (
    93         const   XMLElementDecl*             elemDef
    94     );
    95 
    96     virtual Grammar* getGrammar() const;
    97     virtual void setGrammar(Grammar* aGrammar);
    98 
    99     // -----------------------------------------------------------------------
    100     //  Virtual DTD handler interface.
    101     // -----------------------------------------------------------------------
    102     virtual bool handlesDTD() const;
    103 
    104     // -----------------------------------------------------------------------
    105     //  Virtual Schema handler interface. handlesSchema() always return false.
    106     // -----------------------------------------------------------------------
    107     virtual bool handlesSchema() const;
    108 
    109     // -----------------------------------------------------------------------
    110     //  Schema Validator methods
    111     // -----------------------------------------------------------------------
    112     void normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* const value, XMLBuffer& toFill, bool bStandalone = false);
    113 
    114     // -----------------------------------------------------------------------
    115     //  Setter methods
    116     // -----------------------------------------------------------------------
    117     void setGrammarResolver(GrammarResolver* grammarResolver);
    118 
    119     void setXsiType(const XMLCh* const        prefix
    120       , const XMLCh* const        localPart
    121        , const unsigned int        uriId);
    122 
    123     void setNillable(bool isNil);
    124     void resetNillable();
    125     void setErrorReporter(XMLErrorReporter* const errorReporter);
    126     void setExitOnFirstFatal(const bool newValue);
    127     void setDatatypeBuffer(const XMLCh* const value);
    128     void clearDatatypeBuffer();
    129 
    130     // -----------------------------------------------------------------------
    131     //  Getter methods
    132     // -----------------------------------------------------------------------
    133     ComplexTypeInfo* getCurrentTypeInfo() const;
    134     DatatypeValidator *getCurrentDatatypeValidator() const;
    135     DatatypeValidator *getMostRecentAttrValidator() const;
    136     bool getErrorOccurred() const;
    137     bool getIsElemSpecified() const;
    138     bool getIsXsiTypeSet() const;
    139     const XMLCh* getNormalizedValue() const;
    140 
    141 private:
    142     // -----------------------------------------------------------------------
    143     //  Unimplemented constructors and operators
    144     // -----------------------------------------------------------------------
    145     SchemaValidator(const SchemaValidator&);
    146     SchemaValidator& operator=(const SchemaValidator&);
    147 
    148     // -----------------------------------------------------------------------
    149     //  Element Consistency Checking methods
    150     // -----------------------------------------------------------------------
    151     void checkRefElementConsistency(SchemaGrammar* const currentGrammar,
    152                                     const ComplexTypeInfo* const curTypeInfo,
    153                                     const XercesGroupInfo* const curGroup = 0);
    154 
    155     // -----------------------------------------------------------------------
    156     //  Particle Derivation Checking methods
    157     // -----------------------------------------------------------------------
    158     void checkParticleDerivation(SchemaGrammar* const currentGrammar,
    159                                  const ComplexTypeInfo* const typeInfo);
    160     void checkParticleDerivationOk(SchemaGrammar* const currentGrammar,
    161                                    ContentSpecNode* const curNode,
    162                                    const int derivedScope,
    163                                    ContentSpecNode* const baseNode,
    164                                    const int baseScope,
    165                                    const ComplexTypeInfo* const baseInfo = 0,
    166                                    const bool toCheckOccurrence = true);
    167     ContentSpecNode* checkForPointlessOccurrences(ContentSpecNode* const specNode,
    168                                                   const ContentSpecNode::NodeTypes nodeType,
    169                                                   ValueVectorOf<ContentSpecNode*>* const nodes);
    170     void gatherChildren(const ContentSpecNode::NodeTypes parentNodeType,
    171                         ContentSpecNode* const specNode,
    172                         ValueVectorOf<ContentSpecNode*>* const nodes);
    173     bool isOccurrenceRangeOK(const int min1, const int max1, const int min2, const int max2);
    174     void checkNSCompat(const ContentSpecNode* const derivedSpecNode,
    175                        const ContentSpecNode* const baseSpecNode,
    176                        const bool toCheckOccurence);
    177     bool wildcardEltAllowsNamespace(const ContentSpecNode* const baseSpecNode,
    178                                     const unsigned int derivedURI);
    179     void checkNameAndTypeOK(SchemaGrammar* const currentGrammar,
    180                             const ContentSpecNode* const derivedSpecNode,
    181                             const int derivedScope,
    182                             const ContentSpecNode* const baseSpecNode,
    183                             const int baseScope,
    184                             const ComplexTypeInfo* const baseInfo = 0);
    185     SchemaElementDecl* findElement(const int scope,
    186                                    const unsigned int uriIndex,
    187                                    const XMLCh* const name,
    188                                    SchemaGrammar* const grammar,
    189                                    const ComplexTypeInfo* const typeInfo = 0);
    190     void checkICRestriction(const SchemaElementDecl* const derivedElemDecl,
    191                             const SchemaElementDecl* const baseElemDecl,
    192                             const XMLCh* const derivedElemName,
    193                             const XMLCh* const baseElemName);
    194     void checkTypesOK(const SchemaElementDecl* const derivedElemDecl,
    195                       const SchemaElementDecl* const baseElemDecl,
    196                       const XMLCh* const derivedElemName);
    197     void checkRecurseAsIfGroup(SchemaGrammar* const currentGrammar,
    198                                ContentSpecNode* const derivedSpecNode,
    199                                const int derivedScope,
    200                                const ContentSpecNode* const baseSpecNode,
    201                                const int baseScope,
    202                                ValueVectorOf<ContentSpecNode*>* const nodes,
    203                                const ComplexTypeInfo* const baseInfo);
    204     void checkRecurse(SchemaGrammar* const currentGrammar,
    205                       const ContentSpecNode* const derivedSpecNode,
    206                       const int derivedScope,
    207                       ValueVectorOf<ContentSpecNode*>* const derivedNodes,
    208                       const ContentSpecNode* const baseSpecNode,
    209                       const int baseScope,
    210                       ValueVectorOf<ContentSpecNode*>* const baseNodes,
    211                       const ComplexTypeInfo* const baseInfo,
    212                       const bool toLax = false);
    213     void checkNSSubset(const ContentSpecNode* const derivedSpecNode,
    214                        const ContentSpecNode* const baseSpecNode);
    215     bool checkNSSubsetChoiceRoot(const ContentSpecNode* const derivedSpecNode,
    216                        const ContentSpecNode* const baseSpecNode);
    217     bool checkNSSubsetChoice(const ContentSpecNode* const derivedSpecNode,
    218                        const ContentSpecNode* const baseSpecNode);
    219     bool isWildCardEltSubset(const ContentSpecNode* const derivedSpecNode,
    220                              const ContentSpecNode* const baseSpecNode);
    221     void checkNSRecurseCheckCardinality(SchemaGrammar* const currentGrammar,
    222                                         const ContentSpecNode* const derivedSpecNode,
    223                                         ValueVectorOf<ContentSpecNode*>* const derivedNodes,
    224                                         const int derivedScope,
    225                                         ContentSpecNode* const baseSpecNode,
    226                                         const bool toCheckOccurence);
    227     void checkRecurseUnordered(SchemaGrammar* const currentGrammar,
    228                                const ContentSpecNode* const derivedSpecNode,
    229                                ValueVectorOf<ContentSpecNode*>* const derivedNodes,
    230                                const int derivedScope,
    231                                ContentSpecNode* const baseSpecNode,
    232                                ValueVectorOf<ContentSpecNode*>* const baseNodes,
    233                                const int baseScope,
    234                                const ComplexTypeInfo* const baseInfo);
    235     void checkMapAndSum(SchemaGrammar* const currentGrammar,
    236                         const ContentSpecNode* const derivedSpecNode,
    237                         ValueVectorOf<ContentSpecNode*>* const derivedNodes,
    238                         const int derivedScope,
    239                         ContentSpecNode* const baseSpecNode,
    240                         ValueVectorOf<ContentSpecNode*>* const baseNodes,
    241                         const int baseScope,
    242                         const ComplexTypeInfo* const baseInfo);
    243     ContentSpecNode* getNonUnaryGroup(ContentSpecNode* const pNode);
    244 
    245     // -----------------------------------------------------------------------
    246     //  Private data members
    247     //
    248     // -----------------------------------------------------------------------
    249     //  The following comes from or set by the Scanner
    250     //  fSchemaGrammar
    251     //      The current schema grammar used by the validator
    252     //
    253     //  fGrammarResolver
    254     //      All the schema grammar stored
    255     //
    256     //  fXsiType
    257     //      Store the Schema Type Attribute Value if schema type is specified
    258     //
    259     //  fNil
    260     //      Indicates if a nil value is acceptable
    261     //  fNilFound
    262     //      Indicates if Nillable has been set
    263     // -----------------------------------------------------------------------
    264     //  The following used internally in the validator
    265     //
    266     //  fCurrentDatatypeValidator
    267     //      The validator used for validating the content of elements
    268     //      with simple types
    269     //
    270     //  fDatatypeBuffer
    271     //      Buffer for simple type element string content
    272     //
    273     //  fTrailing
    274     //      Previous chunk had a trailing space
    275     //
    276     //  fSeenNonWhiteSpace
    277     //      Seen a non-whitespace character in the previous chunk
    278     //
    279     //  fSeenId
    280     //      Indicate if an attribute of ID type has been seen already, reset per element.
    281     //
    282     //  fSchemaErrorReporter
    283     //      Report schema process errors
    284     //
    285     //  fTypeStack
    286     //      Stack of complex type declarations.
    287     //
    288     //  fMostRecentAttrValidator
    289     //      DatatypeValidator that validated attribute most recently processed
    290     //
    291     //  fErrorOccurred
    292     //      whether an error occurred in the most recent operation
    293     // -----------------------------------------------------------------------
    294     MemoryManager*                  fMemoryManager;
    295     SchemaGrammar*                  fSchemaGrammar;
    296     GrammarResolver*                fGrammarResolver;
    297     QName*                          fXsiType;
    298     bool                            fNil;
    299     bool                            fNilFound;
    300     DatatypeValidator*              fCurrentDatatypeValidator;
    301     XMLBuffer*                      fNotationBuf;
    302     XMLBuffer                       fDatatypeBuffer;
    303     bool                            fTrailing;
    304     bool                            fSeenNonWhiteSpace;
    305     bool                            fSeenId;
    306     XSDErrorReporter                fSchemaErrorReporter;
    307     ValueStackOf<ComplexTypeInfo*>* fTypeStack;
    308     DatatypeValidator *             fMostRecentAttrValidator;
    309     bool                            fErrorOccurred;
    310     bool                            fElemIsSpecified;
    311 };
    312 
    313 
    314 // ---------------------------------------------------------------------------
    315 //  SchemaValidator: Setter methods
    316 // ---------------------------------------------------------------------------
    317 inline void SchemaValidator::setGrammarResolver(GrammarResolver* grammarResolver) {
    318     fGrammarResolver = grammarResolver;
    319 }
    320 
    321 inline void SchemaValidator::setXsiType(const XMLCh* const        prefix
    322       , const XMLCh* const        localPart
    323        , const unsigned int        uriId)
    324 {
    325     delete fXsiType;
    326     fXsiType = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager);
    327 }
    328 
    329 inline void SchemaValidator::setNillable(bool isNil) {
    330     fNil = isNil;
    331     fNilFound = true;
    332 }
    333 
    334 inline void SchemaValidator::resetNillable() {
    335     fNil = false;
    336     fNilFound = false;
    337 }
    338 
    339 inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) {
    340 
    341     fSchemaErrorReporter.setExitOnFirstFatal(newValue);
    342 }
    343 
    344 inline void SchemaValidator::setDatatypeBuffer(const XMLCh* const value)
    345 {
    346     fDatatypeBuffer.append(value);
    347 }
    348 
    349 inline void SchemaValidator::clearDatatypeBuffer()
    350 {
    351     fDatatypeBuffer.reset();
    352 }
    353 
    354 // ---------------------------------------------------------------------------
    355 //  SchemaValidator: Getter methods
    356 // ---------------------------------------------------------------------------
    357 inline ComplexTypeInfo* SchemaValidator::getCurrentTypeInfo() const {
    358     if (fTypeStack->empty())
    359         return 0;
    360     return fTypeStack->peek();
    361 }
    362 
    363 inline DatatypeValidator * SchemaValidator::getCurrentDatatypeValidator() const
    364 {
    365     return fCurrentDatatypeValidator;
    366 }
    367 inline DatatypeValidator *SchemaValidator::getMostRecentAttrValidator() const
    368 {
    369     return fMostRecentAttrValidator;
    370 }
    371 
    372 // ---------------------------------------------------------------------------
    373 //  Virtual interface
    374 // ---------------------------------------------------------------------------
    375 inline Grammar* SchemaValidator::getGrammar() const {
    376     return fSchemaGrammar;
    377 }
    378 
    379 inline void SchemaValidator::setGrammar(Grammar* aGrammar) {
    380     fSchemaGrammar = (SchemaGrammar*) aGrammar;
    381 }
    382 
    383 inline void SchemaValidator::setErrorReporter(XMLErrorReporter* const errorReporter) {
    384 
    385     XMLValidator::setErrorReporter(errorReporter);
    386     fSchemaErrorReporter.setErrorReporter(errorReporter);
    387 }
    388 
    389 // ---------------------------------------------------------------------------
    390 //  SchemaValidator: DTD handler interface
    391 // ---------------------------------------------------------------------------
    392 inline bool SchemaValidator::handlesDTD() const
    393 {
    394     // No DTD scanning
    395     return false;
    396 }
    397 
    398 // ---------------------------------------------------------------------------
    399 //  SchemaValidator: Schema handler interface
    400 // ---------------------------------------------------------------------------
    401 inline bool SchemaValidator::handlesSchema() const
    402 {
    403     return true;
    404 }
    405 
    406 // ---------------------------------------------------------------------------
    407 //  SchemaValidator: Particle derivation checking
    408 // ---------------------------------------------------------------------------
    409 inline bool
    410 SchemaValidator::isOccurrenceRangeOK(const int min1, const int max1,
    411                                      const int min2, const int max2) {
    412 
    413     if (min1 >= min2 &&
    414         (max2 == SchemaSymbols::XSD_UNBOUNDED ||
    415          (max1 != SchemaSymbols::XSD_UNBOUNDED && max1 <= max2))) {
    416         return true;
    417     }
    418     return false;
    419 }
    420 
    421 inline bool SchemaValidator::getErrorOccurred() const
    422 {
    423     return fErrorOccurred;
    424 }
    425 
    426 inline bool SchemaValidator::getIsElemSpecified() const
    427 {
    428     return fElemIsSpecified;
    429 }
    430 
    431 inline const XMLCh* SchemaValidator::getNormalizedValue() const
    432 {
    433     return fDatatypeBuffer.getRawBuffer();
    434 }
    435 
    436 inline bool SchemaValidator::getIsXsiTypeSet() const
    437 {
    438     return (fXsiType!=0);
    439 }
    440 
    441 XERCES_CPP_NAMESPACE_END
    442 
    443 #endif
     1#include <icxercesc/validators/schema/SchemaValidator.hpp>
Note: See TracChangeset for help on using the changeset viewer.