source: icXML/icXML-devel/src/xercesc/framework/XMLEntityDecl.cpp @ 2732

Last change on this file since 2732 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 5.3 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * $Id: XMLEntityDecl.cpp 679359 2008-07-24 11:15:19Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/framework/XMLEntityDecl.hpp>
27#include <xercesc/util/XMLUniDefs.hpp>
28#include <xercesc/util/OutOfMemoryException.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  XMLEntityDecl: Constructors and Destructor
34// ---------------------------------------------------------------------------
35XMLEntityDecl::XMLEntityDecl(MemoryManager* const manager) :
36
37    fId(0)
38    , fValueLen(0)
39    , fValue(0)
40    , fName(0)
41    , fNotationName(0)
42    , fPublicId(0)
43    , fSystemId(0)
44    , fBaseURI(0)
45    , fIsExternal(false)
46    , fMemoryManager(manager)
47{
48}
49
50XMLEntityDecl::XMLEntityDecl(const XMLCh* const entName,
51                             MemoryManager* const manager) :
52
53    fId(0)
54    , fValueLen(0)
55    , fValue(0)
56    , fName(0)
57    , fNotationName(0)
58    , fPublicId(0)
59    , fSystemId(0)
60    , fBaseURI(0)
61    , fIsExternal(false)
62    , fMemoryManager(manager)
63{
64    fName = XMLString::replicate(entName, fMemoryManager);
65}
66
67typedef JanitorMemFunCall<XMLEntityDecl>  CleanupType;
68
69XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
70                            , const XMLCh* const   value
71                            , MemoryManager* const manager) :
72    fId(0)
73    , fValueLen(XMLString::stringLen(value))
74    , fValue(0)
75    , fName(0)
76    , fNotationName(0)
77    , fPublicId(0)
78    , fSystemId(0)
79    , fBaseURI(0)
80    , fIsExternal(false)
81    , fMemoryManager(manager)
82{
83    CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
84
85    try
86    {
87        fValue = XMLString::replicate(value, fMemoryManager);
88        fName = XMLString::replicate(entName, fMemoryManager);
89    }
90    catch(const OutOfMemoryException&)
91    {
92        cleanup.release();
93
94        throw;
95    }
96
97    cleanup.release();
98}
99
100XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
101                            , const XMLCh          value
102                            , MemoryManager* const manager) :
103    fId(0)
104    , fValueLen(1)
105    , fValue(0)
106    , fName(0)
107    , fNotationName(0)
108    , fPublicId(0)
109    , fSystemId(0)
110    , fBaseURI(0)
111    , fIsExternal(false)
112    , fMemoryManager(manager)
113{
114    CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
115
116    try
117    {
118        XMLCh dummy[2] = { chNull, chNull };
119        dummy[0] = value;
120        fValue = XMLString::replicate(dummy, fMemoryManager);
121        fName = XMLString::replicate(entName, fMemoryManager);
122    }
123    catch(const OutOfMemoryException&)
124    {
125        cleanup.release();
126
127        throw;
128    }
129
130    cleanup.release();
131}
132
133XMLEntityDecl::~XMLEntityDecl()
134{
135    cleanUp();
136}
137
138
139// ---------------------------------------------------------------------------
140//  XMLEntityDecl: Setter methods
141// ---------------------------------------------------------------------------
142void XMLEntityDecl::setName(const XMLCh* const entName)
143{
144    // Clean up the current name stuff
145    if (fName)
146       fMemoryManager->deallocate(fName);
147
148    fName = XMLString::replicate(entName, fMemoryManager);
149}
150
151
152// ---------------------------------------------------------------------------
153//  XMLEntityDecl: Private helper methods
154// ---------------------------------------------------------------------------
155void XMLEntityDecl::cleanUp()
156{
157    fMemoryManager->deallocate(fName);
158    fMemoryManager->deallocate(fNotationName);
159    fMemoryManager->deallocate(fValue);
160    fMemoryManager->deallocate(fPublicId);
161    fMemoryManager->deallocate(fSystemId);
162    fMemoryManager->deallocate(fBaseURI);
163}
164
165/***
166 * Support for Serialization/De-serialization
167 ***/
168
169IMPL_XSERIALIZABLE_NOCREATE(XMLEntityDecl)
170
171void XMLEntityDecl::serialize(XSerializeEngine& serEng)
172{
173
174    if (serEng.isStoring())
175    {
176        serEng.writeSize (fId);
177        serEng.writeSize (fValueLen);
178        serEng.writeString(fValue);
179        serEng.writeString(fName);
180        serEng.writeString(fNotationName);
181        serEng.writeString(fPublicId);
182        serEng.writeString(fSystemId);
183        serEng.writeString(fBaseURI);
184        serEng<<fIsExternal;
185    }
186    else
187    {
188        serEng.readSize (fId);
189        serEng.readSize (fValueLen);
190        serEng.readString(fValue);
191        serEng.readString(fName);
192        serEng.readString(fNotationName);
193        serEng.readString(fPublicId);
194        serEng.readString(fSystemId);
195        serEng.readString(fBaseURI);
196        serEng>>fIsExternal;
197    }
198}
199
200XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.