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: FloatDatatypeValidator.cpp 676911 2008-07-15 13:27:32Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/datatype/FloatDatatypeValidator.hpp> 00026 #include <xercesc/validators/schema/SchemaSymbols.hpp> 00027 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp> 00028 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp> 00029 00030 XERCES_CPP_NAMESPACE_BEGIN 00031 00032 // --------------------------------------------------------------------------- 00033 // Constructors and Destructor 00034 // --------------------------------------------------------------------------- 00035 FloatDatatypeValidator::FloatDatatypeValidator(MemoryManager* const manager) 00036 :AbstractNumericValidator(0, 0, 0, DatatypeValidator::Float, manager) 00037 { 00038 setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL); 00039 setBounded(true); 00040 setFinite(true); 00041 setNumeric(true); 00042 } 00043 00044 FloatDatatypeValidator::FloatDatatypeValidator( 00045 DatatypeValidator* const baseValidator 00046 , RefHashTableOf<KVStringPair>* const facets 00047 , RefArrayVectorOf<XMLCh>* const enums 00048 , const int finalSet 00049 , MemoryManager* const manager) 00050 :AbstractNumericValidator(baseValidator, facets, finalSet, DatatypeValidator::Float, manager) 00051 { 00052 init(enums, manager); 00053 } 00054 00055 FloatDatatypeValidator::~FloatDatatypeValidator() 00056 {} 00057 00058 // ----------------------------------------------------------------------- 00059 // Compare methods 00060 // ----------------------------------------------------------------------- 00061 int FloatDatatypeValidator::compare(const XMLCh* const lValue 00062 , const XMLCh* const rValue 00063 , MemoryManager* const manager) 00064 { 00065 XMLFloat lObj(lValue, manager); 00066 XMLFloat rObj(rValue, manager); 00067 00068 return compareValues(&lObj, &rObj); 00069 } 00070 00071 DatatypeValidator* FloatDatatypeValidator::newInstance 00072 ( 00073 RefHashTableOf<KVStringPair>* const facets 00074 , RefArrayVectorOf<XMLCh>* const enums 00075 , const int finalSet 00076 , MemoryManager* const manager 00077 ) 00078 { 00079 return (DatatypeValidator*) new (manager) FloatDatatypeValidator(this, facets, enums, finalSet, manager); 00080 } 00081 00082 // ----------------------------------------------------------------------- 00083 // ctor provided to be used by derived classes 00084 // ----------------------------------------------------------------------- 00085 FloatDatatypeValidator::FloatDatatypeValidator(DatatypeValidator* const baseValidator 00086 , RefHashTableOf<KVStringPair>* const facets 00087 , const int finalSet 00088 , const ValidatorType type 00089 , MemoryManager* const manager) 00090 :AbstractNumericValidator(baseValidator, facets, finalSet, type, manager) 00091 { 00092 //do not invoke init here !!! 00093 } 00094 00095 int FloatDatatypeValidator::compareValues(const XMLNumber* const lValue 00096 , const XMLNumber* const rValue) 00097 { 00098 return XMLFloat::compareValues((XMLFloat*) lValue, (XMLFloat*) rValue); 00099 } 00100 00101 void FloatDatatypeValidator::setMaxInclusive(const XMLCh* const value) 00102 { 00103 fMaxInclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager); 00104 } 00105 00106 void FloatDatatypeValidator::setMaxExclusive(const XMLCh* const value) 00107 { 00108 fMaxExclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager); 00109 } 00110 00111 void FloatDatatypeValidator::setMinInclusive(const XMLCh* const value) 00112 { 00113 fMinInclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager); 00114 } 00115 00116 void FloatDatatypeValidator::setMinExclusive(const XMLCh* const value) 00117 { 00118 fMinExclusive = new (fMemoryManager) XMLFloat(value, fMemoryManager); 00119 } 00120 00121 void FloatDatatypeValidator::setEnumeration(MemoryManager* const manager) 00122 { 00123 // check 4.3.5.c0 must: enumeration values from the value space of base 00124 // 00125 // 1. shall be from base value space 00126 // 2. shall be from current value space as well ( shall go through boundsCheck() ) 00127 // 00128 if (!fStrEnumeration) 00129 return; 00130 00131 XMLSize_t i = 0; 00132 XMLSize_t enumLength = fStrEnumeration->size(); 00133 00134 FloatDatatypeValidator *numBase = (FloatDatatypeValidator*) getBaseValidator(); 00135 if (numBase) 00136 { 00137 try 00138 { 00139 for ( i = 0; i < enumLength; i++) 00140 { 00141 numBase->checkContent(fStrEnumeration->elementAt(i), (ValidationContext*)0, false, manager); 00142 } 00143 } 00144 catch (XMLException&) 00145 { 00146 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException 00147 , XMLExcepts::FACET_enum_base 00148 , fStrEnumeration->elementAt(i) 00149 , manager); 00150 00151 } 00152 } 00153 #if 0 00154 // spec says that only base has to checkContent 00155 // We put the this->checkContent in a separate loop 00156 // to not block original message with in that method. 00157 // 00158 for ( i = 0; i < enumLength; i++) 00159 { 00160 checkContent(fStrEnumeration->elementAt(i), (ValidationContext*)0, false, manager); 00161 } 00162 #endif 00163 00164 fEnumeration = new (fMemoryManager) RefVectorOf<XMLNumber>(enumLength, true, fMemoryManager); 00165 fEnumerationInherited = false; 00166 00167 for ( i = 0; i < enumLength; i++) 00168 { 00169 fEnumeration->insertElementAt(new (fMemoryManager) XMLFloat(fStrEnumeration->elementAt(i), fMemoryManager), i); 00170 } 00171 } 00172 00173 // ----------------------------------------------------------------------- 00174 // Abstract interface from AbstractNumericValidator 00175 // ----------------------------------------------------------------------- 00176 void FloatDatatypeValidator::checkContent(const XMLCh* const content 00177 , ValidationContext* const context 00178 , bool asBase 00179 , MemoryManager* const manager) 00180 { 00181 00182 //validate against base validator if any 00183 FloatDatatypeValidator *pBase = (FloatDatatypeValidator*) this->getBaseValidator(); 00184 if (pBase) 00185 pBase->checkContent(content, context, true, manager); 00186 00187 // we check pattern first 00188 if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) 00189 { 00190 if (getRegex()->matches(content, manager) ==false) 00191 { 00192 ThrowXMLwithMemMgr2(InvalidDatatypeValueException 00193 , XMLExcepts::VALUE_NotMatch_Pattern 00194 , content 00195 , getPattern() 00196 , manager); 00197 } 00198 } 00199 00200 // if this is a base validator, we only need to check pattern facet 00201 // all other facet were inherited by the derived type 00202 if (asBase) 00203 return; 00204 00205 XMLFloat theValue(content, manager); 00206 XMLFloat *theData = &theValue; 00207 00208 if (getEnumeration() != 0) 00209 { 00210 XMLSize_t i=0; 00211 XMLSize_t enumLength = getEnumeration()->size(); 00212 for ( ; i < enumLength; i++) 00213 { 00214 if (compareValues(theData, (XMLFloat*) getEnumeration()->elementAt(i))==0) 00215 break; 00216 } 00217 00218 if (i == enumLength) 00219 ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); 00220 } 00221 00222 boundsCheck(theData, manager); 00223 } 00224 00225 /*** 00226 * Support for Serialization/De-serialization 00227 ***/ 00228 00229 IMPL_XSERIALIZABLE_TOCREATE(FloatDatatypeValidator) 00230 00231 void FloatDatatypeValidator::serialize(XSerializeEngine& serEng) 00232 { 00233 /*** 00234 * Note: 00235 * 00236 * During storing, we need write the specific number 00237 * type info before calling base::serialize(). 00238 * 00239 * While loading, we do nothing here 00240 ***/ 00241 00242 if (serEng.isStoring()) 00243 { 00244 serEng<<(int) (XMLNumber::Float); 00245 } 00246 00247 AbstractNumericValidator::serialize(serEng); 00248 00249 } 00250 00251 XERCES_CPP_NAMESPACE_END 00252