GME  13
XSElementDeclaration.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: XSElementDeclaration.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 #include <xercesc/framework/psvi/XSElementDeclaration.hpp>
00023 #include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
00024 #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
00025 #include <xercesc/framework/psvi/XSIDCDefinition.hpp>
00026 #include <xercesc/framework/psvi/XSModel.hpp>
00027 #include <xercesc/validators/schema/SchemaElementDecl.hpp>
00028 #include <xercesc/util/StringPool.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031    
00032 // ---------------------------------------------------------------------------
00033 //  XSElementDeclaration: Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 XSElementDeclaration::XSElementDeclaration
00036 (
00037     SchemaElementDecl* const             schemaElementDecl
00038     , XSTypeDefinition* const            typeDefinition
00039     , XSElementDeclaration* const        substitutionGroupAffiliation
00040     , XSAnnotation* const                annot
00041     , XSNamedMap<XSIDCDefinition>* const identityConstraints
00042     , XSModel* const                     xsModel
00043     , XSConstants::SCOPE                 elemScope
00044     , XSComplexTypeDefinition* const     enclosingTypeDefinition
00045     , MemoryManager* const               manager
00046 )
00047     : XSObject(XSConstants::ELEMENT_DECLARATION, xsModel, manager)
00048     , fDisallowedSubstitutions(0)
00049     , fSubstitutionGroupExclusions(0)
00050     , fScope(elemScope)
00051     , fSchemaElementDecl(schemaElementDecl)
00052     , fTypeDefinition(typeDefinition)
00053     , fEnclosingTypeDefinition(enclosingTypeDefinition)
00054     , fSubstitutionGroupAffiliation(substitutionGroupAffiliation)
00055     , fAnnotation(annot)
00056     , fIdentityConstraints(identityConstraints)
00057 {
00058     // set block and final information
00059     // NOTE: rest of setup will be taken care of in construct()
00060     int blockFinalSet = fSchemaElementDecl->getBlockSet();
00061     if (blockFinalSet) 
00062     {
00063         if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
00064             fDisallowedSubstitutions |= XSConstants::DERIVATION_EXTENSION;
00065 
00066         if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
00067             fDisallowedSubstitutions |= XSConstants::DERIVATION_RESTRICTION;
00068 
00069         if (blockFinalSet & SchemaSymbols::XSD_SUBSTITUTION)
00070             fDisallowedSubstitutions |= XSConstants::DERIVATION_SUBSTITUTION;
00071     }
00072     
00073     if (0 != (blockFinalSet = fSchemaElementDecl->getFinalSet()))
00074     {
00075         if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
00076             fSubstitutionGroupExclusions |= XSConstants::DERIVATION_EXTENSION;
00077 
00078         if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
00079             fSubstitutionGroupExclusions |= XSConstants::DERIVATION_RESTRICTION;
00080     }
00081 }
00082 
00083 XSElementDeclaration::~XSElementDeclaration() 
00084 {
00085     // don't delete fTypeDefinition - deleted by XSModel
00086     // don't delete fSubstitutionGroupAffiliation - deleted by XSModel
00087     if (fIdentityConstraints)
00088         delete fIdentityConstraints;
00089 }
00090 
00091 // ---------------------------------------------------------------------------
00092 //  XSElementDeclaration: XSObject virtual methods
00093 // ---------------------------------------------------------------------------
00094 const XMLCh *XSElementDeclaration::getName() const
00095 {
00096     return fSchemaElementDecl->getElementName()->getLocalPart();
00097 }
00098 
00099 const XMLCh *XSElementDeclaration::getNamespace() 
00100 {
00101     return fXSModel->getURIStringPool()->getValueForId(fSchemaElementDecl->getURI());
00102 }
00103 
00104 XSNamespaceItem *XSElementDeclaration::getNamespaceItem() 
00105 {
00106     return fXSModel->getNamespaceItem(getNamespace());
00107 }
00108 
00109 
00110 // ---------------------------------------------------------------------------
00111 //  XSElementDeclaration: access methods
00112 // ---------------------------------------------------------------------------
00113 XSConstants::VALUE_CONSTRAINT XSElementDeclaration::getConstraintType() const
00114 {
00115     if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_FIXED)
00116         return XSConstants::VALUE_CONSTRAINT_FIXED;
00117 
00118     if (fSchemaElementDecl->getDefaultValue())
00119         return XSConstants::VALUE_CONSTRAINT_DEFAULT;
00120 
00121     return XSConstants::VALUE_CONSTRAINT_NONE;
00122 }
00123 
00124 const XMLCh *XSElementDeclaration::getConstraintValue()
00125 {
00126     return fSchemaElementDecl->getDefaultValue();
00127 }
00128 
00129 bool XSElementDeclaration::getNillable() const
00130 {
00131     if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_NILLABLE)
00132         return true;
00133 
00134     return false;
00135 }
00136 
00137 bool XSElementDeclaration::isSubstitutionGroupExclusion(XSConstants::DERIVATION_TYPE exclusion)
00138 {
00139     if (fSubstitutionGroupExclusions & exclusion)
00140         return true;
00141 
00142     return false;
00143 }
00144 
00145 
00146 bool XSElementDeclaration::isDisallowedSubstitution(XSConstants::DERIVATION_TYPE disallowed)
00147 {
00148     if (fDisallowedSubstitutions & disallowed)
00149         return true;
00150 
00151     return false;
00152 }
00153 
00154 
00155 bool XSElementDeclaration::getAbstract() const
00156 {
00157     if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_ABSTRACT)
00158         return true;
00159 
00160     return false;
00161 }
00162 
00163 XERCES_CPP_NAMESPACE_END