GME  13
XMLEntityDecl.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/XMLEntityDecl.hpp>
00027 #include <xercesc/util/XMLUniDefs.hpp>
00028 #include <xercesc/util/OutOfMemoryException.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  XMLEntityDecl: Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 XMLEntityDecl::XMLEntityDecl(MemoryManager* const manager) :
00036 
00037     fId(0)
00038     , fValueLen(0)
00039     , fValue(0)
00040     , fName(0)
00041     , fNotationName(0)
00042     , fPublicId(0)
00043     , fSystemId(0)
00044     , fBaseURI(0)
00045     , fIsExternal(false)
00046     , fMemoryManager(manager)
00047 {
00048 }
00049 
00050 XMLEntityDecl::XMLEntityDecl(const XMLCh* const entName,
00051                              MemoryManager* const manager) :
00052 
00053     fId(0)
00054     , fValueLen(0)
00055     , fValue(0)
00056     , fName(0)
00057     , fNotationName(0)
00058     , fPublicId(0)
00059     , fSystemId(0)
00060     , fBaseURI(0)
00061     , fIsExternal(false)
00062     , fMemoryManager(manager)
00063 {
00064     fName = XMLString::replicate(entName, fMemoryManager);
00065 }
00066 
00067 typedef JanitorMemFunCall<XMLEntityDecl>  CleanupType;
00068 
00069 XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
00070                             , const XMLCh* const   value
00071                             , MemoryManager* const manager) :
00072     fId(0)
00073     , fValueLen(XMLString::stringLen(value))
00074     , fValue(0)
00075     , fName(0)
00076     , fNotationName(0)
00077     , fPublicId(0)
00078     , fSystemId(0)
00079     , fBaseURI(0)
00080     , fIsExternal(false)
00081     , fMemoryManager(manager)
00082 {
00083     CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
00084 
00085     try
00086     {
00087         fValue = XMLString::replicate(value, fMemoryManager);
00088         fName = XMLString::replicate(entName, fMemoryManager);
00089     }
00090     catch(const OutOfMemoryException&)
00091     {
00092         cleanup.release();
00093 
00094         throw;
00095     }
00096 
00097     cleanup.release();
00098 }
00099 
00100 XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
00101                             , const XMLCh          value
00102                             , MemoryManager* const manager) :
00103     fId(0)
00104     , fValueLen(1)
00105     , fValue(0)
00106     , fName(0)
00107     , fNotationName(0)
00108     , fPublicId(0)
00109     , fSystemId(0)
00110     , fBaseURI(0)
00111     , fIsExternal(false)
00112     , fMemoryManager(manager)
00113 {
00114     CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
00115 
00116     try
00117     {
00118         XMLCh dummy[2] = { chNull, chNull };
00119         dummy[0] = value;
00120         fValue = XMLString::replicate(dummy, fMemoryManager);
00121         fName = XMLString::replicate(entName, fMemoryManager);
00122     }
00123     catch(const OutOfMemoryException&)
00124     {
00125         cleanup.release();
00126 
00127         throw;
00128     }
00129 
00130     cleanup.release();
00131 }
00132 
00133 XMLEntityDecl::~XMLEntityDecl()
00134 {
00135     cleanUp();
00136 }
00137 
00138 
00139 // ---------------------------------------------------------------------------
00140 //  XMLEntityDecl: Setter methods
00141 // ---------------------------------------------------------------------------
00142 void XMLEntityDecl::setName(const XMLCh* const entName)
00143 {
00144     // Clean up the current name stuff
00145     if (fName)
00146        fMemoryManager->deallocate(fName);
00147 
00148     fName = XMLString::replicate(entName, fMemoryManager);
00149 }
00150 
00151 
00152 // ---------------------------------------------------------------------------
00153 //  XMLEntityDecl: Private helper methods
00154 // ---------------------------------------------------------------------------
00155 void XMLEntityDecl::cleanUp()
00156 {
00157     fMemoryManager->deallocate(fName);
00158     fMemoryManager->deallocate(fNotationName);
00159     fMemoryManager->deallocate(fValue);
00160     fMemoryManager->deallocate(fPublicId);
00161     fMemoryManager->deallocate(fSystemId);
00162     fMemoryManager->deallocate(fBaseURI);
00163 }
00164 
00165 /***
00166  * Support for Serialization/De-serialization
00167  ***/
00168 
00169 IMPL_XSERIALIZABLE_NOCREATE(XMLEntityDecl)
00170 
00171 void XMLEntityDecl::serialize(XSerializeEngine& serEng)
00172 {
00173 
00174     if (serEng.isStoring())
00175     {
00176         serEng.writeSize (fId);
00177         serEng.writeSize (fValueLen);
00178         serEng.writeString(fValue);
00179         serEng.writeString(fName);
00180         serEng.writeString(fNotationName);
00181         serEng.writeString(fPublicId);
00182         serEng.writeString(fSystemId);
00183         serEng.writeString(fBaseURI);
00184         serEng<<fIsExternal;
00185     }
00186     else
00187     {
00188         serEng.readSize (fId);
00189         serEng.readSize (fValueLen);
00190         serEng.readString(fValue);
00191         serEng.readString(fName);
00192         serEng.readString(fNotationName);
00193         serEng.readString(fPublicId);
00194         serEng.readString(fSystemId);
00195         serEng.readString(fBaseURI);
00196         serEng>>fIsExternal;
00197     }
00198 }
00199 
00200 XERCES_CPP_NAMESPACE_END