GME  13
XMLAttr.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 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/framework/XMLAttr.hpp>
00027 #include <xercesc/framework/MemoryManager.hpp>
00028 #include <xercesc/util/OutOfMemoryException.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  XMLAttr: Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 XMLAttr::XMLAttr(MemoryManager* const manager) :
00036 
00037       fSpecified(false)
00038     , fType(XMLAttDef::CData)
00039     , fValueBufSz(0)
00040     , fValue(0)
00041     , fAttName(0)
00042     , fMemoryManager(manager)
00043 {
00044     fAttName = new (fMemoryManager) QName(fMemoryManager);
00045 }
00046 
00047 typedef JanitorMemFunCall<XMLAttr>  CleanupType;
00048 
00049 XMLAttr::XMLAttr(   const   unsigned int        uriId
00050                     , const XMLCh* const        attrName
00051                     , const XMLCh* const        attrPrefix
00052                     , const XMLCh* const        attrValue
00053                     , const XMLAttDef::AttTypes type
00054                     , const bool                specified
00055                     , MemoryManager* const      manager
00056                     , DatatypeValidator*
00057                     , const bool /*isSchema*/ ):
00058 
00059       fSpecified(specified)
00060     , fType(type)
00061     , fValueBufSz(0)
00062     , fValue(0)
00063     , fAttName(0)
00064     , fMemoryManager(manager)
00065 {
00066     CleanupType cleanup(this, &XMLAttr::cleanUp);
00067 
00068     try
00069     {
00070         //
00071         //  Just call the local setters to set up everything. Too much
00072         //  work is required to replicate that functionality here.
00073         //
00074         fAttName = new (fMemoryManager) QName(attrPrefix, attrName, uriId, fMemoryManager);
00075         setValue(attrValue);
00076     }
00077     catch(const OutOfMemoryException&)
00078     {
00079         cleanup.release();
00080 
00081         throw;
00082     }
00083 
00084     cleanup.release();
00085 }
00086 
00087 XMLAttr::XMLAttr(   const   unsigned int        uriId
00088                     , const XMLCh* const        rawName
00089                     , const XMLCh* const        attrValue
00090                     , const XMLAttDef::AttTypes type
00091                     , const bool                specified
00092                     , MemoryManager* const      manager
00093                     , DatatypeValidator *
00094                     , const bool /*isSchema*/ ):
00095 
00096       fSpecified(specified)
00097     , fType(type)
00098     , fValueBufSz(0)
00099     , fValue(0)
00100     , fAttName(0)
00101     , fMemoryManager(manager)
00102 {
00103     CleanupType cleanup(this, &XMLAttr::cleanUp);
00104 
00105     try
00106     {
00107         //  Just call the local setters to set up everything. Too much
00108         //  work is required to replicate that functionality here.
00109         fAttName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager);
00110         setValue(attrValue);
00111     }
00112     catch(const OutOfMemoryException&)
00113     {
00114         cleanup.release();
00115 
00116         throw;
00117     }
00118 
00119     cleanup.release();
00120 }
00121 
00122 
00123 // ---------------------------------------------------------------------------
00124 //  XMLAttr: Getter methods
00125 // ---------------------------------------------------------------------------
00126 const XMLCh* XMLAttr::getQName() const
00127 {
00128     return fAttName->getRawName();
00129 }
00130 
00131 
00132 // ---------------------------------------------------------------------------
00133 //  XMLAttr: Setter methods
00134 // ---------------------------------------------------------------------------
00135 void XMLAttr::setName(  const   unsigned int    uriId
00136                         , const XMLCh* const    attrName
00137                         , const XMLCh* const    attrPrefix)
00138 {
00139     fAttName->setName(attrPrefix, attrName, uriId);
00140 }
00141 
00142 
00143 void XMLAttr::setURIId(const unsigned int uriId)
00144 {
00145     fAttName->setURI(uriId);
00146 }
00147 
00148 
00149 void XMLAttr::setValue(const XMLCh* const newValue)
00150 {
00151     const XMLSize_t newLen = XMLString::stringLen(newValue);
00152     if (!fValueBufSz || (newLen > fValueBufSz))
00153     {
00154         fMemoryManager->deallocate(fValue); //delete [] fValue;
00155         fValue = 0;
00156         fValueBufSz = newLen + 8;
00157         fValue = (XMLCh*) fMemoryManager->allocate((fValueBufSz+1) * sizeof(XMLCh)); //new XMLCh[fValueBufSz + 1];
00158     }
00159     XMLString::moveChars(fValue, newValue, newLen + 1);
00160 }
00161 
00162 
00163 // ---------------------------------------------------------------------------
00164 //  XMLAttr: Private, helper methods
00165 // ---------------------------------------------------------------------------
00166 void XMLAttr::cleanUp()
00167 {
00168     delete fAttName;
00169     fMemoryManager->deallocate(fValue); //delete [] fValue;
00170 }
00171 
00172 XERCES_CPP_NAMESPACE_END