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

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

Fix imports in icXML modified Xerces files

File size: 6.7 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
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  Local const data
35//
36//  gAttTypeStrings
37//      A list of strings which are used to map attribute type numbers to
38//      attribute type names.
39//
40//  gDefAttTypesStrings
41//      A list of strings which are used to map default attribute type
42//      numbers to default attribute type names.
43// ---------------------------------------------------------------------------
44const XMLCh* const gAttTypeStrings[XMLAttDef::AttTypes_Count] =
45{
46    XMLUni::fgCDATAString
47    , XMLUni::fgIDString
48    , XMLUni::fgIDRefString
49    , XMLUni::fgIDRefsString
50    , XMLUni::fgEntityString
51    , XMLUni::fgEntitiesString
52    , XMLUni::fgNmTokenString
53    , XMLUni::fgNmTokensString
54    , XMLUni::fgNotationString
55    , XMLUni::fgEnumerationString
56    , XMLUni::fgCDATAString
57    , XMLUni::fgCDATAString
58    , XMLUni::fgCDATAString
59    , XMLUni::fgCDATAString
60
61};
62
63const XMLCh* const gDefAttTypeStrings[XMLAttDef::DefAttTypes_Count] =
64{
65    XMLUni::fgDefaultString
66    , XMLUni::fgFixedString
67    , XMLUni::fgRequiredString
68    , XMLUni::fgImpliedString
69    , XMLUni::fgImpliedString
70    , XMLUni::fgImpliedString
71    , XMLUni::fgImpliedString
72    , XMLUni::fgImpliedString
73    , XMLUni::fgImpliedString
74};
75
76
77
78// ---------------------------------------------------------------------------
79//  XMLAttDef: Public, static data members
80// ---------------------------------------------------------------------------
81const unsigned int XMLAttDef::fgInvalidAttrId = 0xFFFFFFFE;
82
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// ---------------------------------------------------------------------------
116//  XMLAttDef: Hidden constructors
117// ---------------------------------------------------------------------------
118XMLAttDef::XMLAttDef( const XMLAttDef::AttTypes    type
119                    , const XMLAttDef::DefAttTypes defType
120                    , MemoryManager* const         manager) :
121
122    fDefaultType(defType)
123    , fType(type)
124    , fCreateReason(XMLAttDef::NoReason)
125    , fExternalAttribute(false)
126    , fId(XMLAttDef::fgInvalidAttrId)
127    , fValue(0)
128    , fEnumeration(0)
129    , fLastOccurrence(0)
130    , fMemoryManager(manager)
131{
132}
133
134typedef JanitorMemFunCall<XMLAttDef>    CleanupType;
135
136XMLAttDef::XMLAttDef( const XMLCh* const           attrValue
137                    , const XMLAttDef::AttTypes    type
138                    , const XMLAttDef::DefAttTypes defType
139                    , const XMLCh* const           enumValues
140                    , MemoryManager* const         manager) :
141
142    fDefaultType(defType)
143    , fType(type)
144    , fCreateReason(XMLAttDef::NoReason)
145    , fExternalAttribute(false)
146    , fId(XMLAttDef::fgInvalidAttrId)
147    , fValue(0)
148    , fEnumeration(0)
149    , fLastOccurrence(0)
150    , fMemoryManager(manager)
151{
152    CleanupType cleanup(this, &XMLAttDef::cleanUp);
153
154    try
155    {
156        fValue = XMLString::replicate(attrValue, fMemoryManager);
157        fEnumeration = XMLString::replicate(enumValues, fMemoryManager);
158    }
159    catch(const OutOfMemoryException&)
160    {
161        cleanup.release();
162
163        throw;
164    }
165
166    cleanup.release();
167}
168
169
170// ---------------------------------------------------------------------------
171//  XMLAttDef: Private helper methods
172// ---------------------------------------------------------------------------
173void XMLAttDef::cleanUp()
174{
175    if (fEnumeration)
176        fMemoryManager->deallocate(fEnumeration);
177
178    if (fValue)
179        fMemoryManager->deallocate(fValue);
180}
181
182/***
183 * Support for Serialization/De-serialization
184 ***/
185
186IMPL_XSERIALIZABLE_NOCREATE(XMLAttDef)
187
188void XMLAttDef::serialize(XSerializeEngine& serEng)
189{
190
191    if (serEng.isStoring())
192    {
193        serEng<<(int)fDefaultType;
194        serEng<<(int)fType;
195        serEng<<(int)fCreateReason;
196        serEng<<fExternalAttribute;
197        serEng.writeSize (fId);
198
199        serEng.writeString(fValue);
200        serEng.writeString(fEnumeration);
201    }
202    else
203    {
204        int i;
205        serEng>>i;
206        fDefaultType = (DefAttTypes) i;
207
208        serEng>>i;
209        fType = (AttTypes)i;
210
211        serEng>>i;
212        fCreateReason = (CreateReasons)i;
213
214        serEng>>fExternalAttribute;
215        serEng.readSize (fId);
216
217        serEng.readString(fValue);
218        serEng.readString(fEnumeration);
219    }
220}
221
222XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.