GME  13
SchemaAttDef.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: SchemaAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/framework/XMLElementDecl.hpp>
00027 #include <xercesc/validators/schema/SchemaAttDef.hpp>
00028 
00029 #include <xercesc/internal/XTemplateSerializer.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 // ---------------------------------------------------------------------------
00034 //  SchemaAttDef: Implementation of the XMLAttDef interface
00035 // ---------------------------------------------------------------------------
00036 const XMLCh* SchemaAttDef::getFullName() const
00037 {
00038    return fAttName->getRawName();
00039 }
00040 
00041 // ---------------------------------------------------------------------------
00042 //  SchemaAttDef: Constructors and Destructor
00043 // ---------------------------------------------------------------------------
00044 SchemaAttDef::SchemaAttDef(MemoryManager* const manager) :
00045     XMLAttDef(XMLAttDef::CData, XMLAttDef::Implied, manager)
00046     , fElemId(XMLElementDecl::fgInvalidElemId)
00047     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00048     , fAttName(0)
00049     , fDatatypeValidator(0)
00050     , fNamespaceList(0)
00051     , fBaseAttDecl(0)
00052 {
00053 }
00054 
00055 SchemaAttDef::SchemaAttDef( const XMLCh* const           prefix
00056                           , const XMLCh* const           localPart
00057                           , const int                    uriId
00058                           , const XMLAttDef::AttTypes    type
00059                           , const XMLAttDef::DefAttTypes defType
00060                           , MemoryManager* const         manager) :
00061     XMLAttDef(type, defType, manager)
00062     , fElemId(XMLElementDecl::fgInvalidElemId)
00063     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00064     , fDatatypeValidator(0)
00065     , fNamespaceList(0)
00066     , fBaseAttDecl(0)
00067 {
00068     fAttName = new (manager) QName(prefix, localPart, uriId, manager);
00069 }
00070 
00071 SchemaAttDef::SchemaAttDef( const XMLCh* const           prefix
00072                           , const XMLCh* const           localPart
00073                           , const int                    uriId
00074                           , const XMLCh* const           attValue
00075                           , const XMLAttDef::AttTypes    type
00076                           , const XMLAttDef::DefAttTypes defType
00077                           , const XMLCh* const           enumValues
00078                           , MemoryManager* const         manager) :
00079 
00080     XMLAttDef(attValue, type, defType, enumValues, manager)
00081     , fElemId(XMLElementDecl::fgInvalidElemId)
00082     , fPSVIScope(PSVIDefs::SCP_ABSENT)
00083     , fDatatypeValidator(0)
00084     , fNamespaceList(0)
00085     , fBaseAttDecl(0)
00086 {
00087     fAttName = new (manager) QName(prefix, localPart, uriId, manager);
00088 }
00089 
00090 SchemaAttDef::SchemaAttDef(const SchemaAttDef* other) :
00091 
00092     XMLAttDef(other->getValue(), other->getType(),
00093               other->getDefaultType(), other->getEnumeration(),
00094               other->getMemoryManager())
00095     , fElemId(XMLElementDecl::fgInvalidElemId)
00096     , fPSVIScope(other->fPSVIScope)
00097     , fAttName(0)
00098     , fDatatypeValidator(other->fDatatypeValidator)
00099     , fNamespaceList(0)
00100     , fBaseAttDecl(other->fBaseAttDecl)
00101 {
00102     QName* otherName = other->getAttName();
00103     fAttName = new (getMemoryManager()) QName(otherName->getPrefix(),
00104                          otherName->getLocalPart(), otherName->getURI(),
00105                          getMemoryManager());
00106 
00107     if (other->fNamespaceList && other->fNamespaceList->size()) {
00108         fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*(other->fNamespaceList));
00109     }
00110 }
00111 
00112 SchemaAttDef::~SchemaAttDef()
00113 {
00114    delete fAttName;
00115    delete fNamespaceList;
00116 }
00117 
00118 
00119 // ---------------------------------------------------------------------------
00120 //  SchemaAttDef: Setter methods
00121 // ---------------------------------------------------------------------------
00122 void SchemaAttDef::setAttName(const XMLCh* const        prefix
00123                             , const XMLCh* const        localPart
00124                             , const int                 uriId )
00125 {
00126    fAttName->setName(prefix, localPart, uriId);
00127 }
00128 
00129 /***
00130  * Support for Serialization/De-serialization
00131  ***/
00132 
00133 IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDef)
00134 
00135 void SchemaAttDef::serialize(XSerializeEngine& serEng)
00136 {
00137 
00138     XMLAttDef::serialize(serEng);
00139 
00140     if (serEng.isStoring())
00141     {
00142         serEng.writeSize (fElemId);
00143         serEng<<(int)fPSVIScope;
00144 
00145         serEng<<fAttName;
00146 
00147         DatatypeValidator::storeDV(serEng, fDatatypeValidator);
00148 
00149         /***
00150          * Serialize ValueVectorOf<unsigned int>
00151          ***/
00152         XTemplateSerializer::storeObject(fNamespaceList, serEng);
00153 
00154         serEng<<fBaseAttDecl;
00155     }
00156     else
00157     {
00158 
00159         serEng.readSize (fElemId);
00160         int i;
00161         serEng>>i;
00162         fPSVIScope = (PSVIDefs::PSVIScope)i;
00163 
00164         serEng>>fAttName;
00165 
00166         fDatatypeValidator    = DatatypeValidator::loadDV(serEng);
00167 
00168         /***
00169          * Deserialize ValueVectorOf<unsigned int>
00170          ***/
00171         XTemplateSerializer::loadObject(&fNamespaceList, 8, false, serEng);
00172 
00173         serEng>>fBaseAttDecl;
00174     }
00175 }
00176 
00177 
00178 XERCES_CPP_NAMESPACE_END