GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: IdentityConstraint.cpp 676911 2008-07-15 13:27:32Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/schema/identity/IdentityConstraint.hpp> 00026 #include <xercesc/validators/schema/identity/IC_Selector.hpp> 00027 #include <xercesc/validators/schema/identity/IC_Field.hpp> 00028 #include <xercesc/util/XMLString.hpp> 00029 #include <xercesc/util/OutOfMemoryException.hpp> 00030 00031 //since we need to dynamically created each and every derivatives 00032 //during deserialization by XSerializeEngine>>Derivative, we got 00033 //to include all hpp 00034 #include <xercesc/validators/schema/identity/IC_Unique.hpp> 00035 #include <xercesc/validators/schema/identity/IC_Key.hpp> 00036 #include <xercesc/validators/schema/identity/IC_KeyRef.hpp> 00037 00038 #include <xercesc/internal/XTemplateSerializer.hpp> 00039 00040 XERCES_CPP_NAMESPACE_BEGIN 00041 00042 typedef JanitorMemFunCall<IdentityConstraint> CleanupType; 00043 00044 // --------------------------------------------------------------------------- 00045 // IdentityConstraint: Constructors and Destructor 00046 // --------------------------------------------------------------------------- 00047 IdentityConstraint::IdentityConstraint(const XMLCh* const identityConstraintName, 00048 const XMLCh* const elemName, 00049 MemoryManager* const manager) 00050 : fIdentityConstraintName(0) 00051 , fElemName(0) 00052 , fSelector(0) 00053 , fFields(0) 00054 , fMemoryManager(manager) 00055 , fNamespaceURI(-1) 00056 { 00057 CleanupType cleanup(this, &IdentityConstraint::cleanUp); 00058 00059 try { 00060 fIdentityConstraintName = XMLString::replicate(identityConstraintName, fMemoryManager); 00061 fElemName = XMLString::replicate(elemName, fMemoryManager); 00062 } 00063 catch(const OutOfMemoryException&) 00064 { 00065 cleanup.release(); 00066 00067 throw; 00068 } 00069 00070 cleanup.release(); 00071 } 00072 00073 00074 IdentityConstraint::~IdentityConstraint() 00075 { 00076 cleanUp(); 00077 } 00078 00079 // --------------------------------------------------------------------------- 00080 // IdentityConstraint: operators 00081 // --------------------------------------------------------------------------- 00082 bool IdentityConstraint::operator ==(const IdentityConstraint& other) const { 00083 00084 if (getType() != other.getType()) 00085 return false; 00086 00087 if (!XMLString::equals(fIdentityConstraintName, other.fIdentityConstraintName)) 00088 return false; 00089 00090 if (*fSelector != *(other.fSelector)) 00091 return false; 00092 00093 XMLSize_t fieldCount = fFields->size(); 00094 00095 if (fieldCount != other.fFields->size()) 00096 return false; 00097 00098 for (XMLSize_t i = 0; i < fieldCount; i++) { 00099 if (*(fFields->elementAt(i)) != *(other.fFields->elementAt(i))) 00100 return false; 00101 } 00102 00103 return true; 00104 } 00105 00106 bool IdentityConstraint::operator !=(const IdentityConstraint& other) const { 00107 00108 return !operator==(other); 00109 } 00110 00111 // --------------------------------------------------------------------------- 00112 // IdentityConstraint: Setter methods 00113 // --------------------------------------------------------------------------- 00114 void IdentityConstraint::setSelector(IC_Selector* const selector) { 00115 00116 if (fSelector) { 00117 delete fSelector; 00118 } 00119 00120 fSelector = selector; 00121 } 00122 00123 00124 // --------------------------------------------------------------------------- 00125 // IdentityConstraint: cleanUp methods 00126 // --------------------------------------------------------------------------- 00127 void IdentityConstraint::cleanUp() { 00128 00129 fMemoryManager->deallocate(fIdentityConstraintName);//delete [] fIdentityConstraintName; 00130 fMemoryManager->deallocate(fElemName);//delete [] fElemName; 00131 delete fFields; 00132 delete fSelector; 00133 } 00134 00135 /*** 00136 * Support for Serialization/De-serialization 00137 ***/ 00138 00139 IMPL_XSERIALIZABLE_NOCREATE(IdentityConstraint) 00140 00141 void IdentityConstraint::serialize(XSerializeEngine& serEng) 00142 { 00143 00144 if (serEng.isStoring()) 00145 { 00146 serEng.writeString(fIdentityConstraintName); 00147 serEng.writeString(fElemName); 00148 00149 serEng<<fSelector; 00150 serEng<<fNamespaceURI; 00151 /*** 00152 * 00153 * Serialize RefVectorOf<IC_Field>* fFields; 00154 * 00155 ***/ 00156 XTemplateSerializer::storeObject(fFields, serEng); 00157 00158 } 00159 else 00160 { 00161 00162 serEng.readString(fIdentityConstraintName); 00163 serEng.readString(fElemName); 00164 00165 serEng>>fSelector; 00166 serEng>>fNamespaceURI; 00167 /*** 00168 * 00169 * Deserialize RefVectorOf<IC_Field>* fFields; 00170 * 00171 ***/ 00172 XTemplateSerializer::loadObject(&fFields, 4, true, serEng); 00173 00174 } 00175 00176 } 00177 00178 void IdentityConstraint::storeIC(XSerializeEngine& serEng 00179 , IdentityConstraint* const ic) 00180 { 00181 if (ic) 00182 { 00183 serEng<<(int) ic->getType(); 00184 serEng<<ic; 00185 } 00186 else 00187 { 00188 serEng<<(int) ICType_UNKNOWN; 00189 } 00190 00191 } 00192 00193 IdentityConstraint* IdentityConstraint::loadIC(XSerializeEngine& serEng) 00194 { 00195 00196 int type; 00197 serEng>>type; 00198 00199 switch((ICType)type) 00200 { 00201 case ICType_UNIQUE: 00202 IC_Unique* ic_unique; 00203 serEng>>ic_unique; 00204 return ic_unique; 00205 case ICType_KEY: 00206 IC_Key* ic_key; 00207 serEng>>ic_key; 00208 return ic_key; 00209 case ICType_KEYREF: 00210 IC_KeyRef* ic_keyref; 00211 serEng>>ic_keyref; 00212 return ic_keyref; 00213 case ICType_UNKNOWN: 00214 return 0; 00215 default: //we treat this same as UnKnown 00216 return 0; 00217 } 00218 00219 } 00220 00221 XERCES_CPP_NAMESPACE_END 00222