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: SchemaAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/validators/schema/SchemaAttDefList.hpp> 00027 00028 #include <xercesc/internal/XTemplateSerializer.hpp> 00029 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> 00030 00031 XERCES_CPP_NAMESPACE_BEGIN 00032 00033 // --------------------------------------------------------------------------- 00034 // SchemaAttDefList: Constructors and Destructor 00035 // --------------------------------------------------------------------------- 00036 SchemaAttDefList::SchemaAttDefList(RefHash2KeysTableOf<SchemaAttDef>* const listToUse, MemoryManager* const manager) 00037 : XMLAttDefList(manager) 00038 ,fEnum(0) 00039 ,fList(listToUse) 00040 ,fArray(0) 00041 ,fSize(0) 00042 ,fCount(0) 00043 { 00044 fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(listToUse, false, getMemoryManager()); 00045 fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) << 1)); 00046 fSize = 2; 00047 } 00048 00049 SchemaAttDefList::~SchemaAttDefList() 00050 { 00051 delete fEnum; 00052 (getMemoryManager())->deallocate(fArray); 00053 } 00054 00055 00056 // --------------------------------------------------------------------------- 00057 // SchemaAttDefList: Implementation of the virtual interface 00058 // --------------------------------------------------------------------------- 00059 00060 bool SchemaAttDefList::isEmpty() const 00061 { 00062 return fList->isEmpty(); 00063 } 00064 00065 00066 XMLAttDef* SchemaAttDefList::findAttDef(const unsigned int uriID 00067 , const XMLCh* const attName) 00068 { 00069 const int colonInd = XMLString::indexOf(attName, chColon); 00070 00071 // An index of 0 is really an error, but the QName class doesn't check for 00072 // that case either... 00073 const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName; 00074 00075 return fList->get((void*)localPart, uriID); 00076 } 00077 00078 00079 const XMLAttDef* 00080 SchemaAttDefList::findAttDef( const unsigned int uriID 00081 , const XMLCh* const attName) const 00082 { 00083 const int colonInd = XMLString::indexOf(attName, chColon); 00084 00085 // An index of 0 is really an error, but the QName class doesn't check for 00086 // that case either... 00087 const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName; 00088 00089 return fList->get((void*)localPart, uriID); 00090 } 00091 00092 00093 XMLAttDef* SchemaAttDefList::findAttDef( const XMLCh* const 00094 , const XMLCh* const) 00095 { 00096 //need numeric URI id to locate the attribute, that's how it was stored 00097 ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager()); 00098 return 0; 00099 } 00100 00101 00102 const XMLAttDef* 00103 SchemaAttDefList::findAttDef( const XMLCh* const 00104 , const XMLCh* const) const 00105 { 00106 //need numeric URI id to locate the attribute, that's how it was stored 00107 ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager()); 00108 return 0; 00109 } 00110 00114 XMLSize_t SchemaAttDefList::getAttDefCount() const 00115 { 00116 return fCount; 00117 } 00118 00122 XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index) 00123 { 00124 if(index >= fCount) 00125 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager()); 00126 return *(fArray[index]); 00127 } 00128 00132 const XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index) const 00133 { 00134 if(index >= fCount) 00135 ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager()); 00136 return *(fArray[index]); 00137 } 00138 00139 /*** 00140 * Support for Serialization/De-serialization 00141 ***/ 00142 00143 IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDefList) 00144 00145 void SchemaAttDefList::serialize(XSerializeEngine& serEng) 00146 { 00147 00148 XMLAttDefList::serialize(serEng); 00149 00150 if (serEng.isStoring()) 00151 { 00152 /*** 00153 * 00154 * Serialize RefHash2KeysTableOf<SchemaAttDef> 00155 * 00156 ***/ 00157 XTemplateSerializer::storeObject(fList, serEng); 00158 serEng.writeSize (fCount); 00159 00160 // do not serialize fEnum 00161 } 00162 else 00163 { 00164 /*** 00165 * 00166 * Deserialize RefHash2KeysTableOf<SchemaAttDef> 00167 * 00168 ***/ 00169 XTemplateSerializer::loadObject(&fList, 29, true, serEng); 00170 00171 // assume empty so we can size fArray just right 00172 serEng.readSize (fSize); 00173 if (!fEnum && fList) 00174 { 00175 fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(fList, false, getMemoryManager()); 00176 } 00177 if(fSize) 00178 { 00179 (getMemoryManager())->deallocate(fArray); 00180 fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize)); 00181 fCount = 0; 00182 while(fEnum->hasMoreElements()) 00183 { 00184 fArray[fCount++] = &fEnum->nextElement(); 00185 } 00186 } 00187 } 00188 00189 } 00190 00191 SchemaAttDefList::SchemaAttDefList(MemoryManager* const manager) 00192 : XMLAttDefList(manager) 00193 ,fEnum(0) 00194 ,fList(0) 00195 ,fArray(0) 00196 ,fSize(0) 00197 ,fCount(0) 00198 { 00199 } 00200 00201 XERCES_CPP_NAMESPACE_END