GME
13
|
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: DTDAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/validators/DTD/DTDAttDefList.hpp> 00027 #include <xercesc/internal/XTemplateSerializer.hpp> 00028 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> 00029 00030 XERCES_CPP_NAMESPACE_BEGIN 00031 00032 // --------------------------------------------------------------------------- 00033 // DTDAttDefList: Constructors and Destructor 00034 // --------------------------------------------------------------------------- 00035 DTDAttDefList::DTDAttDefList(RefHashTableOf<DTDAttDef>* const listToUse, MemoryManager* const manager) 00036 : XMLAttDefList(manager) 00037 ,fEnum(0) 00038 ,fList(listToUse) 00039 ,fArray(0) 00040 ,fSize(0) 00041 ,fCount(0) 00042 { 00043 fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(listToUse, false, manager); 00044 fArray = (DTDAttDef **)(manager->allocate( sizeof(DTDAttDef*) << 1)); 00045 fSize = 2; 00046 } 00047 00048 DTDAttDefList::~DTDAttDefList() 00049 { 00050 delete fEnum; 00051 (getMemoryManager())->deallocate(fArray); 00052 } 00053 00054 00055 // --------------------------------------------------------------------------- 00056 // DTDAttDefList: Implementation of the virtual interface 00057 // --------------------------------------------------------------------------- 00058 00059 bool DTDAttDefList::isEmpty() const 00060 { 00061 return fList->isEmpty(); 00062 } 00063 00064 00065 XMLAttDef* DTDAttDefList::findAttDef(const unsigned int 00066 , const XMLCh* const attName) 00067 { 00068 // We don't use the URI, so we just look up the name 00069 return fList->get(attName); 00070 } 00071 00072 00073 const XMLAttDef* 00074 DTDAttDefList::findAttDef( const unsigned int 00075 , const XMLCh* const attName) const 00076 { 00077 // We don't use the URI, so we just look up the name 00078 return fList->get(attName); 00079 } 00080 00081 00082 XMLAttDef* DTDAttDefList::findAttDef( const XMLCh* const 00083 , const XMLCh* const attName) 00084 { 00085 // We don't use the URI, so we just look up the name 00086 return fList->get(attName); 00087 } 00088 00089 00090 const XMLAttDef* 00091 DTDAttDefList::findAttDef( const XMLCh* const 00092 , const XMLCh* const attName) const 00093 { 00094 // We don't use the URI, so we just look up the name 00095 return fList->get(attName); 00096 } 00097 00101 XMLSize_t DTDAttDefList::getAttDefCount() const 00102 { 00103 return fCount; 00104 } 00105 00109 XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index) 00110 { 00111 if(index >= fCount) 00112 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager()); 00113 return *(fArray[index]); 00114 } 00115 00119 const XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index) const 00120 { 00121 if(index >= fCount) 00122 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager()); 00123 return *(fArray[index]); 00124 } 00125 00126 /*** 00127 * Support for Serialization/De-serialization 00128 ***/ 00129 00130 IMPL_XSERIALIZABLE_TOCREATE(DTDAttDefList) 00131 00132 void DTDAttDefList::serialize(XSerializeEngine& serEng) 00133 { 00134 00135 XMLAttDefList::serialize(serEng); 00136 00137 if (serEng.isStoring()) 00138 { 00139 /*** 00140 * 00141 * Serialize RefHashTableOf<DTDAttDef> 00142 * 00143 ***/ 00144 XTemplateSerializer::storeObject(fList, serEng); 00145 serEng.writeSize (fCount); 00146 00147 // do not serialize fEnum 00148 } 00149 else 00150 { 00151 /*** 00152 * 00153 * Deserialize RefHashTableOf<DTDAttDef> 00154 * 00155 ***/ 00156 XTemplateSerializer::loadObject(&fList, 29, true, serEng); 00157 // assume empty so we can size fArray just right 00158 serEng.readSize (fSize); 00159 if (!fEnum && fList) 00160 { 00161 fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(fList, false, getMemoryManager()); 00162 } 00163 if(fSize) 00164 { 00165 (getMemoryManager())->deallocate(fArray); 00166 fArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize)); 00167 fCount = 0; 00168 while(fEnum->hasMoreElements()) 00169 { 00170 fArray[fCount++] = &fEnum->nextElement(); 00171 } 00172 } 00173 } 00174 00175 } 00176 00177 00178 DTDAttDefList::DTDAttDefList(MemoryManager* const manager) 00179 : XMLAttDefList(manager) 00180 ,fEnum(0) 00181 ,fList(0) 00182 ,fArray(0) 00183 ,fSize(0) 00184 ,fCount(0) 00185 { 00186 } 00187 00188 XERCES_CPP_NAMESPACE_END