source: icXML/icXML-devel/src/icxercesc/validators/schema/identity/IdentityConstraint.cpp @ 3152

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

New custom icxercesc files

File size: 5.6 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: IdentityConstraint.cpp 676911 2008-07-15 13:27:32Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
26#include <xercesc/validators/schema/identity/IC_Selector.hpp>
27#include <xercesc/validators/schema/identity/IC_Field.hpp>
28#include <xercesc/util/XMLString.hpp>
29#include <xercesc/util/OutOfMemoryException.hpp>
30
31//since we need to dynamically created each and every derivatives
32//during deserialization by XSerializeEngine>>Derivative, we got
33//to include all hpp
34#include <xercesc/validators/schema/identity/IC_Unique.hpp>
35#include <xercesc/validators/schema/identity/IC_Key.hpp>
36#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
37
38#include <xercesc/internal/XTemplateSerializer.hpp>
39
40XERCES_CPP_NAMESPACE_BEGIN
41
42typedef JanitorMemFunCall<IdentityConstraint>   CleanupType;
43
44// ---------------------------------------------------------------------------
45//  IdentityConstraint: Constructors and Destructor
46// ---------------------------------------------------------------------------
47IdentityConstraint::IdentityConstraint(const XMLCh* const identityConstraintName,
48                                                                           const XMLCh* const elemName,
49                                                                           MemoryManager* const manager)
50        : fIdentityConstraintName(0)
51        , fElemName(0)
52        , fSelector(0)
53        , fFields(0)
54        , fMemoryManager(manager)
55        , fNamespaceURI(-1)
56{
57        CleanupType cleanup(this, &IdentityConstraint::cleanUp);
58
59        try
60        {
61                fIdentityConstraintName = XMLString::replicate(identityConstraintName, fMemoryManager);
62                fElemName = XMLString::replicate(elemName, fMemoryManager);
63        }
64        catch(const OutOfMemoryException&)
65        {
66                cleanup.release();
67
68                throw;
69        }
70
71        cleanup.release();
72}
73
74
75IdentityConstraint::~IdentityConstraint()
76{
77        cleanUp();
78}
79
80// ---------------------------------------------------------------------------
81//  IdentityConstraint: operators
82// ---------------------------------------------------------------------------
83bool IdentityConstraint::operator ==(const IdentityConstraint& other) const
84{
85        if (getType() != other.getType())
86                return false;
87
88        if (!XMLString::equals(fIdentityConstraintName, other.fIdentityConstraintName))
89                return false;
90
91        if (*fSelector != *(other.fSelector))
92                return false;
93
94        XMLSize_t fieldCount = fFields->size();
95
96        if (fieldCount != other.fFields->size())
97                return false;
98
99        for (XMLSize_t i = 0; i < fieldCount; i++)
100        {
101                if (*(fFields->elementAt(i)) != *(other.fFields->elementAt(i)))
102                        return false;
103        }
104
105        return true;
106}
107
108bool IdentityConstraint::operator !=(const IdentityConstraint& other) const
109{
110        return !operator==(other);
111}
112
113// ---------------------------------------------------------------------------
114//  IdentityConstraint: Setter methods
115// ---------------------------------------------------------------------------
116void IdentityConstraint::setSelector(IC_Selector* const selector)
117{
118        if (fSelector)
119        {
120                delete fSelector;
121        }
122
123        fSelector = selector;
124}
125
126
127// ---------------------------------------------------------------------------
128//  IdentityConstraint: cleanUp methods
129// ---------------------------------------------------------------------------
130void IdentityConstraint::cleanUp()
131{
132        fMemoryManager->deallocate(fIdentityConstraintName);//delete [] fIdentityConstraintName;
133        fMemoryManager->deallocate(fElemName);//delete [] fElemName;
134        delete fFields;
135        delete fSelector;
136}
137
138/***
139 * Support for Serialization/De-serialization
140 ***/
141
142IMPL_XSERIALIZABLE_NOCREATE(IdentityConstraint)
143
144void IdentityConstraint::serialize(XSerializeEngine& serEng)
145{
146
147        if (serEng.isStoring())
148        {
149                serEng.writeString(fIdentityConstraintName);
150                serEng.writeString(fElemName);
151
152                serEng<<fSelector;
153                serEng<<fNamespaceURI;
154                /***
155                 *
156                 * Serialize RefVectorOf<IC_Field>* fFields;
157                 *
158                 ***/
159                XTemplateSerializer::storeObject(fFields, serEng);
160
161        }
162        else
163        {
164
165                serEng.readString(fIdentityConstraintName);
166                serEng.readString(fElemName);
167
168                serEng>>fSelector;
169                serEng>>fNamespaceURI;
170                /***
171                 *
172                 * Deserialize RefVectorOf<IC_Field>* fFields;
173                 *
174                 ***/
175                XTemplateSerializer::loadObject(&fFields, 4, true, serEng);
176
177        }
178
179}
180
181void IdentityConstraint::storeIC(XSerializeEngine&         serEng
182                                                           , IdentityConstraint* const ic)
183{
184        if (ic)
185        {
186                serEng<<(int) ic->getType();
187                serEng<<ic;
188        }
189        else
190        {
191                serEng<<(int) ICType_UNKNOWN;
192        }
193
194}
195
196IdentityConstraint* IdentityConstraint::loadIC(XSerializeEngine& serEng)
197{
198
199        int type;
200        serEng>>type;
201
202        switch((ICType)type)
203        {
204        case ICType_UNIQUE:
205                IC_Unique* ic_unique;
206                serEng>>ic_unique;
207                return ic_unique;
208        case ICType_KEY:
209                IC_Key* ic_key;
210                serEng>>ic_key;
211                return ic_key;
212        case ICType_KEYREF:
213                IC_KeyRef* ic_keyref;
214                serEng>>ic_keyref;
215                return ic_keyref;
216        case ICType_UNKNOWN:
217                return 0;
218        default: //we treat this same as UnKnown
219                return 0;
220        }
221
222}
223
224XERCES_CPP_NAMESPACE_END
225
226/**
227  * End of file IdentityConstraint.cpp
228  */
229
Note: See TracBrowser for help on using the repository browser.