GME  13
VecAttrListImpl.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: VecAttrListImpl.cpp 672273 2008-06-27 13:57:00Z borisk $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/util/Janitor.hpp>
00027 #include <xercesc/internal/VecAttrListImpl.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 // ---------------------------------------------------------------------------
00032 //  Constructors and Destructor
00033 // ---------------------------------------------------------------------------
00034 VecAttrListImpl::VecAttrListImpl() :
00035 
00036     fAdopt(false)
00037     , fCount(0)
00038     , fVector(0)
00039 {
00040 }
00041 
00042 VecAttrListImpl::~VecAttrListImpl()
00043 {
00044     //
00045     //  Note that some compilers can't deal with the fact that the pointer
00046     //  is to a const object, so we have to cast off the const'ness here!
00047     //
00048     if (fAdopt)
00049         delete (RefVectorOf<XMLAttr>*)fVector;
00050 }
00051 
00052 
00053 // ---------------------------------------------------------------------------
00054 //  Implementation of the attribute list interface
00055 // ---------------------------------------------------------------------------
00056 XMLSize_t VecAttrListImpl::getLength() const
00057 {
00058     return fCount;
00059 }
00060 
00061 const XMLCh* VecAttrListImpl::getName(const XMLSize_t index) const
00062 {
00063     if (index >= fCount) {
00064         return 0;
00065     }
00066     return fVector->elementAt(index)->getQName();
00067 }
00068 
00069 const XMLCh* VecAttrListImpl::getType(const XMLSize_t index) const
00070 {
00071     if (index >= fCount) {
00072         return 0;
00073     }
00074     return XMLAttDef::getAttTypeString(fVector->elementAt(index)->getType(), fVector->getMemoryManager());
00075 }
00076 
00077 const XMLCh* VecAttrListImpl::getValue(const XMLSize_t index) const
00078 {
00079     if (index >= fCount) {
00080         return 0;
00081     }
00082     return fVector->elementAt(index)->getValue();
00083 }
00084 
00085 const XMLCh* VecAttrListImpl::getType(const XMLCh* const name) const
00086 {
00087     //
00088     //  Search the vector for the attribute with the given name and return
00089     //  its type.
00090     //
00091     for (XMLSize_t index = 0; index < fCount; index++)
00092     {
00093         const XMLAttr* curElem = fVector->elementAt(index);
00094 
00095         if (XMLString::equals(curElem->getQName(), name))
00096             return XMLAttDef::getAttTypeString(curElem->getType(), fVector->getMemoryManager());
00097     }
00098     return 0;
00099 }
00100 
00101 const XMLCh* VecAttrListImpl::getValue(const XMLCh* const name) const
00102 {
00103     //
00104     //  Search the vector for the attribute with the given name and return
00105     //  its type.
00106     //
00107     for (XMLSize_t index = 0; index < fCount; index++)
00108     {
00109         const XMLAttr* curElem = fVector->elementAt(index);
00110 
00111         if (XMLString::equals(curElem->getQName(), name))
00112             return curElem->getValue();
00113     }
00114     return 0;
00115 }
00116 
00117 const XMLCh* VecAttrListImpl::getValue(const char* const name) const
00118 {
00119     // Temporarily transcode the name for lookup
00120     XMLCh* wideName = XMLString::transcode(name, XMLPlatformUtils::fgMemoryManager);
00121     ArrayJanitor<XMLCh> janName(wideName, XMLPlatformUtils::fgMemoryManager);
00122 
00123     //
00124     //  Search the vector for the attribute with the given name and return
00125     //  its type.
00126     //
00127     for (XMLSize_t index = 0; index < fCount; index++)
00128     {
00129         const XMLAttr* curElem = fVector->elementAt(index);
00130 
00131         if (XMLString::equals(curElem->getQName(), wideName))
00132             return curElem->getValue();
00133     }
00134     return 0;
00135 }
00136 
00137 
00138 
00139 // ---------------------------------------------------------------------------
00140 //  Setter methods
00141 // ---------------------------------------------------------------------------
00142 void VecAttrListImpl::setVector(const   RefVectorOf<XMLAttr>* const srcVec
00143                                 , const XMLSize_t                   count
00144                                 , const bool                        adopt)
00145 {
00146     //
00147     //  Delete the previous vector (if any) if we are adopting. Note that some
00148     //  compilers can't deal with the fact that the pointer is to a const
00149     //  object, so we have to cast off the const'ness here!
00150     //
00151     if (fAdopt)
00152         delete (RefVectorOf<XMLAttr>*)fVector;
00153 
00154     fAdopt = adopt;
00155     fCount = count;
00156     fVector = srcVec;
00157 }
00158 
00159 XERCES_CPP_NAMESPACE_END