source: icXML/icXML-devel/src/xercesc/validators/schema/identity/IdentityConstraint.cpp @ 2722

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

Original Xerces files with import mods for icxercesc

File size: 6.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: 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 <icxercesc/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        fIdentityConstraintName = XMLString::replicate(identityConstraintName, fMemoryManager);
61        fElemName = XMLString::replicate(elemName, fMemoryManager);
62    }
63    catch(const OutOfMemoryException&)
64    {
65        cleanup.release();
66
67        throw;
68    }
69
70    cleanup.release();
71}
72
73
74IdentityConstraint::~IdentityConstraint()
75{
76    cleanUp();
77}
78
79// ---------------------------------------------------------------------------
80//  IdentityConstraint: operators
81// ---------------------------------------------------------------------------
82bool IdentityConstraint::operator ==(const IdentityConstraint& other) const {
83
84    if (getType() != other.getType())
85        return false;
86
87    if (!XMLString::equals(fIdentityConstraintName, other.fIdentityConstraintName))
88        return false;
89
90    if (*fSelector != *(other.fSelector))
91        return false;
92
93    XMLSize_t fieldCount = fFields->size();
94
95    if (fieldCount != other.fFields->size())
96        return false;
97
98    for (XMLSize_t i = 0; i < fieldCount; i++) {
99        if (*(fFields->elementAt(i)) != *(other.fFields->elementAt(i)))
100            return false;
101    }
102
103    return true;
104}
105
106bool IdentityConstraint::operator !=(const IdentityConstraint& other) const {
107
108    return !operator==(other);
109}
110
111// ---------------------------------------------------------------------------
112//  IdentityConstraint: Setter methods
113// ---------------------------------------------------------------------------
114void IdentityConstraint::setSelector(IC_Selector* const selector) {
115
116    if (fSelector) {
117        delete fSelector;
118    }
119
120    fSelector = selector;
121}
122
123
124// ---------------------------------------------------------------------------
125//  IdentityConstraint: cleanUp methods
126// ---------------------------------------------------------------------------
127void IdentityConstraint::cleanUp() {
128
129    fMemoryManager->deallocate(fIdentityConstraintName);//delete [] fIdentityConstraintName;
130    fMemoryManager->deallocate(fElemName);//delete [] fElemName;
131    delete fFields;
132    delete fSelector;
133}
134
135/***
136 * Support for Serialization/De-serialization
137 ***/
138
139IMPL_XSERIALIZABLE_NOCREATE(IdentityConstraint)
140
141void IdentityConstraint::serialize(XSerializeEngine& serEng)
142{
143
144    if (serEng.isStoring())
145    {
146        serEng.writeString(fIdentityConstraintName);
147        serEng.writeString(fElemName);
148
149        serEng<<fSelector;
150        serEng<<fNamespaceURI;
151        /***
152         *
153         * Serialize RefVectorOf<IC_Field>* fFields;
154         *
155         ***/
156        XTemplateSerializer::storeObject(fFields, serEng);
157   
158    }
159    else
160    {
161
162        serEng.readString(fIdentityConstraintName);
163        serEng.readString(fElemName);
164
165        serEng>>fSelector;
166        serEng>>fNamespaceURI;
167        /***
168         *
169         * Deserialize RefVectorOf<IC_Field>* fFields;
170         *
171         ***/
172        XTemplateSerializer::loadObject(&fFields, 4, true, serEng);
173
174    }
175
176} 
177
178void IdentityConstraint::storeIC(XSerializeEngine&         serEng
179                               , IdentityConstraint* const ic)
180{
181    if (ic)
182    {
183        serEng<<(int) ic->getType();
184        serEng<<ic;
185    }
186    else
187    {
188        serEng<<(int) ICType_UNKNOWN;
189    }
190
191}
192
193IdentityConstraint* IdentityConstraint::loadIC(XSerializeEngine& serEng)
194{
195
196    int type;
197    serEng>>type;
198
199    switch((ICType)type)
200    {
201    case ICType_UNIQUE:
202        IC_Unique* ic_unique;
203        serEng>>ic_unique;
204        return ic_unique;     
205    case ICType_KEY:
206        IC_Key* ic_key;
207        serEng>>ic_key;
208        return ic_key;
209    case ICType_KEYREF:
210        IC_KeyRef* ic_keyref;
211        serEng>>ic_keyref;
212        return ic_keyref;
213    case ICType_UNKNOWN:
214        return 0;
215    default: //we treat this same as UnKnown
216        return 0;
217    }
218
219}
220
221XERCES_CPP_NAMESPACE_END
222
223/**
224  * End of file IdentityConstraint.cpp
225  */
226
Note: See TracBrowser for help on using the repository browser.