GME  13
XercesAttGroupInfo.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: XercesAttGroupInfo.cpp 676911 2008-07-15 13:27:32Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
00026 #include <xercesc/util/QName.hpp>
00027 
00028 #include <xercesc/internal/XTemplateSerializer.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  XercesAttGroupInfo: Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 XercesAttGroupInfo::XercesAttGroupInfo(MemoryManager* const manager)
00036     : fTypeWithId(false)
00037     , fNameId(0)
00038     , fNamespaceId(0)
00039     , fAttributes(0)
00040     , fAnyAttributes(0)
00041     , fCompleteWildCard(0)
00042     , fMemoryManager(manager)
00043 {
00044 
00045 }
00046 
00047 XercesAttGroupInfo::XercesAttGroupInfo(unsigned int attGroupNameId,
00048                                        unsigned int attGroupNamespaceId,
00049                                        MemoryManager* const manager)
00050     : fTypeWithId(false)
00051     , fNameId(attGroupNameId)
00052     , fNamespaceId(attGroupNamespaceId)
00053     , fAttributes(0)
00054     , fAnyAttributes(0)
00055     , fCompleteWildCard(0)
00056     , fMemoryManager(manager)
00057 {
00058 
00059 }
00060 
00061 XercesAttGroupInfo::~XercesAttGroupInfo()
00062 {
00063     delete fAttributes;
00064     delete fAnyAttributes;
00065     delete fCompleteWildCard;
00066 }
00067 
00068 bool XercesAttGroupInfo::containsAttribute(const XMLCh* const name,
00069                                            const unsigned int uri) {
00070 
00071     if (fAttributes) {
00072 
00073         XMLSize_t attCount = fAttributes->size();
00074 
00075         if (attCount) {
00076 
00077             for (XMLSize_t i=0; i < attCount; i++) {
00078 
00079                 QName* attName = fAttributes->elementAt(i)->getAttName();
00080 
00081                 if (attName->getURI() == uri &&
00082                     XMLString::equals(attName->getLocalPart(),name)) {
00083                     return true;
00084                 }
00085             }
00086         }
00087     }
00088 
00089     return false;
00090 }
00091 
00092 // ---------------------------------------------------------------------------
00093 //  XercesAttGroupInfo: Getter methods
00094 // ---------------------------------------------------------------------------
00095 const SchemaAttDef* XercesAttGroupInfo::getAttDef(const XMLCh* const baseName,
00096                                                   const int uriId) const {
00097 
00098     // If no list, then return a null
00099     if (!fAttributes)
00100         return 0;
00101 
00102     XMLSize_t attSize = fAttributes->size();
00103 
00104     for (XMLSize_t i=0; i<attSize; i++) {
00105 
00106         const SchemaAttDef* attDef = fAttributes->elementAt(i);
00107         QName* attName = attDef->getAttName();
00108 
00109         if (uriId == (int) attName->getURI() &&
00110                         XMLString::equals(baseName, attName->getLocalPart())) {
00111 
00112             return attDef;
00113         }
00114     }
00115 
00116     return 0;
00117 }
00118 
00119 /***
00120  * Support for Serialization/De-serialization
00121  ***/
00122 
00123 IMPL_XSERIALIZABLE_TOCREATE(XercesAttGroupInfo)
00124 
00125 void XercesAttGroupInfo::serialize(XSerializeEngine& serEng)
00126 {
00127 
00128     if (serEng.isStoring())
00129     {
00130         serEng<<fTypeWithId;
00131         serEng<<fNameId;
00132         serEng<<fNamespaceId;
00133 
00134         /***
00135          *
00136          * Serialize RefVectorOf<SchemaAttDef>* fAttributes;
00137          *
00138          ***/
00139         XTemplateSerializer::storeObject(fAttributes, serEng);
00140 
00141         /***
00142          *
00143          * Serialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
00144          *
00145          ***/
00146         XTemplateSerializer::storeObject(fAnyAttributes, serEng);
00147 
00148         serEng<<fCompleteWildCard;
00149     }
00150     else
00151     {
00152         serEng>>fTypeWithId;
00153         serEng>>fNameId;
00154         serEng>>fNamespaceId;
00155 
00156         /***
00157          *
00158          * Deserialize RefVectorOf<SchemaAttDef>* fAttributes;
00159          *
00160          ***/
00161         XTemplateSerializer::loadObject(&fAttributes, 4, true, serEng);
00162 
00163         /***
00164          *
00165          * Deserialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
00166          *
00167          ***/
00168 
00169         XTemplateSerializer::loadObject(&fAnyAttributes, 2, true, serEng);
00170 
00171         serEng>>fCompleteWildCard;
00172     }
00173 
00174 }
00175 
00176 XERCES_CPP_NAMESPACE_END
00177