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_COMPLEXTYPEINFO_HPP)
0023 #define XERCESC_INCLUDE_GUARD_COMPLEXTYPEINFO_HPP
0024 
0025 
0026 /**
0027   * The class act as a place holder to store complex type information.
0028   *
0029   * The class is intended for internal use.
0030   */
0031 
0032 // ---------------------------------------------------------------------------
0033 //  Includes
0034 // ---------------------------------------------------------------------------
0035 #include <xercesc/util/XMLString.hpp>
0036 #include <xercesc/util/RefHash2KeysTableOf.hpp>
0037 #include <xercesc/util/RefVectorOf.hpp>
0038 #include <xercesc/framework/XMLElementDecl.hpp>
0039 #include <xercesc/framework/XMLContentModel.hpp>
0040 #include <xercesc/validators/schema/SchemaAttDef.hpp>
0041 #include <xercesc/internal/XSerializable.hpp>
0042 
0043 XERCES_CPP_NAMESPACE_BEGIN
0044 
0045 
0046 // ---------------------------------------------------------------------------
0047 //  Forward Declarations
0048 // ---------------------------------------------------------------------------
0049 class DatatypeValidator;
0050 class ContentSpecNode;
0051 class SchemaAttDefList;
0052 class SchemaElementDecl;
0053 class XSDLocator;
0054 
0055 
0056 class VALIDATORS_EXPORT ComplexTypeInfo : public XSerializable, public XMemory
0057 {
0058 public:
0059     // -----------------------------------------------------------------------
0060     //  Public Constructors/Destructor
0061     // -----------------------------------------------------------------------
0062     ComplexTypeInfo(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0063     ~ComplexTypeInfo();
0064 
0065     // -----------------------------------------------------------------------
0066     //  Getter methods
0067     // -----------------------------------------------------------------------
0068     bool                     getAbstract() const;
0069     bool                     getAdoptContentSpec() const;
0070     bool                     containsAttWithTypeId() const;
0071     bool                     getPreprocessed() const;
0072     int                      getDerivedBy() const;
0073     int                      getBlockSet() const;
0074     int                      getFinalSet() const;
0075     unsigned int             getScopeDefined() const;
0076     unsigned int             getElementId() const;
0077     int                      getContentType() const;
0078     XMLSize_t                elementCount() const;
0079     XMLCh*                   getTypeName() const;
0080     DatatypeValidator*       getBaseDatatypeValidator() const;
0081     DatatypeValidator*       getDatatypeValidator() const;
0082     ComplexTypeInfo*         getBaseComplexTypeInfo() const;
0083     ContentSpecNode*         getContentSpec() const;
0084     const SchemaAttDef*      getAttWildCard() const;
0085     SchemaAttDef*            getAttWildCard();
0086     const SchemaAttDef*      getAttDef(const XMLCh* const baseName,
0087                                        const int uriId) const;
0088     SchemaAttDef*            getAttDef(const XMLCh* const baseName,
0089                                        const int uriId);
0090     XMLAttDefList&           getAttDefList() const;
0091     const SchemaElementDecl* elementAt(const XMLSize_t index) const;
0092     SchemaElementDecl*       elementAt(const XMLSize_t index);
0093     XMLContentModel*         getContentModel(const bool checkUPA = false);
0094     const XMLCh*             getFormattedContentModel ()   const;
0095     XSDLocator*              getLocator() const;
0096     const XMLCh*             getTypeLocalName() const;
0097     const XMLCh*             getTypeUri() const;
0098 
0099     /**
0100      * returns true if this type is anonymous
0101      **/
0102     bool getAnonymous() const;
0103 
0104     // -----------------------------------------------------------------------
0105     //  Setter methods
0106     // -----------------------------------------------------------------------
0107     void setAbstract(const bool isAbstract);
0108     void setAdoptContentSpec(const bool toAdopt);
0109     void setAttWithTypeId(const bool value);
0110     void setPreprocessed(const bool aValue = true);
0111     void setDerivedBy(const int derivedBy);
0112     void setBlockSet(const int blockSet);
0113     void setFinalSet(const int finalSet);
0114     void setScopeDefined(const unsigned int scopeDefined);
0115     void setElementId(const unsigned int elemId);
0116     void setTypeName(const XMLCh* const typeName);
0117     void setContentType(const int contentType);
0118     void setBaseDatatypeValidator(DatatypeValidator* const baseValidator);
0119     void setDatatypeValidator(DatatypeValidator* const validator);
0120     void setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo);
0121     void setContentSpec(ContentSpecNode* const toAdopt);
0122     void setAttWildCard(SchemaAttDef* const toAdopt);
0123     void addAttDef(SchemaAttDef* const toAdd);
0124     void addElement(SchemaElementDecl* const toAdd);
0125     void setLocator(XSDLocator* const aLocator);
0126 
0127     /**
0128      * sets this type to be anonymous
0129      **/
0130     void setAnonymous();
0131 
0132     // -----------------------------------------------------------------------
0133     //  Helper methods
0134     // -----------------------------------------------------------------------
0135     bool hasAttDefs() const;
0136     bool contains(const XMLCh* const attName);
0137     void checkUniqueParticleAttribution
0138     (
0139         SchemaGrammar*    const pGrammar
0140       , GrammarResolver*  const pGrammarResolver
0141       , XMLStringPool*    const pStringPool
0142       , XMLValidator*     const pValidator
0143     ) ;
0144 
0145     /**
0146       * Return a singleton that represents 'anyType'
0147       *
0148       * @param emptyNSId the uri id of the empty namespace
0149       */
0150     static ComplexTypeInfo* getAnyType(unsigned int emptyNSId);
0151 
0152     /**
0153       *  Notification that lazy data has been deleted
0154       */
0155     static void reinitAnyType();
0156 
0157     /***
0158      * Support for Serialization/De-serialization
0159      ***/
0160     DECL_XSERIALIZABLE(ComplexTypeInfo)
0161 
0162 private:
0163     // -----------------------------------------------------------------------
0164     //  Unimplemented constructors and operators
0165     // -----------------------------------------------------------------------
0166     ComplexTypeInfo(const ComplexTypeInfo& elemInfo);
0167     ComplexTypeInfo& operator= (const ComplexTypeInfo& other);
0168 
0169     // -----------------------------------------------------------------------
0170     //  Private helper methods
0171     // -----------------------------------------------------------------------
0172     void faultInAttDefList() const;
0173     bool useRepeatingLeafNodes(ContentSpecNode* particle);
0174     XMLContentModel* makeContentModel(bool checkUPA = false);
0175     XMLCh* formatContentModel () const ;
0176     ContentSpecNode* expandContentModel(ContentSpecNode* const curNode, int minOccurs, int maxOccurs, bool bAllowCompactSyntax);
0177     ContentSpecNode* convertContentSpecTree(ContentSpecNode* const curNode, bool checkUPA, bool bAllowCompactSyntax);
0178     void resizeContentSpecOrgURI();
0179 
0180     // -----------------------------------------------------------------------
0181     //  Private data members
0182     // -----------------------------------------------------------------------
0183     bool                               fAnonymous;
0184     bool                               fAbstract;
0185     bool                               fAdoptContentSpec;
0186     bool                               fAttWithTypeId;
0187     bool                               fPreprocessed;
0188     int                                fDerivedBy;
0189     int                                fBlockSet;
0190     int                                fFinalSet;
0191     unsigned int                       fScopeDefined;
0192     int                                fContentType;
0193 
0194     unsigned int                       fElementId;
0195     unsigned int                       fUniqueURI;
0196     unsigned int                       fContentSpecOrgURISize;
0197 
0198     XMLCh*                             fTypeName;
0199     XMLCh*                             fTypeLocalName;
0200     XMLCh*                             fTypeUri;
0201     DatatypeValidator*                 fBaseDatatypeValidator;
0202     DatatypeValidator*                 fDatatypeValidator;
0203     ComplexTypeInfo*                   fBaseComplexTypeInfo;
0204     ContentSpecNode*                   fContentSpec;
0205     SchemaAttDef*                      fAttWildCard;
0206     SchemaAttDefList*                  fAttList;
0207     RefVectorOf<SchemaElementDecl>*    fElements;
0208     RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
0209     XMLContentModel*                   fContentModel;
0210     XMLCh*                             fFormattedModel;
0211     unsigned int*                      fContentSpecOrgURI;
0212     XSDLocator*                        fLocator;
0213     MemoryManager*                     fMemoryManager;
0214 
0215     static ComplexTypeInfo*            fAnyType;
0216 
0217     friend class XMLInitializer;
0218 };
0219 
0220 // ---------------------------------------------------------------------------
0221 //  ComplexTypeInfo: Getter methods
0222 // ---------------------------------------------------------------------------
0223 inline bool ComplexTypeInfo::getAbstract() const {
0224 
0225     return fAbstract;
0226 }
0227 
0228 inline bool ComplexTypeInfo::getAdoptContentSpec() const {
0229 
0230     return fAdoptContentSpec;
0231 }
0232 
0233 inline bool ComplexTypeInfo::containsAttWithTypeId() const {
0234 
0235     return fAttWithTypeId;
0236 }
0237 
0238 inline bool ComplexTypeInfo::getPreprocessed() const {
0239 
0240     return fPreprocessed;
0241 }
0242 
0243 inline int ComplexTypeInfo::getDerivedBy() const {
0244 
0245     return fDerivedBy;
0246 }
0247 
0248 inline int ComplexTypeInfo::getBlockSet() const {
0249 
0250     return fBlockSet;
0251 }
0252 
0253 inline int ComplexTypeInfo::getFinalSet() const {
0254 
0255     return fFinalSet;
0256 }
0257 
0258 inline unsigned int ComplexTypeInfo::getScopeDefined() const {
0259 
0260     return fScopeDefined;
0261 }
0262 
0263 inline unsigned int ComplexTypeInfo::getElementId() const {
0264 
0265     return fElementId;
0266 }
0267 
0268 inline int ComplexTypeInfo::getContentType() const {
0269 
0270     return fContentType;
0271 }
0272 
0273 inline XMLSize_t ComplexTypeInfo::elementCount() const {
0274 
0275     if (fElements) {
0276         return fElements->size();
0277     }
0278 
0279     return 0;
0280 }
0281 
0282 inline XMLCh* ComplexTypeInfo::getTypeName() const {
0283     return fTypeName;
0284 }
0285 
0286 inline DatatypeValidator* ComplexTypeInfo::getBaseDatatypeValidator() const {
0287 
0288     return fBaseDatatypeValidator;
0289 }
0290 
0291 inline DatatypeValidator* ComplexTypeInfo::getDatatypeValidator() const {
0292 
0293     return fDatatypeValidator;
0294 }
0295 
0296 inline ComplexTypeInfo* ComplexTypeInfo::getBaseComplexTypeInfo() const {
0297 
0298     return fBaseComplexTypeInfo;
0299 }
0300 
0301 inline ContentSpecNode* ComplexTypeInfo::getContentSpec() const {
0302 
0303     return fContentSpec;
0304 }
0305 
0306 inline const SchemaAttDef* ComplexTypeInfo::getAttWildCard() const {
0307 
0308     return fAttWildCard;
0309 }
0310 
0311 inline SchemaAttDef* ComplexTypeInfo::getAttWildCard() {
0312 
0313     return fAttWildCard;
0314 }
0315 
0316 inline const SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
0317                                                       const int uriId) const {
0318 
0319     return fAttDefs->get(baseName, uriId);
0320 }
0321 
0322 inline SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
0323                                                 const int uriId)
0324 {
0325     return fAttDefs->get(baseName, uriId);
0326 }
0327 
0328 inline SchemaElementDecl*
0329 ComplexTypeInfo::elementAt(const XMLSize_t index) {
0330 
0331     if (!fElements) {
0332         return 0; // REVISIT - need to throw an exception
0333     }
0334 
0335     return fElements->elementAt(index);
0336 }
0337 
0338 inline const SchemaElementDecl*
0339 ComplexTypeInfo::elementAt(const XMLSize_t index) const {
0340 
0341     if (!fElements) {
0342         return 0; // REVISIT - need to throw an exception
0343     }
0344 
0345     return fElements->elementAt(index);
0346 }
0347 
0348 inline XMLContentModel* ComplexTypeInfo::getContentModel(const bool checkUPA)
0349 {
0350     if (!fContentModel && fContentSpec)
0351         fContentModel = makeContentModel(checkUPA);
0352 
0353     return fContentModel;
0354 }
0355 
0356 inline XSDLocator* ComplexTypeInfo::getLocator() const
0357 {
0358     return fLocator;
0359 }
0360 
0361 inline bool ComplexTypeInfo::getAnonymous() const {
0362     return fAnonymous;
0363 }
0364 
0365 inline const XMLCh* ComplexTypeInfo::getTypeLocalName() const
0366 {
0367     return fTypeLocalName;
0368 }
0369 
0370 inline const XMLCh* ComplexTypeInfo::getTypeUri() const
0371 {
0372    return fTypeUri;
0373 }
0374 
0375 // ---------------------------------------------------------------------------
0376 //  ComplexTypeInfo: Setter methods
0377 // ---------------------------------------------------------------------------
0378 inline void ComplexTypeInfo::setAbstract(const bool isAbstract) {
0379 
0380     fAbstract = isAbstract;
0381 }
0382 
0383 inline void ComplexTypeInfo::setAdoptContentSpec(const bool toAdopt) {
0384 
0385     fAdoptContentSpec = toAdopt;
0386 }
0387 
0388 inline void ComplexTypeInfo::setAttWithTypeId(const bool value) {
0389 
0390     fAttWithTypeId = value;
0391 }
0392 
0393 inline void ComplexTypeInfo::setPreprocessed(const bool aValue) {
0394 
0395     fPreprocessed = aValue;
0396 }
0397 
0398 inline void ComplexTypeInfo::setDerivedBy(const int derivedBy) {
0399 
0400     fDerivedBy = derivedBy;
0401 }
0402 
0403 inline void ComplexTypeInfo::setBlockSet(const int blockSet) {
0404 
0405     fBlockSet = blockSet;
0406 }
0407 
0408 inline void ComplexTypeInfo::setFinalSet(const int finalSet) {
0409 
0410     fFinalSet = finalSet;
0411 }
0412 
0413 inline void ComplexTypeInfo::setScopeDefined(const unsigned int scopeDefined) {
0414 
0415     fScopeDefined = scopeDefined;
0416 }
0417 
0418 inline void ComplexTypeInfo::setElementId(const unsigned int elemId) {
0419 
0420     fElementId = elemId;
0421 }
0422 
0423 inline void
0424 ComplexTypeInfo::setContentType(const int contentType) {
0425 
0426     fContentType = contentType;
0427 }
0428 
0429 inline void ComplexTypeInfo::setTypeName(const XMLCh* const typeName) {
0430 
0431     fMemoryManager->deallocate(fTypeName);//delete [] fTypeName;
0432     fMemoryManager->deallocate(fTypeLocalName);//delete [] fTypeLocalName;
0433     fMemoryManager->deallocate(fTypeUri);//delete [] fTypeUri;
0434 
0435     if (typeName)
0436     {
0437         fTypeName = XMLString::replicate(typeName, fMemoryManager);
0438 
0439         int index = XMLString::indexOf(fTypeName, chComma);
0440         XMLSize_t length = XMLString::stringLen(fTypeName);
0441         fTypeLocalName = (XMLCh*) fMemoryManager->allocate
0442         (
0443             (length - index + 1) * sizeof(XMLCh)
0444         ); //new XMLCh[length - index + 1];
0445         XMLString::subString(fTypeLocalName, fTypeName, index + 1, length, fMemoryManager);
0446 
0447         fTypeUri = (XMLCh*) fMemoryManager->allocate
0448         (
0449             (index + 1) * sizeof(XMLCh)
0450         ); //new XMLCh[index + 1];
0451         XMLString::subString(fTypeUri, fTypeName, 0, index, fMemoryManager);
0452     }
0453     else
0454     {
0455         fTypeName = fTypeLocalName = fTypeUri = 0;
0456     }
0457 }
0458 
0459 inline void
0460 ComplexTypeInfo::setBaseDatatypeValidator(DatatypeValidator* const validator) {
0461 
0462     fBaseDatatypeValidator = validator;
0463 }
0464 
0465 inline void
0466 ComplexTypeInfo::setDatatypeValidator(DatatypeValidator* const validator) {
0467 
0468     fDatatypeValidator = validator;
0469 }
0470 
0471 inline void
0472 ComplexTypeInfo::setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo) {
0473 
0474     fBaseComplexTypeInfo = typeInfo;
0475 }
0476 
0477 inline void ComplexTypeInfo::addElement(SchemaElementDecl* const elem) {
0478 
0479     if (!fElements) {
0480         fElements = new (fMemoryManager) RefVectorOf<SchemaElementDecl>(8, false, fMemoryManager);
0481     }
0482     else if (fElements->containsElement(elem)) {
0483         return;
0484     }
0485 
0486     fElements->addElement(elem);
0487 }
0488 
0489 inline void ComplexTypeInfo::setAttWildCard(SchemaAttDef* const toAdopt) {
0490 
0491     if (fAttWildCard) {
0492        delete fAttWildCard;
0493     }
0494 
0495     fAttWildCard = toAdopt;
0496 }
0497 
0498 inline void ComplexTypeInfo::setAnonymous() {
0499     fAnonymous = true;
0500 }
0501 
0502 // ---------------------------------------------------------------------------
0503 //  ComplexTypeInfo: Helper methods
0504 // ---------------------------------------------------------------------------
0505 inline bool ComplexTypeInfo::hasAttDefs() const
0506 {
0507     return !fAttDefs->isEmpty();
0508 }
0509 
0510 inline bool ComplexTypeInfo::contains(const XMLCh* const attName) {
0511 
0512     RefHash2KeysTableOfEnumerator<SchemaAttDef> enumDefs(fAttDefs, false, fMemoryManager);
0513 
0514     while (enumDefs.hasMoreElements()) {
0515 
0516         if (XMLString::equals(attName, enumDefs.nextElement().getAttName()->getLocalPart())) {
0517             return true;
0518         }
0519     }
0520 
0521     return false;
0522 }
0523 
0524 XERCES_CPP_NAMESPACE_END
0525 
0526 #endif
0527 
0528 /**
0529   * End of file ComplexTypeInfo.hpp
0530   */
0531