GME  13
SchemaElementDecl.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: SchemaElementDecl.cpp 609971 2008-01-08 13:30:47Z amassari $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/util/XMLString.hpp>
00027 #include <xercesc/util/XMLUniDefs.hpp>
00028 #include <xercesc/util/XMLUni.hpp>
00029 #include <xercesc/validators/schema/SchemaAttDefList.hpp>
00030 #include <xercesc/validators/schema/SchemaElementDecl.hpp>
00031 #include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
00032 
00033 #include <xercesc/internal/XTemplateSerializer.hpp>
00034 
00035 XERCES_CPP_NAMESPACE_BEGIN
00036 
00037 // ---------------------------------------------------------------------------
00038 //  SchemaElementDecl: Constructors and Destructor
00039 // ---------------------------------------------------------------------------
00040 SchemaElementDecl::SchemaElementDecl(MemoryManager* const manager) :
00041     XMLElementDecl(manager)
00042     , fModelType(Any)
00043     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00044     , fEnclosingScope(Grammar::TOP_LEVEL_SCOPE)
00045     , fFinalSet(0)
00046     , fBlockSet(0)    
00047     , fMiscFlags(0)
00048     , fDefaultValue(0)
00049     , fComplexTypeInfo(0)
00050     , fAttDefs(0)        
00051     , fIdentityConstraints(0)
00052     , fAttWildCard(0)
00053     , fSubstitutionGroupElem(0)
00054     , fDatatypeValidator(0)    
00055 {
00056 }
00057 
00058 SchemaElementDecl::SchemaElementDecl(const XMLCh* const                  prefix
00059                                    , const XMLCh* const                  localPart
00060                                    , const int                           uriId
00061                                    , const SchemaElementDecl::ModelTypes type
00062                                    , const unsigned int                  enclosingScope
00063                                    , MemoryManager* const                manager) :
00064     XMLElementDecl(manager)
00065     , fModelType(type)
00066     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00067     , fEnclosingScope(enclosingScope)
00068     , fFinalSet(0)
00069     , fBlockSet(0)    
00070     , fMiscFlags(0)
00071     , fDefaultValue(0)
00072     , fComplexTypeInfo(0)
00073     , fAttDefs(0)          
00074     , fIdentityConstraints(0)
00075     , fAttWildCard(0)
00076     , fSubstitutionGroupElem(0)
00077     , fDatatypeValidator(0)
00078 {
00079     setElementName(prefix, localPart, uriId);
00080 }
00081 
00082 SchemaElementDecl::SchemaElementDecl(const QName* const                  elementName
00083                                    , const SchemaElementDecl::ModelTypes type
00084                                    , const unsigned int                  enclosingScope
00085                                    , MemoryManager* const                manager) :
00086     XMLElementDecl(manager)
00087     , fModelType(type)
00088     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00089     , fEnclosingScope(enclosingScope)
00090     , fFinalSet(0)
00091     , fBlockSet(0)    
00092     , fMiscFlags(0)
00093     , fDefaultValue(0)
00094     , fComplexTypeInfo(0)
00095     , fAttDefs(0)        
00096     , fIdentityConstraints(0)
00097     , fAttWildCard(0)
00098     , fSubstitutionGroupElem(0)
00099     , fDatatypeValidator(0)
00100 {
00101     setElementName(elementName);
00102 }
00103 
00104 SchemaElementDecl::~SchemaElementDecl()
00105 {
00106     getMemoryManager()->deallocate(fDefaultValue);//delete [] fDefaultValue;
00107     delete fAttDefs;
00108     delete fIdentityConstraints;
00109     delete fAttWildCard;
00110 }
00111 
00112 
00113 // ---------------------------------------------------------------------------
00114 //  SchemaElementDecl: XMLElementDecl virtual interface implementation
00115 // ---------------------------------------------------------------------------
00116 XMLAttDefList& SchemaElementDecl::getAttDefList() const
00117 {
00118     if (!fComplexTypeInfo)
00119         {
00120         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::DV_InvalidOperation, getMemoryManager());
00121     }
00122 
00123         return fComplexTypeInfo->getAttDefList();
00124 }
00125 
00126 
00127 XMLElementDecl::CharDataOpts SchemaElementDecl::getCharDataOpts() const
00128 {
00129     SchemaElementDecl::ModelTypes modelType = fModelType;
00130 
00131     if (fComplexTypeInfo) {
00132         modelType = (SchemaElementDecl::ModelTypes) fComplexTypeInfo->getContentType();
00133     }
00134 
00135     XMLElementDecl::CharDataOpts retVal;
00136     switch(modelType)
00137     {
00138         case Children :
00139         case ElementOnlyEmpty :
00140             retVal = XMLElementDecl::SpacesOk;
00141             break;
00142 
00143         case Empty :
00144             retVal = XMLElementDecl::NoCharData;
00145             break;
00146 
00147         default :
00148             retVal = XMLElementDecl::AllCharData;
00149             break;
00150     }
00151     return retVal;
00152 }
00153 
00154 
00155 bool SchemaElementDecl::hasAttDefs() const
00156 {
00157     if (fComplexTypeInfo) {
00158         return fComplexTypeInfo->hasAttDefs();
00159     }
00160 
00161     // If the collection hasn't been faulted in, then no att defs
00162     return false;
00163 
00164 }
00165 
00166 const XMLCh*
00167 SchemaElementDecl::getFormattedContentModel() const
00168 {
00169     if (fComplexTypeInfo) {
00170         return fComplexTypeInfo->getFormattedContentModel();
00171     }
00172     return 0;
00173 }
00174 
00175 // ---------------------------------------------------------------------------
00176 //  SchemaElementDecl: Getter methods
00177 // ---------------------------------------------------------------------------
00178 const SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId) const
00179 {
00180     if (fComplexTypeInfo) {
00181         return fComplexTypeInfo->getAttDef(baseName, uriId);
00182     }
00183 
00184     // If no complex type, then return a null
00185     return 0;
00186 
00187 }
00188 
00189 SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId)
00190 {
00191     if (fComplexTypeInfo) {
00192         return fComplexTypeInfo->getAttDef(baseName, uriId);
00193     }
00194 
00195     // If no complex type, then return a null
00196     return 0;
00197 }
00198 
00199 /***
00200  * Support for Serialization/De-serialization
00201  ***/
00202 
00203 IMPL_XSERIALIZABLE_TOCREATE(SchemaElementDecl)
00204 
00205 void SchemaElementDecl::serialize(XSerializeEngine& serEng)
00206 {
00207 
00208     XMLElementDecl::serialize(serEng);
00209 
00210     if (serEng.isStoring())
00211     {
00212         serEng<<(int)fModelType;
00213         serEng<<(int)fPSVIScope;        
00214 
00215         serEng<<fEnclosingScope;
00216         serEng<<fFinalSet;
00217         serEng<<fBlockSet;
00218         serEng<<fMiscFlags;
00219 
00220         serEng.writeString(fDefaultValue);
00221 
00222         serEng<<fComplexTypeInfo;
00223 
00224         /***
00225          * Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
00226          ***/
00227 
00228         XTemplateSerializer::storeObject(fAttDefs, serEng);        
00229         
00230         /***
00231          * Serialize RefVectorOf<IdentityConstraint>*   fIdentityConstraints;
00232          ***/
00233         XTemplateSerializer::storeObject(fIdentityConstraints, serEng);
00234 
00235         serEng<<fAttWildCard;
00236         serEng<<fSubstitutionGroupElem;
00237         DatatypeValidator::storeDV(serEng, fDatatypeValidator);                
00238     }
00239     else
00240     {
00241         int i;
00242         serEng>>i;
00243         fModelType = (ModelTypes)i;
00244         serEng>>i;
00245         fPSVIScope = (PSVIDefs::PSVIScope)i;   
00246 
00247         serEng>>fEnclosingScope;
00248         serEng>>fFinalSet;
00249         serEng>>fBlockSet;
00250         serEng>>fMiscFlags;
00251 
00252         serEng.readString(fDefaultValue);
00253 
00254         serEng>>fComplexTypeInfo;
00255 
00256         /***
00257          * DeSerialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
00258          ***/
00259         XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);                
00260 
00261         /***
00262          * DeSerialize RefVectorOf<IdentityConstraint>*   fIdentityConstraints;
00263          ***/
00264         XTemplateSerializer::loadObject(&fIdentityConstraints, 16, true, serEng);
00265 
00266         serEng>>fAttWildCard;
00267         serEng>>fSubstitutionGroupElem;
00268         fDatatypeValidator = DatatypeValidator::loadDV(serEng);
00269     }
00270 }
00271 
00272 XMLElementDecl::objectType  SchemaElementDecl::getObjectType() const
00273 {
00274     return Schema;
00275 }
00276 
00277 XERCES_CPP_NAMESPACE_END