Back to home page

EIC code displayed by LXR

 
 

    


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

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_SCHEMAINFO_HPP)
0023 #define XERCESC_INCLUDE_GUARD_SCHEMAINFO_HPP
0024 
0025 
0026 /** When in a <redefine>, type definitions being used (and indeed
0027   * refs to <group>'s and <attributeGroup>'s) may refer to info
0028   * items either in the schema being redefined, in the <redefine>,
0029   * or else in the schema doing the redefining.  Because of this
0030   * latter we have to be prepared sometimes to look for our type
0031   * definitions outside the schema stored in fSchemaRootElement.
0032   * This simple class does this; it's just a linked list that
0033   * lets us look at the <schema>'s on the queue; note also that this
0034   * should provide us with a mechanism to handle nested <redefine>'s.
0035   * It's also a handy way of saving schema info when importing/including.
0036   */
0037 
0038 // ---------------------------------------------------------------------------
0039 //  Includes
0040 // ---------------------------------------------------------------------------
0041 #include <xercesc/dom/DOMElement.hpp>
0042 #include <xercesc/util/RefVectorOf.hpp>
0043 #include <xercesc/util/ValueVectorOf.hpp>
0044 #include <xercesc/util/RefHashTableOf.hpp>
0045 
0046 XERCES_CPP_NAMESPACE_BEGIN
0047 
0048 // ---------------------------------------------------------------------------
0049 //  Forward Declarations
0050 // ---------------------------------------------------------------------------
0051 class XMLScanner;
0052 class ValidationContext;
0053 class NamespaceScope;
0054 
0055 class VALIDATORS_EXPORT SchemaInfo : public XMemory
0056 {
0057 public:
0058 
0059     enum ListType {
0060         // Redefine is treated as an include
0061         IMPORT = 1,
0062         INCLUDE = 2
0063     };
0064 
0065     enum {
0066         C_ComplexType,
0067         C_SimpleType,
0068         C_Group,
0069         C_Attribute,
0070         C_AttributeGroup,
0071         C_Element,
0072         C_Notation,
0073 
0074         C_Count
0075     };
0076 
0077     // -----------------------------------------------------------------------
0078     //  Constructor/Destructor
0079     // -----------------------------------------------------------------------
0080     SchemaInfo(const unsigned short fElemAttrDefaultQualified,
0081                const int blockDefault,
0082                const int finalDefault,
0083                const int targetNSURI,
0084                const NamespaceScope* const currNamespaceScope,
0085                const XMLCh* const schemaURL,
0086                const XMLCh* const targetNSURIString,
0087                const DOMElement* const root,
0088                XMLScanner* xmlScanner,
0089                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0090     ~SchemaInfo();
0091 
0092 
0093     // -----------------------------------------------------------------------
0094     //  Getter methods
0095     // -----------------------------------------------------------------------
0096     XMLCh*                            getCurrentSchemaURL() const;
0097     const XMLCh*                      getTargetNSURIString() const;
0098     const DOMElement*                 getRoot() const;
0099     bool                              getProcessed() const;
0100     int                               getBlockDefault() const;
0101     int                               getFinalDefault() const;
0102     int                               getTargetNSURI() const;
0103     NamespaceScope*                   getNamespaceScope() const;
0104     unsigned short                    getElemAttrDefaultQualified() const;
0105     BaseRefVectorEnumerator<SchemaInfo>   getImportingListEnumerator() const;
0106     ValueVectorOf<const DOMElement*>* getRecursingAnonTypes() const;
0107     ValueVectorOf<const XMLCh*>*      getRecursingTypeNames() const;
0108     ValueVectorOf<DOMNode*>*          getNonXSAttList() const;
0109     ValidationContext*                getValidationContext() const;
0110 
0111     // -----------------------------------------------------------------------
0112     //  Setter methods
0113     // -----------------------------------------------------------------------
0114     void setProcessed(const bool aValue = true);
0115     void setBlockDefault(const int aValue);
0116     void setFinalDefault(const int aValue);
0117     void setElemAttrDefaultQualified(const unsigned short aValue);
0118     void resetRoot ();
0119 
0120     // -----------------------------------------------------------------------
0121     //  Access methods
0122     // -----------------------------------------------------------------------
0123     void addSchemaInfo(SchemaInfo* const toAdd, const ListType aListType);
0124     bool containsInfo(const SchemaInfo* const toCheck, const ListType aListType) const;
0125     SchemaInfo* getImportInfo(const unsigned int namespaceURI) const;
0126     DOMElement* getTopLevelComponent(const unsigned short compCategory,
0127                                      const XMLCh* const compName,
0128                                      const XMLCh* const name);
0129     DOMElement* getTopLevelComponent(const unsigned short compCategory,
0130                                      const XMLCh* const compName,
0131                                      const XMLCh* const name,
0132                                      SchemaInfo** enclosingSchema);
0133     void updateImportingInfo(SchemaInfo* const importingInfo);
0134     bool circularImportExist(const unsigned int nameSpaceURI);
0135     bool isFailedRedefine(const DOMElement* const anElem);
0136     void addFailedRedefine(const DOMElement* const anElem);
0137     void addRecursingType(const DOMElement* const elem, const XMLCh* const name);
0138 
0139 private:
0140     // -----------------------------------------------------------------------
0141     //  Unimplemented constructors and operators
0142     // -----------------------------------------------------------------------
0143     SchemaInfo(const SchemaInfo&);
0144     SchemaInfo& operator=(const SchemaInfo&);
0145 
0146     // -----------------------------------------------------------------------
0147     //  Private helper methods
0148     // -----------------------------------------------------------------------
0149     void clearTopLevelComponents();
0150 
0151     // -----------------------------------------------------------------------
0152     //  Private data members
0153     // -----------------------------------------------------------------------
0154     bool                              fAdoptInclude;
0155     bool                              fProcessed;
0156     unsigned short                    fElemAttrDefaultQualified;
0157     int                               fBlockDefault;
0158     int                               fFinalDefault;
0159     int                               fTargetNSURI;
0160     NamespaceScope*                   fNamespaceScope;
0161     XMLCh*                            fCurrentSchemaURL;
0162     XMLCh*                            fTargetNSURIString;
0163     const DOMElement*                 fSchemaRootElement;
0164     RefVectorOf<SchemaInfo>*          fIncludeInfoList;
0165     RefVectorOf<SchemaInfo>*          fImportedInfoList;
0166     RefVectorOf<SchemaInfo>*          fImportingInfoList;
0167     ValueVectorOf<const DOMElement*>* fFailedRedefineList;
0168     ValueVectorOf<const DOMElement*>* fRecursingAnonTypes;
0169     ValueVectorOf<const XMLCh*>*      fRecursingTypeNames;
0170     RefHashTableOf<DOMElement>*       fTopLevelComponents[C_Count];
0171     DOMElement*                       fLastTopLevelComponent[C_Count];
0172     ValueVectorOf<DOMNode*>*          fNonXSAttList;
0173     ValidationContext*                fValidationContext;
0174     MemoryManager*                    fMemoryManager;
0175 };
0176 
0177 // ---------------------------------------------------------------------------
0178 //  SchemaInfo: Getter methods
0179 // ---------------------------------------------------------------------------
0180 inline unsigned short SchemaInfo::getElemAttrDefaultQualified() const {
0181 
0182     return fElemAttrDefaultQualified;
0183 }
0184 
0185 inline bool SchemaInfo::getProcessed() const {
0186 
0187     return fProcessed;
0188 }
0189 
0190 inline int SchemaInfo::getBlockDefault() const {
0191 
0192     return fBlockDefault;
0193 }
0194 
0195 inline int SchemaInfo::getFinalDefault() const {
0196 
0197     return fFinalDefault;
0198 }
0199 
0200 inline NamespaceScope* SchemaInfo::getNamespaceScope() const {
0201     return fNamespaceScope;
0202 }
0203 
0204 inline XMLCh* SchemaInfo::getCurrentSchemaURL() const {
0205 
0206     return fCurrentSchemaURL;
0207 }
0208 
0209 inline const XMLCh* SchemaInfo::getTargetNSURIString() const {
0210 
0211     return fTargetNSURIString;
0212 }
0213 
0214 inline const DOMElement* SchemaInfo::getRoot() const {
0215 
0216     return fSchemaRootElement;
0217 }
0218 
0219 inline int SchemaInfo::getTargetNSURI() const {
0220 
0221     return fTargetNSURI;
0222 }
0223 
0224 inline BaseRefVectorEnumerator<SchemaInfo>
0225 SchemaInfo::getImportingListEnumerator() const {
0226 
0227     return BaseRefVectorEnumerator<SchemaInfo>(fImportingInfoList);
0228 }
0229 
0230 inline ValueVectorOf<const DOMElement*>*
0231 SchemaInfo::getRecursingAnonTypes() const {
0232 
0233     return fRecursingAnonTypes;
0234 }
0235 
0236 
0237 inline ValueVectorOf<const XMLCh*>*
0238 SchemaInfo::getRecursingTypeNames() const {
0239 
0240     return fRecursingTypeNames;
0241 }
0242 
0243 inline ValueVectorOf<DOMNode*>* SchemaInfo::getNonXSAttList() const
0244 {
0245     return fNonXSAttList;
0246 }
0247 
0248 // ---------------------------------------------------------------------------
0249 //  Setter methods
0250 // ---------------------------------------------------------------------------
0251 inline void SchemaInfo::setBlockDefault(const int aValue) {
0252 
0253     fBlockDefault = aValue;
0254 }
0255 
0256 inline void SchemaInfo::setFinalDefault(const int aValue) {
0257 
0258     fFinalDefault = aValue;
0259 }
0260 
0261 inline void SchemaInfo::setElemAttrDefaultQualified(const unsigned short aValue) {
0262 
0263     fElemAttrDefaultQualified = aValue;
0264 }
0265 
0266 inline void SchemaInfo::setProcessed(const bool aValue) {
0267 
0268     fProcessed = aValue;
0269 
0270 /*    if (fProcessed && fIncludeInfoList) {
0271 
0272         unsigned int includeListLen = fIncludeInfoList->size());
0273         for (unsigned int i = 0; i < includeListLen; i++) {
0274             fIncludeInfoList->elementAt(i)->clearTopLevelComponents();
0275         }
0276     }*/
0277 }
0278 
0279 inline void SchemaInfo::resetRoot ()
0280 {
0281     fSchemaRootElement = 0;
0282 }
0283 
0284 // ---------------------------------------------------------------------------
0285 //  SchemaInfo: Access methods
0286 // ---------------------------------------------------------------------------
0287 inline void SchemaInfo::addSchemaInfo(SchemaInfo* const toAdd,
0288                                       const ListType aListType) {
0289 
0290     if (aListType == IMPORT) {
0291 
0292         if (!fImportedInfoList)
0293             fImportedInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager);
0294 
0295         if (!fImportedInfoList->containsElement(toAdd)) {
0296 
0297             fImportedInfoList->addElement(toAdd);
0298             toAdd->updateImportingInfo(this);
0299         }
0300     }
0301     else {
0302 
0303         if (!fIncludeInfoList) {
0304 
0305             fIncludeInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(8, false, fMemoryManager);
0306             fAdoptInclude = true;
0307         }
0308 
0309         if (!fIncludeInfoList->containsElement(toAdd)) {
0310 
0311             fIncludeInfoList->addElement(toAdd);
0312             //code was originally:
0313             //toAdd->fIncludeInfoList = fIncludeInfoList;
0314             //however for handling multiple imports this was causing
0315             //to schemaInfo's to have the same fIncludeInfoList which they
0316             //both owned so when it was deleted it crashed.
0317             if (toAdd->fIncludeInfoList) {
0318                if (toAdd->fIncludeInfoList != fIncludeInfoList) {
0319                    XMLSize_t size = toAdd->fIncludeInfoList->size();
0320                    for (XMLSize_t i=0; i<size; i++) {
0321                        if (!fIncludeInfoList->containsElement(toAdd->fIncludeInfoList->elementAt(i))) {
0322                             fIncludeInfoList->addElement(toAdd->fIncludeInfoList->elementAt(i));
0323                        }
0324                    }
0325                    size = fIncludeInfoList->size();
0326                    for (XMLSize_t j=0; j<size; j++) {
0327                        if (!toAdd->fIncludeInfoList->containsElement(fIncludeInfoList->elementAt(j))) {
0328                             toAdd->fIncludeInfoList->addElement(fIncludeInfoList->elementAt(j));
0329                        }
0330                    }
0331                }
0332             }
0333             else {
0334                 toAdd->fIncludeInfoList = fIncludeInfoList;
0335             }
0336         }
0337     }
0338 }
0339 
0340 inline SchemaInfo* SchemaInfo::getImportInfo(const unsigned int namespaceURI) const {
0341 
0342     XMLSize_t importSize = (fImportedInfoList) ? fImportedInfoList->size() : 0;
0343     SchemaInfo* currInfo = 0;
0344 
0345     for (XMLSize_t i=0; i < importSize; i++) {
0346 
0347         currInfo = fImportedInfoList->elementAt(i);
0348 
0349         if (currInfo->getTargetNSURI() == (int) namespaceURI)
0350             return currInfo;
0351     }
0352 
0353     return 0;
0354 }
0355 
0356 inline ValidationContext* SchemaInfo::getValidationContext() const {
0357 
0358     return fValidationContext;
0359 }
0360 
0361 inline bool SchemaInfo::containsInfo(const SchemaInfo* const toCheck,
0362                                      const ListType aListType) const {
0363 
0364     if ((aListType == INCLUDE) && fIncludeInfoList) {
0365         return fIncludeInfoList->containsElement(toCheck);
0366     }
0367     else if ((aListType == IMPORT) && fImportedInfoList) {
0368         return fImportedInfoList->containsElement(toCheck);
0369     }
0370 
0371     return false;
0372 }
0373 
0374 inline bool SchemaInfo::circularImportExist(const unsigned int namespaceURI) {
0375 
0376     XMLSize_t importSize = fImportingInfoList->size();
0377 
0378     for (XMLSize_t i=0; i < importSize; i++) {
0379         if (fImportingInfoList->elementAt(i)->getTargetNSURI() == (int) namespaceURI) {
0380             return true;
0381         }
0382     }
0383 
0384     return false;
0385 }
0386 
0387 inline bool SchemaInfo::isFailedRedefine(const DOMElement* const anElem) {
0388 
0389     if (fFailedRedefineList)
0390         return (fFailedRedefineList->containsElement(anElem));
0391 
0392     return false;
0393 }
0394 
0395 inline void SchemaInfo::addFailedRedefine(const DOMElement* const anElem) {
0396 
0397     if (!fFailedRedefineList) {
0398         fFailedRedefineList = new (fMemoryManager) ValueVectorOf<const DOMElement*>(4, fMemoryManager);
0399     }
0400 
0401     fFailedRedefineList->addElement(anElem);
0402 }
0403 
0404 inline void SchemaInfo::addRecursingType(const DOMElement* const elem,
0405                                          const XMLCh* const name) {
0406 
0407     if (!fRecursingAnonTypes) {
0408         fRecursingAnonTypes = new (fMemoryManager) ValueVectorOf<const DOMElement*>(8, fMemoryManager);
0409         fRecursingTypeNames = new (fMemoryManager) ValueVectorOf<const XMLCh*>(8, fMemoryManager);
0410     }
0411 
0412     fRecursingAnonTypes->addElement(elem);
0413     fRecursingTypeNames->addElement(name);
0414 }
0415 
0416 inline void SchemaInfo::clearTopLevelComponents() {
0417 
0418     for (unsigned int i = 0; i < C_Count; i++) {
0419 
0420         delete fTopLevelComponents[i];
0421         fTopLevelComponents[i] = 0;
0422         fLastTopLevelComponent[i] = 0;
0423     }
0424 }
0425 
0426 XERCES_CPP_NAMESPACE_END
0427 
0428 #endif
0429 
0430 /**
0431   * End of file SchemaInfo.hpp
0432   */