GME  13
XMLSchemaDescriptionImpl.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: XMLSchemaDescriptionImpl.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
00027 #include <xercesc/util/QName.hpp>
00028 
00029 #include <xercesc/internal/XTemplateSerializer.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 // ---------------------------------------------------------------------------
00034 //  XMLSchemaDescriptionImpl: constructor and destructor
00035 // ---------------------------------------------------------------------------
00036 XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(const XMLCh* const   targetNamespace
00037                                                  , MemoryManager* const memMgr)
00038 :XMLSchemaDescription(memMgr)
00039 ,fContextType(CONTEXT_UNKNOWN)
00040 ,fNamespace(0)
00041 ,fLocationHints(0)
00042 ,fTriggeringComponent(0)
00043 ,fEnclosingElementName(0)
00044 ,fAttributes(0) 
00045 {
00046     if (targetNamespace)
00047         fNamespace = XMLString::replicate(targetNamespace, memMgr);
00048 
00049 
00050     fLocationHints =  new (memMgr) RefArrayVectorOf<XMLCh>(4, true, memMgr);
00051 
00052     /***
00053         fAttributes
00054     ***/
00055 }
00056 
00057 XMLSchemaDescriptionImpl::~XMLSchemaDescriptionImpl()
00058 {
00059     if (fNamespace)
00060         XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
00061 
00062     if (fLocationHints)
00063         delete fLocationHints;
00064 
00065     if (fTriggeringComponent)
00066         delete fTriggeringComponent;
00067 
00068     if (fEnclosingElementName)
00069         delete fEnclosingElementName;
00070 
00071 }
00072 
00073 const XMLCh* XMLSchemaDescriptionImpl::getGrammarKey() const
00074 { 
00075     return getTargetNamespace(); 
00076 }
00077     
00078 XMLSchemaDescription::ContextType XMLSchemaDescriptionImpl::getContextType() const
00079 {
00080     return fContextType; 
00081 }
00082 
00083 const XMLCh* XMLSchemaDescriptionImpl::getTargetNamespace() const
00084 { 
00085     return fNamespace; 
00086 }
00087 
00088 const RefArrayVectorOf<XMLCh>* XMLSchemaDescriptionImpl::getLocationHints() const
00089 { 
00090     return fLocationHints; 
00091 }
00092 
00093 const QName* XMLSchemaDescriptionImpl::getTriggeringComponent() const                      
00094 { 
00095     return fTriggeringComponent; 
00096 }
00097 
00098 const QName* XMLSchemaDescriptionImpl::getEnclosingElementName() const
00099 { 
00100     return fEnclosingElementName; 
00101 }
00102 
00103 const XMLAttDef* XMLSchemaDescriptionImpl::getAttributes() const                      
00104 { 
00105     return fAttributes; 
00106 }
00107          
00108 void XMLSchemaDescriptionImpl::setContextType(ContextType type)
00109 { 
00110     fContextType = type; 
00111 }
00112 
00113 void XMLSchemaDescriptionImpl::setTargetNamespace(const XMLCh* const newNamespace)
00114 {  
00115     if (fNamespace) {
00116         XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
00117         fNamespace = 0;
00118     }
00119     
00120     fNamespace = XMLString::replicate(newNamespace, XMLGrammarDescription::getMemoryManager()); 
00121 }
00122 
00123 void XMLSchemaDescriptionImpl::setLocationHints(const XMLCh* const hint)
00124 {    
00125     fLocationHints->addElement(XMLString::replicate(hint, XMLGrammarDescription::getMemoryManager())); 
00126 }
00127 
00128 void XMLSchemaDescriptionImpl::setTriggeringComponent(QName* const trigComponent)
00129 { 
00130     if ( fTriggeringComponent) {
00131         delete fTriggeringComponent;
00132         fTriggeringComponent = 0;
00133     }
00134     
00135     fTriggeringComponent = new (trigComponent->getMemoryManager()) QName(*trigComponent); 
00136 
00137 }
00138 
00139 void XMLSchemaDescriptionImpl::setEnclosingElementName(QName* const encElement)
00140 { 
00141     if (fEnclosingElementName) {
00142         delete fEnclosingElementName;
00143         fEnclosingElementName = 0; 
00144     }
00145 
00146     fEnclosingElementName = new (encElement->getMemoryManager()) QName(*encElement); 
00147 
00148 }
00149 
00150 void XMLSchemaDescriptionImpl::setAttributes(XMLAttDef* const attDefs)
00151 { 
00152     // XMLAttDef is part of the grammar that this description refers to
00153     // so we reference to it instead of adopting/owning/cloning.
00154     fAttributes = attDefs; 
00155 }
00156 
00157 /***
00158  * Support for Serialization/De-serialization
00159  ***/
00160 
00161 IMPL_XSERIALIZABLE_TOCREATE(XMLSchemaDescriptionImpl)
00162 
00163 void XMLSchemaDescriptionImpl::serialize(XSerializeEngine& serEng)
00164 {
00165     XMLSchemaDescription::serialize(serEng);
00166 
00167     if (serEng.isStoring())
00168     {
00169         serEng<<(int)fContextType;       
00170         serEng.writeString(fNamespace);
00171 
00172         /***
00173          * 
00174          * Serialize RefArrayVectorOf<XMLCh>*               fLocationHints;
00175          *
00176          ***/
00177         XTemplateSerializer::storeObject(fLocationHints, serEng);
00178 
00179         QName* tempQName = (QName*)fTriggeringComponent;
00180         serEng<<tempQName;
00181         tempQName = (QName*)fEnclosingElementName;
00182         serEng<<tempQName;
00183 
00184         XMLAttDef* tempAttDef = (XMLAttDef*)fAttributes;
00185         serEng<<tempAttDef;
00186     }
00187 
00188     else
00189     {
00190         int i;
00191         serEng>>i;
00192 
00193         fContextType = (ContextType)i;       
00194 
00195         //the original fNamespace which came from the ctor needs deallocated
00196         if (fNamespace)
00197         {
00198             XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
00199         }
00200         serEng.readString((XMLCh*&)fNamespace);
00201 
00202         /***
00203          *
00204          *  Deserialize RefArrayVectorOf<XMLCh>    fLocationHints     
00205          *
00206          ***/
00207         XTemplateSerializer::loadObject(&fLocationHints, 4, true, serEng);
00208 
00209         QName* tempQName;
00210         serEng>>tempQName;
00211         fTriggeringComponent = tempQName;
00212 
00213         serEng>>tempQName;
00214         fEnclosingElementName = tempQName;
00215 
00216         XMLAttDef* tempAttDef;
00217         serEng>>tempAttDef;
00218         fAttributes=tempAttDef;
00219 
00220     }
00221 
00222 }
00223 
00224 XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(MemoryManager* const memMgr)
00225 :XMLSchemaDescription(memMgr)
00226 ,fContextType(CONTEXT_UNKNOWN)
00227 ,fNamespace(0)
00228 ,fLocationHints(0)
00229 ,fTriggeringComponent(0)
00230 ,fEnclosingElementName(0)
00231 ,fAttributes(0) 
00232 {
00233 }
00234 
00235 XERCES_CPP_NAMESPACE_END