/src/xerces-c/src/xercesc/framework/XMLEntityDecl.cpp
Line | Count | Source (jump to first uncovered 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 | | |
30 | | XERCES_CPP_NAMESPACE_BEGIN |
31 | | |
32 | | // --------------------------------------------------------------------------- |
33 | | // XMLEntityDecl: Constructors and Destructor |
34 | | // --------------------------------------------------------------------------- |
35 | | XMLEntityDecl::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 | 480 | { |
48 | 480 | } |
49 | | |
50 | | XMLEntityDecl::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 | 11.1k | { |
64 | 11.1k | fName = XMLString::replicate(entName, fMemoryManager); |
65 | 11.1k | } |
66 | | |
67 | | typedef JanitorMemFunCall<XMLEntityDecl> CleanupType; |
68 | | |
69 | | XMLEntityDecl::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 | 0 | { |
83 | 0 | CleanupType cleanup(this, &XMLEntityDecl::cleanUp); |
84 | |
|
85 | 0 | try |
86 | 0 | { |
87 | 0 | fValue = XMLString::replicate(value, fMemoryManager); |
88 | 0 | fName = XMLString::replicate(entName, fMemoryManager); |
89 | 0 | } |
90 | 0 | catch(const OutOfMemoryException&) |
91 | 0 | { |
92 | 0 | cleanup.release(); |
93 | |
|
94 | 0 | throw; |
95 | 0 | } |
96 | | |
97 | 0 | cleanup.release(); |
98 | 0 | } |
99 | | |
100 | | XMLEntityDecl::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 | 10 | { |
114 | 10 | CleanupType cleanup(this, &XMLEntityDecl::cleanUp); |
115 | | |
116 | 10 | try |
117 | 10 | { |
118 | 10 | XMLCh dummy[2] = { chNull, chNull }; |
119 | 10 | dummy[0] = value; |
120 | 10 | fValue = XMLString::replicate(dummy, fMemoryManager); |
121 | 10 | fName = XMLString::replicate(entName, fMemoryManager); |
122 | 10 | } |
123 | 10 | catch(const OutOfMemoryException&) |
124 | 10 | { |
125 | 0 | cleanup.release(); |
126 | |
|
127 | 0 | throw; |
128 | 0 | } |
129 | | |
130 | 10 | cleanup.release(); |
131 | 10 | } |
132 | | |
133 | | XMLEntityDecl::~XMLEntityDecl() |
134 | 11.6k | { |
135 | 11.6k | cleanUp(); |
136 | 11.6k | } |
137 | | |
138 | | |
139 | | // --------------------------------------------------------------------------- |
140 | | // XMLEntityDecl: Setter methods |
141 | | // --------------------------------------------------------------------------- |
142 | | void XMLEntityDecl::setName(const XMLCh* const entName) |
143 | 13.2k | { |
144 | | // Clean up the current name stuff |
145 | 13.2k | if (fName) |
146 | 12.8k | fMemoryManager->deallocate(fName); |
147 | | |
148 | 13.2k | fName = XMLString::replicate(entName, fMemoryManager); |
149 | 13.2k | } |
150 | | |
151 | | |
152 | | // --------------------------------------------------------------------------- |
153 | | // XMLEntityDecl: Private helper methods |
154 | | // --------------------------------------------------------------------------- |
155 | | void XMLEntityDecl::cleanUp() |
156 | 11.6k | { |
157 | 11.6k | fMemoryManager->deallocate(fName); |
158 | 11.6k | fMemoryManager->deallocate(fNotationName); |
159 | 11.6k | fMemoryManager->deallocate(fValue); |
160 | 11.6k | fMemoryManager->deallocate(fPublicId); |
161 | 11.6k | fMemoryManager->deallocate(fSystemId); |
162 | 11.6k | fMemoryManager->deallocate(fBaseURI); |
163 | 11.6k | } |
164 | | |
165 | | /*** |
166 | | * Support for Serialization/De-serialization |
167 | | ***/ |
168 | | |
169 | | IMPL_XSERIALIZABLE_NOCREATE(XMLEntityDecl) |
170 | | |
171 | | void XMLEntityDecl::serialize(XSerializeEngine& serEng) |
172 | 0 | { |
173 | |
|
174 | 0 | if (serEng.isStoring()) |
175 | 0 | { |
176 | 0 | serEng.writeSize (fId); |
177 | 0 | serEng.writeSize (fValueLen); |
178 | 0 | serEng.writeString(fValue); |
179 | 0 | serEng.writeString(fName); |
180 | 0 | serEng.writeString(fNotationName); |
181 | 0 | serEng.writeString(fPublicId); |
182 | 0 | serEng.writeString(fSystemId); |
183 | 0 | serEng.writeString(fBaseURI); |
184 | 0 | serEng<<fIsExternal; |
185 | 0 | } |
186 | 0 | else |
187 | 0 | { |
188 | 0 | serEng.readSize (fId); |
189 | 0 | serEng.readSize (fValueLen); |
190 | 0 | serEng.readString(fValue); |
191 | 0 | serEng.readString(fName); |
192 | 0 | serEng.readString(fNotationName); |
193 | 0 | serEng.readString(fPublicId); |
194 | 0 | serEng.readString(fSystemId); |
195 | 0 | serEng.readString(fBaseURI); |
196 | 0 | serEng>>fIsExternal; |
197 | 0 | } |
198 | 0 | } |
199 | | |
200 | | XERCES_CPP_NAMESPACE_END |