GME  13
XSComplexTypeDefinition.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XSComplexTypeDefinition.cpp 594002 2007-11-12 01:05:09Z cargilld $
00020  */
00021 
00022 #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
00023 #include <xercesc/framework/psvi/XSWildcard.hpp>
00024 #include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
00025 #include <xercesc/framework/psvi/XSAttributeUse.hpp>
00026 #include <xercesc/framework/psvi/XSModel.hpp>
00027 #include <xercesc/framework/psvi/XSAnnotation.hpp>
00028 #include <xercesc/framework/psvi/XSParticle.hpp>
00029 #include <xercesc/validators/schema/ComplexTypeInfo.hpp>
00030 #include <xercesc/validators/schema/SchemaElementDecl.hpp>
00031 #include <xercesc/validators/schema/SchemaAttDefList.hpp>
00032 
00033 
00034 XERCES_CPP_NAMESPACE_BEGIN
00035 
00036 // ---------------------------------------------------------------------------
00037 //  XSComplexTypeDefinition: Constructors and Destructor
00038 // ---------------------------------------------------------------------------
00039 XSComplexTypeDefinition::XSComplexTypeDefinition
00040 (
00041     ComplexTypeInfo* const          complexTypeInfo
00042     , XSWildcard* const             xsWildcard
00043     , XSSimpleTypeDefinition* const xsSimpleType
00044     , XSAttributeUseList* const     xsAttList
00045     , XSTypeDefinition* const       xsBaseType
00046     , XSParticle* const             xsParticle
00047     , XSAnnotation* const           headAnnot
00048     , XSModel* const                xsModel
00049     , MemoryManager* const          manager
00050 )
00051     : XSTypeDefinition(COMPLEX_TYPE, xsBaseType, xsModel, manager)
00052     , fComplexTypeInfo(complexTypeInfo)
00053     , fXSWildcard(xsWildcard)
00054     , fXSAttributeUseList(xsAttList)
00055     , fXSSimpleTypeDefinition(xsSimpleType)
00056     , fXSAnnotationList(0)
00057     , fParticle(xsParticle)
00058     , fProhibitedSubstitution(0)
00059 {
00060     int blockset = fComplexTypeInfo->getBlockSet();
00061     if (blockset)
00062     {
00063         if (blockset & SchemaSymbols::XSD_EXTENSION)
00064             fProhibitedSubstitution |= XSConstants::DERIVATION_EXTENSION;
00065 
00066         if (blockset & SchemaSymbols::XSD_RESTRICTION)
00067             fProhibitedSubstitution |= XSConstants::DERIVATION_RESTRICTION;
00068     }
00069 
00070     int finalSet = fComplexTypeInfo->getFinalSet();
00071     if (finalSet)
00072     {
00073         if (finalSet & SchemaSymbols::XSD_EXTENSION)
00074             fFinal |= XSConstants::DERIVATION_EXTENSION;
00075 
00076         if (finalSet & SchemaSymbols::XSD_RESTRICTION)
00077             fFinal |= XSConstants::DERIVATION_RESTRICTION;
00078     }
00079 
00080     if (headAnnot)
00081     {
00082         fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(1, false, manager);
00083         XSAnnotation* annot = headAnnot;
00084 
00085         do
00086         {
00087             fXSAnnotationList->addElement(annot);
00088             annot = annot->getNext();        
00089         } while (annot);
00090     }
00091 }
00092 
00093 XSComplexTypeDefinition::~XSComplexTypeDefinition() 
00094 {
00095     // don't delete fXSWildcard - deleted by XSModel
00096     // don't delete fXSSimpleTypeDefinition - deleted by XSModel
00097     if (fXSAttributeUseList)
00098         delete fXSAttributeUseList;
00099 
00100     if (fXSAnnotationList)
00101         delete fXSAnnotationList;
00102 
00103     if (fParticle)
00104         delete fParticle;
00105 }
00106 
00107 // ---------------------------------------------------------------------------
00108 //  XSComplexTypeDefinition: access methods
00109 // ---------------------------------------------------------------------------
00110 XSConstants::DERIVATION_TYPE XSComplexTypeDefinition::getDerivationMethod() const
00111 {
00112     if(fComplexTypeInfo->getDerivedBy() == SchemaSymbols::XSD_EXTENSION)
00113         return XSConstants::DERIVATION_EXTENSION;    
00114     return XSConstants::DERIVATION_RESTRICTION;
00115 }
00116 
00117 bool XSComplexTypeDefinition::getAbstract() const
00118 {
00119     return fComplexTypeInfo->getAbstract();
00120 }
00121 
00122 
00123 XSComplexTypeDefinition::CONTENT_TYPE XSComplexTypeDefinition::getContentType() const
00124 {
00125     switch(fComplexTypeInfo->getContentType()) {
00126         case SchemaElementDecl::Simple:
00127             return CONTENTTYPE_SIMPLE;
00128         case SchemaElementDecl::Empty:
00129         case SchemaElementDecl::ElementOnlyEmpty:
00130             return CONTENTTYPE_EMPTY;
00131         case SchemaElementDecl::Children:        
00132             return CONTENTTYPE_ELEMENT;
00133         default:
00134             //case SchemaElementDecl::Mixed_Complex:
00135             //case SchemaElementDecl::Mixed_Simple:
00136             //case SchemaElementDecl::Any:
00137             return CONTENTTYPE_MIXED;
00138     }
00139 }
00140 
00141 bool XSComplexTypeDefinition::isProhibitedSubstitution(XSConstants::DERIVATION_TYPE toTest)                                                     
00142 {
00143     if (fProhibitedSubstitution & toTest)
00144         return true;
00145 
00146     return false;
00147 }
00148 
00149 XSAnnotationList *XSComplexTypeDefinition::getAnnotations()
00150 {    
00151     return fXSAnnotationList;
00152 }
00153 
00154 // ---------------------------------------------------------------------------
00155 //  XSComplexTypeDefinition: virtual methods
00156 // ---------------------------------------------------------------------------
00157 const XMLCh *XSComplexTypeDefinition::getName() const
00158 {
00159     return fComplexTypeInfo->getTypeLocalName();
00160 }
00161 
00162 const XMLCh *XSComplexTypeDefinition::getNamespace() 
00163 {
00164     return fComplexTypeInfo->getTypeUri();
00165 }
00166 
00167 XSNamespaceItem *XSComplexTypeDefinition::getNamespaceItem() 
00168 {
00169     return fXSModel->getNamespaceItem(getNamespace());
00170 }
00171 
00172 bool XSComplexTypeDefinition::getAnonymous() const
00173 {
00174     return fComplexTypeInfo->getAnonymous(); 
00175 }
00176 
00177 XSTypeDefinition *XSComplexTypeDefinition::getBaseType() 
00178 {
00179     return fBaseType;
00180 }
00181 
00182 bool XSComplexTypeDefinition::derivedFromType(const XSTypeDefinition * const ancestorType)
00183 {
00184     if (!ancestorType)
00185         return false;
00186 
00187     XSTypeDefinition* type = (XSTypeDefinition*) ancestorType;
00188 
00189     if (ancestorType == type->getBaseType())
00190     {
00191         // ancestor is anytype
00192         return true;
00193     }
00194 
00195     type = this;
00196     XSTypeDefinition* lastType = 0;  // anytype has a basetype of anytype so will have infinite loop...
00197 
00198     while (type && (type != ancestorType) && (type != lastType))
00199     {
00200         lastType = type;
00201         type = type->getBaseType();
00202     }
00203 
00204     return (type == ancestorType);
00205 }
00206 
00207 XERCES_CPP_NAMESPACE_END