source: icXML/icXML-devel/src/icxercesc/framework/XMLAttDef.cpp

Last change on this file was 3564, checked in by cameron, 6 years ago

Changes to icxercesc files

File size: 9.2 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: XMLAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <icxercesc/framework/XMLAttDef.hpp>
27#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
28#include <xercesc/util/XMLUni.hpp>
29#include <xercesc/util/OutOfMemoryException.hpp>
30#include <icxmlc/XMLNamespaceResolver.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34typedef JanitorMemFunCall<XMLAttDef>    CleanupType;
35
36// ---------------------------------------------------------------------------
37//  Local const data
38//
39//  gAttTypeStrings
40//      A list of strings which are used to map attribute type numbers to
41//      attribute type names.
42//
43//  gDefAttTypesStrings
44//      A list of strings which are used to map default attribute type
45//      numbers to default attribute type names.
46// ---------------------------------------------------------------------------
47const XMLCh* const gAttTypeStrings[XMLAttDef::AttTypes_Count] =
48{
49    XMLUni::fgCDATAString
50    , XMLUni::fgIDString
51    , XMLUni::fgIDRefString
52    , XMLUni::fgIDRefsString
53    , XMLUni::fgEntityString
54    , XMLUni::fgEntitiesString
55    , XMLUni::fgNmTokenString
56    , XMLUni::fgNmTokensString
57    , XMLUni::fgNotationString
58    , XMLUni::fgEnumerationString
59    , XMLUni::fgCDATAString
60    , XMLUni::fgCDATAString
61    , XMLUni::fgCDATAString
62    , XMLUni::fgCDATAString
63
64};
65
66const XMLCh* const gDefAttTypeStrings[XMLAttDef::DefAttTypes_Count] =
67{
68    XMLUni::fgDefaultString
69    , XMLUni::fgFixedString
70    , XMLUni::fgRequiredString
71    , XMLUni::fgImpliedString
72    , XMLUni::fgImpliedString
73    , XMLUni::fgImpliedString
74    , XMLUni::fgImpliedString
75    , XMLUni::fgImpliedString
76    , XMLUni::fgImpliedString
77};
78
79// ---------------------------------------------------------------------------
80//  XMLAttDef: Public, static data members
81// ---------------------------------------------------------------------------
82const unsigned int XMLAttDef::fgInvalidAttrId = 0xFFFFFFFE;
83
84// ---------------------------------------------------------------------------
85//  XMLAttDef: Public, static methods
86// ---------------------------------------------------------------------------
87const XMLCh* XMLAttDef::getAttTypeString(const XMLAttDef::AttTypes attrType
88                                         , MemoryManager* const manager)
89{
90    // Check for an invalid attribute type and return a null
91    if ((attrType < AttTypes_Min) || (attrType > AttTypes_Max))
92        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttDef_BadAttType, manager);
93    return gAttTypeStrings[attrType];
94}
95
96const XMLCh* XMLAttDef::getDefAttTypeString(const XMLAttDef::DefAttTypes attrType
97                                            , MemoryManager* const manager)
98{
99    // Check for an invalid attribute type and return a null
100    if ((attrType < DefAttTypes_Min) || (attrType > DefAttTypes_Max))
101        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttDef_BadDefAttType, manager);
102    return gDefAttTypeStrings[attrType];
103}
104
105
106// ---------------------------------------------------------------------------
107//  XMLAttDef: Destructor
108// ---------------------------------------------------------------------------
109XMLAttDef::~XMLAttDef()
110{
111    cleanUp();
112}
113
114// ---------------------------------------------------------------------------
115//  XMLAttDef: Hidden constructors
116// ---------------------------------------------------------------------------
117XMLAttDef::XMLAttDef(XMLStringPool* const qNameManager)
118: fAttName(qNameManager)
119, fDefaultType(Implied)
120, fType(CData)
121, fCreateReason(XMLAttDef::NoReason)
122, fExternalAttribute(false)
123, fId(XMLAttDef::fgInvalidAttrId)
124, fValue(0)
125, fEnumeration(0)
126, fLastOccurrence(0)
127{
128
129}
130
131XMLAttDef::XMLAttDef
132(
133    QName *                        attName
134    , const XMLAttDef::AttTypes    type
135    , const XMLAttDef::DefAttTypes defType
136)
137: fAttName(*attName)
138, fDefaultType(defType)
139, fType(type)
140, fCreateReason(XMLAttDef::NoReason)
141, fExternalAttribute(false)
142, fId(XMLAttDef::fgInvalidAttrId)
143, fValue(0)
144, fEnumeration(0)
145, fLastOccurrence(0)
146{
147
148}
149
150XMLAttDef::XMLAttDef(const XMLAttDef & other)
151: fAttName(*(other.getAttName()))
152, fDefaultType(other.getDefaultType())
153, fType(other.getType())
154, fCreateReason(other.getCreateReason())
155, fExternalAttribute(other.isExternal())
156, fId(other.getId())
157, fValue(0)
158, fEnumeration(0)
159, fLastOccurrence(other.getLastOccurrence())
160{
161    CleanupType cleanup(this, &XMLAttDef::cleanUp);
162
163    try
164    {
165        fValue = XMLString::replicate(other.getValue(), getMemoryManager());
166        fEnumeration = XMLString::replicate(other.getEnumeration(), getMemoryManager());
167    }
168    catch(const OutOfMemoryException&)
169    {
170        cleanup.release();
171        throw;
172    }
173
174    cleanup.release();
175}
176
177
178XMLAttDef::XMLAttDef
179(
180      const XMLCh* const           prefix
181    , const XMLCh* const           localPart
182    , const int                    uriId
183    , const XMLAttDef::AttTypes    type
184    , const XMLAttDef::DefAttTypes defType
185    , XMLStringPool* const         qNameManager
186)
187: fAttName(prefix, localPart, uriId, qNameManager)
188, fDefaultType(defType)
189, fType(type)
190, fCreateReason(XMLAttDef::NoReason)
191, fExternalAttribute(false)
192, fId(XMLAttDef::fgInvalidAttrId)
193, fValue(0)
194, fEnumeration(0)
195, fLastOccurrence(0)
196{
197
198}
199
200XMLAttDef::XMLAttDef
201(
202    const   XMLCh* const           attName
203    , const XMLAttDef::AttTypes    type
204    , const XMLAttDef::DefAttTypes defType
205    , XMLStringPool* const         qNameManager
206)
207: fAttName(attName, XMLNamespaceResolver::fEmptyUriId, qNameManager)
208, fDefaultType(defType)
209, fType(type)
210, fCreateReason(XMLAttDef::NoReason)
211, fExternalAttribute(false)
212, fId(XMLAttDef::fgInvalidAttrId)
213, fValue(0)
214, fEnumeration(0)
215, fLastOccurrence(0)
216{
217
218}
219
220XMLAttDef::XMLAttDef
221(
222      const XMLCh* const           prefix
223    , const XMLCh* const           localPart
224    , const int                    uriId
225    , const XMLCh* const           attrValue
226    , const XMLAttDef::AttTypes    type
227    , const XMLAttDef::DefAttTypes defType
228    , const XMLCh* const           enumValues
229    , XMLStringPool* const         qNameManager
230)
231: fAttName(prefix, localPart, uriId, qNameManager)
232, fDefaultType(defType)
233, fType(type)
234, fCreateReason(XMLAttDef::NoReason)
235, fExternalAttribute(false)
236, fId(XMLAttDef::fgInvalidAttrId)
237, fValue(0)
238, fEnumeration(0)
239, fLastOccurrence(0)
240{
241    CleanupType cleanup(this, &XMLAttDef::cleanUp);
242
243    try
244    {
245        fValue = XMLString::replicate(attrValue, getMemoryManager());
246        fEnumeration = XMLString::replicate(enumValues, getMemoryManager());
247    }
248    catch(const OutOfMemoryException&)
249    {
250        cleanup.release();
251
252        throw;
253    }
254
255    cleanup.release();
256}
257
258
259XMLAttDef::XMLAttDef
260(
261    const   XMLCh* const           attName
262    , const XMLCh* const           attrValue
263    , const XMLAttDef::AttTypes    type
264    , const XMLAttDef::DefAttTypes defType
265    , const XMLCh* const           enumValues
266    , XMLStringPool* const         qNameManager
267)
268: fAttName(attName, XMLNamespaceResolver::fEmptyUriId, qNameManager)
269, fDefaultType(defType)
270, fType(type)
271, fCreateReason(XMLAttDef::NoReason)
272, fExternalAttribute(false)
273, fId(XMLAttDef::fgInvalidAttrId)
274, fValue(0)
275, fEnumeration(0)
276, fLastOccurrence(0)
277{
278    CleanupType cleanup(this, &XMLAttDef::cleanUp);
279
280    try
281    {
282        fValue = XMLString::replicate(attrValue, getMemoryManager());
283        fEnumeration = XMLString::replicate(enumValues, getMemoryManager());
284    }
285    catch(const OutOfMemoryException&)
286    {
287        cleanup.release();
288        throw;
289    }
290
291    cleanup.release();
292}
293
294// ---------------------------------------------------------------------------
295//  XMLAttDef: Private helper methods
296// ---------------------------------------------------------------------------
297void XMLAttDef::cleanUp()
298{
299    if (fEnumeration)
300        getMemoryManager()->deallocate(fEnumeration);
301
302    if (fValue)
303        getMemoryManager()->deallocate(fValue);
304}
305
306/***
307 * Support for Serialization/De-serialization
308 ***/
309
310IMPL_XSERIALIZABLE_NOCREATE(XMLAttDef)
311
312void XMLAttDef::serialize(XSerializeEngine&)
313{
314    DEPRECATED_FEATURE_IN_ICXML;
315}
316
317XMLAttDef::XMLAttDef(const XMLAttDef::AttTypes, const XMLAttDef::DefAttTypes, MemoryManager* const)
318{
319    DEPRECATED_FEATURE_IN_ICXML;
320}
321
322XMLAttDef::XMLAttDef(const XMLCh* const, const XMLAttDef::AttTypes, const XMLAttDef::DefAttTypes, const XMLCh* const, MemoryManager* const)
323{
324    DEPRECATED_FEATURE_IN_ICXML;
325}
326
327
328XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.