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: VecAttributesImpl.cpp 672311 2008-06-27 16:05:01Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/util/Janitor.hpp> 00027 #include <xercesc/internal/VecAttributesImpl.hpp> 00028 00029 XERCES_CPP_NAMESPACE_BEGIN 00030 00031 // --------------------------------------------------------------------------- 00032 // Constructors and Destructor 00033 // --------------------------------------------------------------------------- 00034 VecAttributesImpl::VecAttributesImpl() : 00035 00036 fAdopt(false) 00037 , fCount(0) 00038 , fVector(0) 00039 , fScanner(0) 00040 { 00041 } 00042 00043 VecAttributesImpl::~VecAttributesImpl() 00044 { 00045 // 00046 // Note that some compilers can't deal with the fact that the pointer 00047 // is to a const object, so we have to cast off the const'ness here! 00048 // 00049 if (fAdopt) 00050 delete (RefVectorOf<XMLAttr>*)fVector; 00051 } 00052 00053 00054 // --------------------------------------------------------------------------- 00055 // Implementation of the attribute list interface 00056 // --------------------------------------------------------------------------- 00057 XMLSize_t VecAttributesImpl::getLength() const 00058 { 00059 return fCount; 00060 } 00061 00062 const XMLCh* VecAttributesImpl::getURI(const XMLSize_t index) const 00063 { 00064 // since this func really needs to be const, like the rest, not sure how we 00065 // make it const and re-use the fURIBuffer member variable. we're currently 00066 // creating a buffer each time you need a URI. there has to be a better 00067 // way to do this... 00068 00069 //XMLBuffer tempBuf; 00070 if (index >= fCount) { 00071 00072 00073 return 0; 00074 } 00075 //fValidator->getURIText(fVector->elementAt(index)->getURIId(), tempBuf) ; 00076 //return tempBuf.getRawBuffer() ; 00077 return fScanner->getURIText(fVector->elementAt(index)->getURIId()); 00078 } 00079 00080 const XMLCh* VecAttributesImpl::getLocalName(const XMLSize_t index) const 00081 { 00082 if (index >= fCount) { 00083 return 0; 00084 } 00085 return fVector->elementAt(index)->getName(); 00086 } 00087 00088 const XMLCh* VecAttributesImpl::getQName(const XMLSize_t index) const 00089 { 00090 if (index >= fCount) { 00091 return 0; 00092 } 00093 return fVector->elementAt(index)->getQName(); 00094 } 00095 00096 const XMLCh* VecAttributesImpl::getType(const XMLSize_t index) const 00097 { 00098 if (index >= fCount) { 00099 return 0; 00100 } 00101 return XMLAttDef::getAttTypeString(fVector->elementAt(index)->getType(), fVector->getMemoryManager()); 00102 } 00103 00104 const XMLCh* VecAttributesImpl::getValue(const XMLSize_t index) const 00105 { 00106 if (index >= fCount) { 00107 return 0; 00108 } 00109 return fVector->elementAt(index)->getValue(); 00110 } 00111 00112 bool VecAttributesImpl::getIndex(const XMLCh* const uri, 00113 const XMLCh* const localPart, 00114 XMLSize_t& index) const 00115 { 00116 // 00117 // Search the vector for the attribute with the given name and return 00118 // its type. 00119 // 00120 XMLBuffer uriBuffer(1023, fVector->getMemoryManager()) ; 00121 for (index = 0; index < fCount; index++) 00122 { 00123 const XMLAttr* curElem = fVector->elementAt(index); 00124 00125 fScanner->getURIText(curElem->getURIId(), uriBuffer) ; 00126 00127 if ( (XMLString::equals(curElem->getName(), localPart)) && 00128 (XMLString::equals(uriBuffer.getRawBuffer(), uri)) ) 00129 return true; 00130 } 00131 return false; 00132 } 00133 00134 int VecAttributesImpl::getIndex(const XMLCh* const uri, const XMLCh* const localPart ) const 00135 { 00136 // 00137 // Search the vector for the attribute with the given name and return 00138 // its type. 00139 // 00140 XMLBuffer uriBuffer(1023, fVector->getMemoryManager()) ; 00141 for (XMLSize_t index = 0; index < fCount; index++) 00142 { 00143 const XMLAttr* curElem = fVector->elementAt(index); 00144 00145 fScanner->getURIText(curElem->getURIId(), uriBuffer) ; 00146 00147 if ( (XMLString::equals(curElem->getName(), localPart)) && 00148 (XMLString::equals(uriBuffer.getRawBuffer(), uri)) ) 00149 return (int)index ; 00150 } 00151 return -1; 00152 } 00153 00154 bool VecAttributesImpl::getIndex(const XMLCh* const qName, 00155 XMLSize_t& index) const 00156 { 00157 // 00158 // Search the vector for the attribute with the given name and return 00159 // its type. 00160 // 00161 for (index = 0; index < fCount; index++) 00162 { 00163 const XMLAttr* curElem = fVector->elementAt(index); 00164 00165 if (XMLString::equals(curElem->getQName(), qName)) 00166 return true; 00167 } 00168 return false; 00169 } 00170 00171 int VecAttributesImpl::getIndex(const XMLCh* const qName ) const 00172 { 00173 // 00174 // Search the vector for the attribute with the given name and return 00175 // its type. 00176 // 00177 for (XMLSize_t index = 0; index < fCount; index++) 00178 { 00179 const XMLAttr* curElem = fVector->elementAt(index); 00180 00181 if (XMLString::equals(curElem->getQName(), qName)) 00182 return (int)index ; 00183 } 00184 return -1; 00185 } 00186 00187 const XMLCh* VecAttributesImpl::getType(const XMLCh* const uri, const XMLCh* const localPart ) const 00188 { 00189 XMLSize_t i; 00190 00191 if (getIndex(uri, localPart, i)) 00192 return getType(i); 00193 else 00194 return 0; 00195 } 00196 00197 const XMLCh* VecAttributesImpl::getType(const XMLCh* const qName) const 00198 { 00199 XMLSize_t i; 00200 00201 if (getIndex(qName, i)) 00202 return getType(i); 00203 else 00204 return 0; 00205 } 00206 00207 const XMLCh* VecAttributesImpl::getValue(const XMLCh* const uri, const XMLCh* const localPart ) const 00208 { 00209 XMLSize_t i; 00210 00211 if (getIndex(uri, localPart, i)) 00212 return getValue(i); 00213 else 00214 return 0; 00215 } 00216 00217 const XMLCh* VecAttributesImpl::getValue(const XMLCh* const qName) const 00218 { 00219 XMLSize_t i; 00220 00221 if (getIndex(qName, i)) 00222 return getValue(i); 00223 else 00224 return 0; 00225 } 00226 00227 // --------------------------------------------------------------------------- 00228 // Setter methods 00229 // --------------------------------------------------------------------------- 00230 void VecAttributesImpl::setVector(const RefVectorOf<XMLAttr>* const srcVec 00231 , const XMLSize_t count 00232 , const XMLScanner * const scanner 00233 , const bool adopt) 00234 { 00235 // 00236 // Delete the previous vector (if any) if we are adopting. Note that some 00237 // compilers can't deal with the fact that the pointer is to a const 00238 // object, so we have to cast off the const'ness here! 00239 // 00240 if (fAdopt) 00241 delete (RefVectorOf<XMLAttr>*)fVector; 00242 00243 fAdopt = adopt; 00244 fCount = count; 00245 fVector = srcVec; 00246 fScanner = scanner ; 00247 } 00248 00249 XERCES_CPP_NAMESPACE_END