Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:20

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_TRAVERSESCHEMA_HPP)
0023 #define XERCESC_INCLUDE_GUARD_TRAVERSESCHEMA_HPP
0024 
0025 /**
0026   * Instances of this class get delegated to Traverse the Schema and
0027   * to populate the SchemaGrammar internal representation.
0028   */
0029 
0030 // ---------------------------------------------------------------------------
0031 //  Includes
0032 // ---------------------------------------------------------------------------
0033 #include <xercesc/util/XMLUniDefs.hpp>
0034 #include <xercesc/dom/DOMElement.hpp>
0035 #include <xercesc/dom/DOMAttr.hpp>
0036 #include <xercesc/framework/XMLBuffer.hpp>
0037 #include <xercesc/framework/XMLErrorCodes.hpp>
0038 #include <xercesc/validators/schema/SchemaSymbols.hpp>
0039 #include <xercesc/util/ValueVectorOf.hpp>
0040 #include <xercesc/util/RefHash2KeysTableOf.hpp>
0041 #include <xercesc/validators/common/ContentSpecNode.hpp>
0042 #include <xercesc/validators/schema/SchemaGrammar.hpp>
0043 #include <xercesc/validators/schema/SchemaInfo.hpp>
0044 #include <xercesc/validators/schema/GeneralAttributeCheck.hpp>
0045 #include <xercesc/validators/schema/XSDErrorReporter.hpp>
0046 #include <xercesc/util/XMLResourceIdentifier.hpp>
0047 
0048 XERCES_CPP_NAMESPACE_BEGIN
0049 
0050 // ---------------------------------------------------------------------------
0051 //  Forward Declarations
0052 // ---------------------------------------------------------------------------
0053 class GrammarResolver;
0054 class XMLEntityHandler;
0055 class XMLScanner;
0056 class DatatypeValidator;
0057 class DatatypeValidatorFactory;
0058 class QName;
0059 class ComplexTypeInfo;
0060 class XMLAttDef;
0061 class NamespaceScope;
0062 class SchemaAttDef;
0063 class InputSource;
0064 class XercesGroupInfo;
0065 class XercesAttGroupInfo;
0066 class IdentityConstraint;
0067 class XSDLocator;
0068 class XSDDOMParser;
0069 class XMLErrorReporter;
0070 
0071 
0072 class VALIDATORS_EXPORT TraverseSchema : public XMemory
0073 {
0074 public:
0075     // -----------------------------------------------------------------------
0076     //  Public Constructors/Destructor
0077     // -----------------------------------------------------------------------
0078     TraverseSchema
0079     (
0080           DOMElement* const       schemaRoot
0081         , XMLStringPool* const    uriStringPool
0082         , SchemaGrammar* const    schemaGrammar
0083         , GrammarResolver* const  grammarResolver
0084         , RefHash2KeysTableOf<SchemaInfo>* cachedSchemaInfoList
0085         , RefHash2KeysTableOf<SchemaInfo>* schemaInfoList
0086         , XMLScanner* const       xmlScanner
0087         , const XMLCh* const      schemaURL
0088         , XMLEntityHandler* const entityHandler
0089         , XMLErrorReporter* const errorReporter
0090         , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
0091         , bool multipleImport = false
0092     );
0093 
0094     ~TraverseSchema();
0095 
0096 private:
0097      // This enumeration is defined here for compatibility with the CodeWarrior
0098      // compiler, which apparently doesn't like to accept default parameter
0099      // arguments that it hasn't yet seen. The Not_All_Context argument is
0100      // used in the declaration of checkMinMax, below.
0101      //
0102     // Flags indicate any special restrictions on minOccurs and maxOccurs
0103     // relating to "all".
0104     //    Not_All_Context    - not processing an <all>
0105     //    All_Element        - processing an <element> in an <all>
0106     //    Group_Ref_With_All - processing <group> reference that contained <all>
0107     //    All_Group          - processing an <all> group itself
0108     enum
0109     {
0110         Not_All_Context = 0
0111         , All_Element = 1
0112         , Group_Ref_With_All = 2
0113         , All_Group = 4
0114     };
0115 
0116     // -----------------------------------------------------------------------
0117     //  Unimplemented constructors and operators
0118     // -----------------------------------------------------------------------
0119     TraverseSchema(const TraverseSchema&);
0120     TraverseSchema& operator=(const TraverseSchema&);
0121 
0122     // -----------------------------------------------------------------------
0123     //  Init/CleanUp methods
0124     // -----------------------------------------------------------------------
0125     void init();
0126     void cleanUp();
0127 
0128     // -----------------------------------------------------------------------
0129     //  Traversal methods
0130     // -----------------------------------------------------------------------
0131     /**
0132       * Traverse the Schema DOM tree
0133       */
0134     void                doTraverseSchema(const DOMElement* const schemaRoot);
0135     void                preprocessSchema(DOMElement* const schemaRoot,
0136                                          const XMLCh* const schemaURL,
0137                                          bool  multipleImport = false);
0138     void                traverseSchemaHeader(const DOMElement* const schemaRoot);
0139     XSAnnotation*       traverseAnnotationDecl(const DOMElement* const childElem,
0140                                                ValueVectorOf<DOMNode*>* const nonXSAttList,
0141                                                const bool topLevel = false);
0142     void                traverseInclude(const DOMElement* const childElem);
0143     void                traverseImport(const DOMElement* const childElem);
0144     void                traverseRedefine(const DOMElement* const childElem);
0145     void                traverseAttributeDecl(const DOMElement* const childElem,
0146                                               ComplexTypeInfo* const typeInfo,
0147                                               const bool topLevel = false);
0148     void                traverseSimpleContentDecl(const XMLCh* const typeName,
0149                                                   const XMLCh* const qualifiedName,
0150                                                   const DOMElement* const contentDecl,
0151                                                   ComplexTypeInfo* const typeInfo,
0152                                                   Janitor<XSAnnotation>* const janAnnot);
0153     void                traverseComplexContentDecl(const XMLCh* const typeName,
0154                                                   const DOMElement* const contentDecl,
0155                                                   ComplexTypeInfo* const typeInfo,
0156                                                   const bool isMixed,
0157                                                   Janitor<XSAnnotation>* const janAnnot);
0158     DatatypeValidator*  traverseSimpleTypeDecl(const DOMElement* const childElem,
0159                                                const bool topLevel = true,
0160                                                int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
0161     int                 traverseComplexTypeDecl(const DOMElement* const childElem,
0162                                                 const bool topLevel = true,
0163                                                 const XMLCh* const recursingTypeName = 0);
0164     DatatypeValidator*  traverseByList(const DOMElement* const rootElem,
0165                                        const DOMElement* const contentElem,
0166                                        const XMLCh* const typeName,
0167                                        const XMLCh* const qualifiedName,
0168                                        const int finalSet,
0169                                        Janitor<XSAnnotation>* const janAnnot);
0170     DatatypeValidator*  traverseByRestriction(const DOMElement* const rootElem,
0171                                               const DOMElement* const contentElem,
0172                                               const XMLCh* const typeName,
0173                                               const XMLCh* const qualifiedName,
0174                                               const int finalSet,
0175                                               Janitor<XSAnnotation>* const janAnnot);
0176     DatatypeValidator*  traverseByUnion(const DOMElement* const rootElem,
0177                                         const DOMElement* const contentElem,
0178                                         const XMLCh* const typeName,
0179                                         const XMLCh* const qualifiedName,
0180                                         const int finalSet,
0181                                         int baseRefContext,
0182                                         Janitor<XSAnnotation>* const janAnnot);
0183     SchemaElementDecl*    traverseElementDecl(const DOMElement* const childElem,
0184                                             const bool topLevel = false);
0185     const XMLCh*        traverseNotationDecl(const DOMElement* const childElem);
0186     const XMLCh*        traverseNotationDecl(const DOMElement* const childElem,
0187                                              const XMLCh* const name,
0188                                              const XMLCh* const uriStr);
0189     ContentSpecNode*    traverseChoiceSequence(const DOMElement* const elemDecl,
0190                                                const int modelGroupType,
0191                                                bool& hasChildren);
0192     ContentSpecNode*    traverseAny(const DOMElement* const anyDecl);
0193     ContentSpecNode*    traverseAll(const DOMElement* const allElem,
0194                                     bool& hasChildren);
0195     XercesGroupInfo*    traverseGroupDecl(const DOMElement* const childElem,
0196                                           const bool topLevel = true);
0197     XercesAttGroupInfo* traverseAttributeGroupDecl(const DOMElement* const elem,
0198                                                    ComplexTypeInfo* const typeInfo,
0199                                                    const bool topLevel = false);
0200     XercesAttGroupInfo* traverseAttributeGroupDeclNS(const DOMElement* const elem,
0201                                                      const XMLCh* const uriStr,
0202                                                      const XMLCh* const name);
0203     SchemaAttDef*       traverseAnyAttribute(const DOMElement* const elem);
0204     void                traverseKey(const DOMElement* const icElem,
0205                                     SchemaElementDecl* const elemDecl);
0206     void                traverseUnique(const DOMElement* const icElem,
0207                                        SchemaElementDecl* const elemDecl);
0208     void                traverseKeyRef(const DOMElement* const icElem,
0209                                        SchemaElementDecl* const elemDecl);
0210     bool                traverseIdentityConstraint(IdentityConstraint* const ic,
0211                                                    const DOMElement* const icElem);
0212 
0213     // -----------------------------------------------------------------------
0214     //  Error Reporting methods
0215     // -----------------------------------------------------------------------
0216     void reportSchemaError(const XSDLocator* const aLocator,
0217                            const XMLCh* const msgDomain,
0218                            const int errorCode);
0219     void reportSchemaError(const XSDLocator* const aLocator,
0220                            const XMLCh* const msgDomain,
0221                            const int errorCode,
0222                            const XMLCh* const text1,
0223                            const XMLCh* const text2 = 0,
0224                            const XMLCh* const text3 = 0,
0225                            const XMLCh* const text4 = 0);
0226     void reportSchemaError(const DOMElement* const elem,
0227                            const XMLCh* const msgDomain,
0228                            const int errorCode);
0229     void reportSchemaError(const DOMElement* const elem,
0230                            const XMLCh* const msgDomain,
0231                            const int errorCode,
0232                            const XMLCh* const text1,
0233                            const XMLCh* const text2 = 0,
0234                            const XMLCh* const text3 = 0,
0235                            const XMLCh* const text4 = 0);
0236     void reportSchemaError(const DOMElement* const elem,
0237                            const XMLException&     except);
0238 
0239     // -----------------------------------------------------------------------
0240     //  Private Helper methods
0241     // -----------------------------------------------------------------------
0242     /**
0243       * Keep track of the xs:import found
0244       */
0245     bool isImportingNS(const int namespaceURI);
0246     void addImportedNS(const int namespaceURI);
0247 
0248     /**
0249       * Retrieved the Namespace mapping from the schema element
0250       */
0251     bool retrieveNamespaceMapping(const DOMElement* const elem);
0252 
0253     /**
0254       * Loop through the children, and traverse the corresponding schema type
0255       * type declaration (simpleType, complexType, import, ....)
0256       */
0257     void processChildren(const DOMElement* const root);
0258     void preprocessChildren(const DOMElement* const root);
0259 
0260     void preprocessImport(const DOMElement* const elemNode);
0261     void preprocessInclude(const DOMElement* const elemNode);
0262     void preprocessRedefine(const DOMElement* const elemNode);
0263 
0264     /**
0265       * Parameters:
0266       *   rootElem - top element for a given type declaration
0267       *   contentElem - content must be annotation? or some other simple content
0268       *   isEmpty: - true if (annotation?, smth_else), false if (annotation?)
0269       *   processAnnot - default is true, false if reprocessing a complex type
0270       *                  since we have already processed the annotation.
0271       *
0272       * Check for Annotation if it is present, traverse it. If a sibling is
0273       * found and it is not an annotation return it, otherwise return 0.
0274       * Used by traverseSimpleTypeDecl.
0275       */
0276     DOMElement* checkContent(const DOMElement* const rootElem,
0277                                DOMElement* const contentElem,
0278                                const bool isEmpty, bool processAnnot = true);
0279 
0280     /**
0281       * Parameters:
0282       *   contentElem - content element to check
0283       *
0284       * Check for identity constraints content.
0285       */
0286     const DOMElement* checkIdentityConstraintContent(const DOMElement* const contentElem);
0287 
0288     DatatypeValidator* getDatatypeValidator(const XMLCh* const uriStr,
0289                                             const XMLCh* const localPartStr);
0290 
0291     /**
0292       * Process simpleType content of a list|restriction|union
0293       * Return a dataype validator if valid type, otherwise 0.
0294       */
0295     DatatypeValidator* checkForSimpleTypeValidator(const DOMElement* const content,
0296                                                    int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
0297 
0298     /**
0299       * Process complexType content of an element
0300       * Return a ComplexTypeInfo if valid type, otherwise 0.
0301       */
0302     ComplexTypeInfo* checkForComplexTypeInfo(const DOMElement* const content);
0303 
0304     /**
0305       * Return DatatypeValidator available for the baseTypeStr.
0306       */
0307     DatatypeValidator* findDTValidator(const DOMElement* const elem,
0308                                        const XMLCh* const derivedTypeName,
0309                                        const XMLCh* const baseTypeName,
0310                                        const int baseRefContext);
0311 
0312     const XMLCh* resolvePrefixToURI(const DOMElement* const elem,
0313                                     const XMLCh* const prefix);
0314 
0315     /**
0316       * Return the prefix for a given rawname string
0317       *
0318       * Function allocated, caller managed (facm) - pointer to be deleted by
0319       * caller.
0320       */
0321     const XMLCh* getPrefix(const XMLCh* const rawName);
0322 
0323     /**
0324       * Return the local for a given rawname string
0325       *
0326       * caller allocated, caller managed (cacm)
0327       */
0328     const XMLCh* getLocalPart(const XMLCh* const rawName);
0329 
0330     /**
0331       * Process a 'ref' of an Element declaration
0332       */
0333     SchemaElementDecl* processElementDeclRef(const DOMElement* const elem,
0334                                              const XMLCh* const refName);
0335     void processElemDeclAttrs(const DOMElement* const elem,
0336                               SchemaElementDecl* const elemDecl,
0337                               const XMLCh*& valConstraint,
0338                               bool isTopLevel = false);
0339     void processElemDeclIC(DOMElement* const elem,
0340                            SchemaElementDecl* const elemDecl);
0341     bool checkElemDeclValueConstraint(const DOMElement* const elem,
0342                                       SchemaElementDecl* const elemDecl,
0343                                       const XMLCh* const valConstraint,
0344                                       ComplexTypeInfo* const typeInfo,
0345                                       DatatypeValidator* const validator);
0346 
0347     /**
0348       * Process a 'ref' of an Attribute declaration
0349       */
0350     void processAttributeDeclRef(const DOMElement* const elem,
0351                                  ComplexTypeInfo* const typeInfo,
0352                                  const XMLCh* const refName,
0353                                  const XMLCh* const useVal,
0354                                  const XMLCh* const defaultVal,
0355                                  const XMLCh* const fixedVal);
0356 
0357     /**
0358       * Process a 'ref' on a group
0359       */
0360     XercesGroupInfo* processGroupRef(const DOMElement* const elem,
0361                                      const XMLCh* const refName);
0362 
0363     /**
0364       * Process a 'ref' on a attributeGroup
0365       */
0366     XercesAttGroupInfo* processAttributeGroupRef(const DOMElement* const elem,
0367                                                  const XMLCh* const refName,
0368                                                  ComplexTypeInfo* const typeInfo);
0369 
0370     /**
0371       * Parse block & final items
0372       */
0373     int parseBlockSet(const DOMElement* const elem, const int blockType, const bool isRoot = false);
0374     int parseFinalSet(const DOMElement* const elem, const int finalType, const bool isRoot = false);
0375 
0376     /**
0377       * Return true if a name is an identity constraint, otherwise false
0378       */
0379     bool isIdentityConstraintName(const XMLCh* const constraintName);
0380 
0381     /**
0382       * If 'typeStr' belongs to a different schema, return that schema URI,
0383       * otherwise return 0;
0384       */
0385     const XMLCh* checkTypeFromAnotherSchema(const DOMElement* const elem,
0386                                             const XMLCh* const typeStr);
0387 
0388     /**
0389       * Return the datatype validator for a given element type attribute if
0390       * the type is a simple type
0391       */
0392     DatatypeValidator* getElementTypeValidator(const DOMElement* const elem,
0393                                                const XMLCh* const typeStr,
0394                                                bool& noErrorDetected,
0395                                                const XMLCh* const otherSchemaURI);
0396 
0397     /**
0398       * Return the complexType info for a given element type attribute if
0399       * the type is a complex type
0400       */
0401     ComplexTypeInfo* getElementComplexTypeInfo(const DOMElement* const elem,
0402                                                const XMLCh* const typeStr,
0403                                                const XMLCh* const otherSchemaURI);
0404 
0405     /**
0406       * Return global schema element declaration for a given element name
0407       */
0408     SchemaElementDecl* getGlobalElemDecl(const DOMElement* const elem,
0409                                          const XMLCh* const name);
0410 
0411     /**
0412       * Check validity constraint of a substitutionGroup attribute in
0413       * an element declaration
0414       */
0415     bool isSubstitutionGroupValid(const DOMElement* const elem,
0416                                   const SchemaElementDecl* const elemDecl,
0417                                   const ComplexTypeInfo* const typeInfo,
0418                                   const DatatypeValidator* const validator,
0419                                   const XMLCh* const elemName,
0420                                   const bool toEmit = true);
0421 
0422     bool isSubstitutionGroupCircular(SchemaElementDecl* const elemDecl,
0423                                      SchemaElementDecl* const subsElemDecl);
0424 
0425     void processSubstitutionGroup(const DOMElement* const elem,
0426                                   SchemaElementDecl* const elemDecl,
0427                                   ComplexTypeInfo*& typeInfo,
0428                                   DatatypeValidator*& validator,
0429                                   const XMLCh* const subsElemQName);
0430 
0431     /**
0432       * Create a 'SchemaElementDecl' object and add it to SchemaGrammar
0433       */
0434     SchemaElementDecl* createSchemaElementDecl(const DOMElement* const elem,
0435                                                const XMLCh* const name,
0436                                                bool& isDuplicate,
0437                                                const XMLCh*& valConstraint,
0438                                                const bool topLevel);
0439 
0440     /**
0441       * Return the value of a given attribute name from an element node
0442       */
0443     const XMLCh* getElementAttValue(const DOMElement* const elem,
0444                                     const XMLCh* const attName,
0445                                     const DatatypeValidator::ValidatorType attType = DatatypeValidator::UnKnown);
0446 
0447     /* return minOccurs */
0448     int checkMinMax(ContentSpecNode* const specNode,
0449                      const DOMElement* const elem,
0450                      const int allContext = Not_All_Context);
0451 
0452     /**
0453       * Process complex content for a complexType
0454       */
0455     void processComplexContent(const DOMElement* const elem,
0456                                const XMLCh* const typeName,
0457                                const DOMElement* const childElem,
0458                                ComplexTypeInfo* const typeInfo,
0459                                const XMLCh* const baseLocalPart,
0460                                const bool isMixed,
0461                                const bool isBaseAnyType = false);
0462 
0463     /**
0464       * Process "base" information for a complexType
0465       */
0466     void processBaseTypeInfo(const DOMElement* const elem,
0467                              const XMLCh* const baseName,
0468                              const XMLCh* const localPart,
0469                              const XMLCh* const uriStr,
0470                              ComplexTypeInfo* const typeInfo);
0471 
0472     /**
0473       * Check if base is from another schema
0474       */
0475     bool isBaseFromAnotherSchema(const XMLCh* const baseURI);
0476 
0477     /**
0478       * Get complexType infp from another schema
0479       */
0480     ComplexTypeInfo* getTypeInfoFromNS(const DOMElement* const elem,
0481                                        const XMLCh* const uriStr,
0482                                        const XMLCh* const localPart);
0483 
0484     DatatypeValidator*
0485     getAttrDatatypeValidatorNS(const DOMElement* const elem,
0486                                const XMLCh* localPart,
0487                                const XMLCh* typeURI);
0488 
0489     /**
0490       * Returns true if a DOM Element is an attribute or attribute group
0491       */
0492     bool isAttrOrAttrGroup(const DOMElement* const elem);
0493 
0494     /**
0495       * Process attributes of a complex type
0496       */
0497     void processAttributes(const DOMElement* const elem,
0498                            const DOMElement* const attElem,
0499                            ComplexTypeInfo* const typeInfo,
0500                            const bool isBaseAnyType = false);
0501 
0502     /**
0503       * Generate a name for an anonymous type
0504       */
0505     const XMLCh* genAnonTypeName(const XMLCh* const prefix);
0506 
0507     void defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo);
0508 
0509     /**
0510       * Resolve a schema location attribute value to an input source.
0511       * Caller to delete the returned object.
0512       */
0513     InputSource* resolveSchemaLocation
0514     (
0515         const XMLCh* const loc
0516         , const XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType
0517         , const XMLCh* const nameSpace=0
0518     );
0519 
0520     void restoreSchemaInfo(SchemaInfo* const toRestore,
0521                            SchemaInfo::ListType const aListType = SchemaInfo::INCLUDE,
0522                            const unsigned int saveScope = Grammar::TOP_LEVEL_SCOPE);
0523     void  popCurrentTypeNameStack();
0524 
0525     /**
0526       * Check whether a mixed content is emptiable or not.
0527       * Needed to validate element constraint values (defualt, fixed)
0528       */
0529     bool emptiableParticle(const ContentSpecNode* const specNode);
0530 
0531     void checkFixedFacet(const DOMElement* const, const XMLCh* const,
0532                          const DatatypeValidator* const, unsigned int&);
0533     void buildValidSubstitutionListF(const DOMElement* const elem,
0534                                      SchemaElementDecl* const,
0535                                      SchemaElementDecl* const);
0536     void buildValidSubstitutionListB(const DOMElement* const elem,
0537                                      SchemaElementDecl* const,
0538                                      SchemaElementDecl* const);
0539 
0540     void checkEnumerationRequiredNotation(const DOMElement* const elem,
0541                                           const XMLCh* const name,
0542                                           const XMLCh* const typeStr);
0543 
0544     void processElements(const DOMElement* const elem,
0545                          ComplexTypeInfo* const baseTypeInfo,
0546                          ComplexTypeInfo* const newTypeInfo);
0547 
0548     void processElements(const DOMElement* const elem,
0549                          XercesGroupInfo* const fromGroup,
0550                          ComplexTypeInfo* const typeInfo);
0551 
0552     void copyGroupElements(const DOMElement* const elem,
0553                            XercesGroupInfo* const fromGroup,
0554                            XercesGroupInfo* const toGroup,
0555                            ComplexTypeInfo* const typeInfo);
0556 
0557     void copyAttGroupAttributes(const DOMElement* const elem,
0558                                 XercesAttGroupInfo* const fromAttGroup,
0559                                 XercesAttGroupInfo* const toAttGroup,
0560                                 ComplexTypeInfo* const typeInfo);
0561 
0562     void checkForEmptyTargetNamespace(const DOMElement* const elem);
0563 
0564     /**
0565       * Attribute wild card intersection.
0566       *
0567       * Note:
0568       *    The first parameter will be the result of the intersection, so
0569       *    we need to make sure that first parameter is a copy of the
0570       *    actual attribute definition we need to intersect with.
0571       *
0572       *    What we need to wory about is: type, defaultType, namespace,
0573       *    and URI. All remaining data members should be the same.
0574       */
0575     void attWildCardIntersection(SchemaAttDef* const resultWildCart,
0576                                  const SchemaAttDef* const toCompareWildCard);
0577 
0578     /**
0579       * Attribute wild card union.
0580       *
0581       * Note:
0582       *    The first parameter will be the result of the union, so
0583       *    we need to make sure that first parameter is a copy of the
0584       *    actual attribute definition we need to intersect with.
0585       *
0586       *    What we need to wory about is: type, defaultType, namespace,
0587       *    and URI. All remaining data members should be the same.
0588       */
0589     void attWildCardUnion(SchemaAttDef* const resultWildCart,
0590                           const SchemaAttDef* const toCompareWildCard);
0591 
0592     void copyWildCardData(const SchemaAttDef* const srcWildCard,
0593                           SchemaAttDef* const destWildCard);
0594 
0595     /**
0596       * Check that the attributes of a type derived by restriction satisfy
0597       * the constraints of derivation valid restriction
0598       */
0599     void checkAttDerivationOK(const DOMElement* const elem,
0600                               const ComplexTypeInfo* const baseTypeInfo,
0601                               const ComplexTypeInfo* const childTypeInfo);
0602     void checkAttDerivationOK(const DOMElement* const elem,
0603                               const XercesAttGroupInfo* const baseAttGrpInfo,
0604                               const XercesAttGroupInfo* const childAttGrpInfo);
0605 
0606     /**
0607       * Check whether a namespace value is valid with respect to wildcard
0608       * constraint
0609       */
0610     bool wildcardAllowsNamespace(const SchemaAttDef* const baseAttWildCard,
0611                                  const unsigned int nameURI);
0612 
0613     /**
0614       * Check whether a namespace constraint is an intensional subset of
0615       * another namespace constraint
0616       */
0617     bool isWildCardSubset(const SchemaAttDef* const baseAttWildCard,
0618                           const SchemaAttDef* const childAttWildCard);
0619 
0620     bool openRedefinedSchema(const DOMElement* const redefineElem);
0621 
0622     /**
0623       * The purpose of this method is twofold:
0624       * 1. To find and appropriately modify all information items
0625       * in redefinedSchema with names that are redefined by children of
0626       * redefineElem.
0627       * 2.  To make sure the redefine element represented by
0628       * redefineElem is valid as far as content goes and with regard to
0629       * properly referencing components to be redefined.
0630       *
0631       * No traversing is done here!
0632       * This method also takes actions to find and, if necessary, modify
0633       * the names of elements in <redefine>'s in the schema that's being
0634       * redefined.
0635       */
0636     void renameRedefinedComponents(const DOMElement* const redefineElem,
0637                                    SchemaInfo* const redefiningSchemaInfo,
0638                                    SchemaInfo* const redefinedSchemaInfo);
0639 
0640     /**
0641       * This method returns true if the redefine component is valid, and if
0642       * it was possible to revise it correctly.
0643       */
0644     bool validateRedefineNameChange(const DOMElement* const redefineChildElem,
0645                                     const XMLCh* const redefineChildElemName,
0646                                     const XMLCh* const redefineChildDeclName,
0647                                     const int redefineNameCounter,
0648                                     SchemaInfo* const redefiningSchemaInfo);
0649 
0650     /**
0651       * This function looks among the children of 'redefineChildElem' for a
0652       * component of type 'redefineChildComponentName'. If it finds one, it
0653       * evaluates whether its ref attribute contains a reference to
0654       * 'refChildTypeName'. If it does, it returns 1 + the value returned by
0655       * calls to itself on all other children.  In all other cases it returns
0656       * 0 plus the sum of the values returned by calls to itself on
0657       * redefineChildElem's children. It also resets the value of ref so that
0658       * it will refer to the renamed type from the schema being redefined.
0659       */
0660     int changeRedefineGroup(const DOMElement* const redefineChildElem,
0661                             const XMLCh* const redefineChildComponentName,
0662                             const XMLCh* const redefineChildTypeName,
0663                             const int redefineNameCounter);
0664 
0665     /** This simple function looks for the first occurrence of a
0666       * 'redefineChildTypeName' item in the redefined schema and appropriately
0667       * changes the value of its name. If it turns out that what we're looking
0668       * for is in a <redefine> though, then we just rename it--and it's
0669       * reference--to be the same.
0670       */
0671     void fixRedefinedSchema(const DOMElement* const elem,
0672                             SchemaInfo* const redefinedSchemaInfo,
0673                             const XMLCh* const redefineChildComponentName,
0674                             const XMLCh* const redefineChildTypeName,
0675                             const int redefineNameCounter);
0676 
0677     void getRedefineNewTypeName(const XMLCh* const oldTypeName,
0678                                 const int redefineCounter,
0679                                 XMLBuffer& newTypeName);
0680 
0681     /**
0682       * This purpose of this method is threefold:
0683       * 1. To extract the schema information of included/redefined schema.
0684       * 2. Rename redefined components.
0685       * 3. Process components of included/redefined schemas
0686       */
0687     void preprocessRedefineInclude(SchemaInfo* const currSchemaInfo);
0688 
0689     /**
0690       * Update the list of valid substitution groups in the case of circular
0691       * import.
0692       */
0693     void updateCircularSubstitutionList(SchemaInfo* const aSchemaInfo);
0694 
0695     void processKeyRefFor(SchemaInfo* const aSchemaInfo,
0696                           ValueVectorOf<SchemaInfo*>* const infoList);
0697 
0698     void processAttValue(const XMLCh* const attVal, XMLBuffer& aBuf);
0699 
0700     // routine to generate synthetic annotations
0701     XSAnnotation* generateSyntheticAnnotation(const DOMElement* const elem
0702                                              , ValueVectorOf<DOMNode*>* nonXSAttList);
0703 
0704     // routine to validate annotations
0705     void validateAnnotations();
0706 
0707     // -----------------------------------------------------------------------
0708     //  Private constants
0709     // -----------------------------------------------------------------------
0710     enum
0711     {
0712         ES_Block
0713         , C_Block
0714         , S_Final
0715         , EC_Final
0716         , ECS_Final
0717     };
0718 
0719     enum ExceptionCodes
0720     {
0721         NoException = 0,
0722         InvalidComplexTypeInfo = 1,
0723         RecursingElement = 2
0724     };
0725 
0726     enum
0727     {
0728         Elem_Def_Qualified = 1,
0729         Attr_Def_Qualified = 2
0730     };
0731 
0732     // -----------------------------------------------------------------------
0733     //  Private data members
0734     // -----------------------------------------------------------------------
0735     bool                                           fFullConstraintChecking;
0736     int                                            fTargetNSURI;
0737     int                                            fEmptyNamespaceURI;
0738     unsigned int                                   fCurrentScope;
0739     unsigned int                                   fScopeCount;
0740     unsigned int                                   fAnonXSTypeCount;
0741     XMLSize_t                                      fCircularCheckIndex;
0742     const XMLCh*                                   fTargetNSURIString;
0743     DatatypeValidatorFactory*                      fDatatypeRegistry;
0744     GrammarResolver*                               fGrammarResolver;
0745     SchemaGrammar*                                 fSchemaGrammar;
0746     XMLEntityHandler*                              fEntityHandler;
0747     XMLErrorReporter*                              fErrorReporter;
0748     XMLStringPool*                                 fURIStringPool;
0749     XMLStringPool*                                 fStringPool;
0750     XMLBuffer                                      fBuffer;
0751     XMLScanner*                                    fScanner;
0752     RefHashTableOf<XMLAttDef>*                     fAttributeDeclRegistry;
0753     RefHashTableOf<ComplexTypeInfo>*               fComplexTypeRegistry;
0754     RefHashTableOf<XercesGroupInfo>*               fGroupRegistry;
0755     RefHashTableOf<XercesAttGroupInfo>*            fAttGroupRegistry;
0756     RefHashTableOf<ElemVector>*                    fIC_ElementsNS;
0757     RefHashTableOf<SchemaInfo, PtrHasher>*         fPreprocessedNodes;
0758     SchemaInfo*                                    fSchemaInfo;
0759     XercesGroupInfo*                               fCurrentGroupInfo;
0760     XercesAttGroupInfo*                            fCurrentAttGroupInfo;
0761     ComplexTypeInfo*                               fCurrentComplexType;
0762     ValueVectorOf<unsigned int>*                   fCurrentTypeNameStack;
0763     ValueVectorOf<unsigned int>*                   fCurrentGroupStack;
0764     ValueVectorOf<SchemaElementDecl*>*             fIC_Elements;
0765     ValueVectorOf<const DOMElement*>*              fDeclStack;
0766     ValueVectorOf<unsigned int>**                  fGlobalDeclarations;
0767     ValueVectorOf<DOMNode*>*                       fNonXSAttList;
0768     ValueVectorOf<int>*                            fImportedNSList;
0769     RefHashTableOf<ValueVectorOf<DOMElement*>, PtrHasher>* fIC_NodeListNS;
0770     RefHash2KeysTableOf<XMLCh>*                    fNotationRegistry;
0771     RefHash2KeysTableOf<XMLCh>*                    fRedefineComponents;
0772     RefHash2KeysTableOf<IdentityConstraint>*       fIdentityConstraintNames;
0773     RefHash2KeysTableOf<ElemVector>*               fValidSubstitutionGroups;
0774     RefHash2KeysTableOf<SchemaInfo>*               fSchemaInfoList;
0775     RefHash2KeysTableOf<SchemaInfo>*               fCachedSchemaInfoList;
0776     XSDDOMParser*                                  fParser;
0777     XSDErrorReporter                               fXSDErrorReporter;
0778     XSDLocator*                                    fLocator;
0779     MemoryManager*                                 fMemoryManager;
0780     MemoryManager*                                 fGrammarPoolMemoryManager;
0781     XSAnnotation*                                  fAnnotation;
0782     GeneralAttributeCheck                          fAttributeCheck;
0783 
0784     friend class GeneralAttributeCheck;
0785     friend class NamespaceScopeManager;
0786 };
0787 
0788 
0789 // ---------------------------------------------------------------------------
0790 //  TraverseSchema: Helper methods
0791 // ---------------------------------------------------------------------------
0792 inline const XMLCh* TraverseSchema::getPrefix(const XMLCh* const rawName) {
0793 
0794     int colonIndex = XMLString::indexOf(rawName, chColon);
0795 
0796     if (colonIndex == -1 || colonIndex == 0) {
0797         return XMLUni::fgZeroLenString;
0798     }
0799 
0800     fBuffer.set(rawName, colonIndex);
0801 
0802     return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
0803 }
0804 
0805 inline const XMLCh* TraverseSchema::getLocalPart(const XMLCh* const rawName) {
0806 
0807     int    colonIndex = XMLString::indexOf(rawName, chColon);
0808     XMLSize_t rawNameLen = XMLString::stringLen(rawName);
0809 
0810     if (XMLSize_t(colonIndex + 1) == rawNameLen) {
0811         return XMLUni::fgZeroLenString;
0812     }
0813 
0814     if (colonIndex == -1) {
0815         fBuffer.set(rawName, rawNameLen);
0816     }
0817     else {
0818 
0819         fBuffer.set(rawName + colonIndex + 1, rawNameLen - colonIndex - 1);
0820     }
0821 
0822     return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
0823 }
0824 
0825 inline void
0826 TraverseSchema::checkForEmptyTargetNamespace(const DOMElement* const elem) {
0827 
0828     const XMLCh* targetNS = getElementAttValue(elem, SchemaSymbols::fgATT_TARGETNAMESPACE);
0829 
0830     if (targetNS && !*targetNS) {
0831         reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidTargetNSValue);
0832     }
0833 }
0834 
0835 inline bool TraverseSchema::isBaseFromAnotherSchema(const XMLCh* const baseURI)
0836 {
0837     if (!XMLString::equals(baseURI,fTargetNSURIString)
0838         && !XMLString::equals(baseURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)
0839         && (baseURI && *baseURI)) {
0840         //REVISIT, !!!! a hack: for schema that has no
0841         //target namespace, e.g. personal-schema.xml
0842         return true;
0843     }
0844 
0845     return false;
0846 }
0847 
0848 inline bool TraverseSchema::isAttrOrAttrGroup(const DOMElement* const elem) {
0849 
0850     const XMLCh* elementName = elem->getLocalName();
0851 
0852     if (XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTE) ||
0853         XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTEGROUP) ||
0854         XMLString::equals(elementName, SchemaSymbols::fgELT_ANYATTRIBUTE)) {
0855         return true;
0856     }
0857 
0858     return false;
0859 }
0860 
0861 inline const XMLCh* TraverseSchema::genAnonTypeName(const XMLCh* const prefix) {
0862 
0863     XMLCh anonCountStr[16]; // a count of 15 digits should be enough
0864 
0865     XMLString::sizeToText(fAnonXSTypeCount++, anonCountStr, 15, 10, fMemoryManager);
0866     fBuffer.set(prefix);
0867     fBuffer.append(anonCountStr);
0868 
0869     return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
0870 }
0871 
0872 inline void TraverseSchema::popCurrentTypeNameStack() {
0873 
0874     XMLSize_t stackSize = fCurrentTypeNameStack->size();
0875 
0876     if (stackSize != 0) {
0877         fCurrentTypeNameStack->removeElementAt(stackSize - 1);
0878     }
0879 }
0880 
0881 inline void
0882 TraverseSchema::copyWildCardData(const SchemaAttDef* const srcWildCard,
0883                                  SchemaAttDef* const destWildCard) {
0884 
0885     destWildCard->getAttName()->setURI(srcWildCard->getAttName()->getURI());
0886     destWildCard->setType(srcWildCard->getType());
0887     destWildCard->setDefaultType(srcWildCard->getDefaultType());
0888 }
0889 
0890 inline void TraverseSchema::getRedefineNewTypeName(const XMLCh* const oldTypeName,
0891                                                    const int redefineCounter,
0892                                                    XMLBuffer& newTypeName) {
0893 
0894     newTypeName.set(oldTypeName);
0895 
0896     for (int i=0; i < redefineCounter; i++) {
0897         newTypeName.append(SchemaSymbols::fgRedefIdentifier);
0898     }
0899 }
0900 
0901 inline bool TraverseSchema::isImportingNS(const int namespaceURI) {
0902 
0903     if (!fImportedNSList)
0904         return false;
0905 
0906     return (fImportedNSList->containsElement(namespaceURI));
0907 }
0908 
0909 inline void TraverseSchema::addImportedNS(const int namespaceURI) {
0910 
0911     if (!fImportedNSList) {
0912         fImportedNSList = new (fMemoryManager) ValueVectorOf<int>(4, fMemoryManager);
0913     }
0914 
0915     if (!fImportedNSList->containsElement(namespaceURI))
0916         fImportedNSList->addElement(namespaceURI);
0917 }
0918 
0919 XERCES_CPP_NAMESPACE_END
0920 
0921 #endif
0922 
0923 /**
0924   * End of file TraverseSchema.hpp
0925   */