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: AbstractNumericValidator.cpp 471747 2006-11-06 14:31:56Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/datatype/AbstractNumericValidator.hpp> 00026 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp> 00027 #include <xercesc/util/XMLAbstractDoubleFloat.hpp> 00028 00029 XERCES_CPP_NAMESPACE_BEGIN 00030 00031 #define REPORT_VALUE_ERROR(val1, val2, except_code, manager) \ 00032 ThrowXMLwithMemMgr2(InvalidDatatypeValueException \ 00033 , except_code \ 00034 , val1->getFormattedString() \ 00035 , val2->getFormattedString() \ 00036 , manager); 00037 00038 // --------------------------------------------------------------------------- 00039 // Constructors and Destructor 00040 // --------------------------------------------------------------------------- 00041 AbstractNumericValidator::~AbstractNumericValidator() 00042 {} 00043 00044 AbstractNumericValidator::AbstractNumericValidator( 00045 DatatypeValidator* const baseValidator 00046 , RefHashTableOf<KVStringPair>* const facets 00047 , const int finalSet 00048 , const ValidatorType type 00049 , MemoryManager* const manager) 00050 :AbstractNumericFacetValidator(baseValidator, facets, finalSet, type, manager) 00051 { 00052 //do not invoke init() here !!! 00053 } 00054 00055 void AbstractNumericValidator::validate(const XMLCh* const content 00056 , ValidationContext* const context 00057 , MemoryManager* const manager) 00058 { 00059 checkContent(content, context, false, manager); 00060 } 00061 00062 void AbstractNumericValidator::boundsCheck(const XMLNumber* const theData 00063 , MemoryManager* const manager) 00064 { 00065 int thisFacetsDefined = getFacetsDefined(); 00066 int result; 00067 00068 if (thisFacetsDefined == 0) 00069 return; 00070 00071 // must be < MaxExclusive 00072 if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0 ) 00073 { 00074 result = compareValues(theData, getMaxExclusive()); 00075 if ( result != -1) 00076 { 00077 REPORT_VALUE_ERROR(theData 00078 , getMaxExclusive() 00079 , XMLExcepts::VALUE_exceed_maxExcl 00080 , manager) 00081 } 00082 } 00083 00084 // must be <= MaxInclusive 00085 if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0 ) 00086 { 00087 result = compareValues(theData, getMaxInclusive()); 00088 if (result == 1) 00089 { 00090 REPORT_VALUE_ERROR(theData 00091 , getMaxInclusive() 00092 , XMLExcepts::VALUE_exceed_maxIncl 00093 , manager) 00094 } 00095 } 00096 00097 // must be >= MinInclusive 00098 if ( (thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0 ) 00099 { 00100 result = compareValues(theData, getMinInclusive()); 00101 if (result == -1) 00102 { 00103 REPORT_VALUE_ERROR(theData 00104 , getMinInclusive() 00105 , XMLExcepts::VALUE_exceed_minIncl 00106 , manager) 00107 } 00108 } 00109 00110 // must be > MinExclusive 00111 if ( (thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0 ) 00112 { 00113 result = compareValues(theData, getMinExclusive()); 00114 if (result != 1) 00115 { 00116 REPORT_VALUE_ERROR(theData 00117 , getMinExclusive() 00118 , XMLExcepts::VALUE_exceed_minExcl 00119 , manager) 00120 } 00121 } 00122 } 00123 00124 const XMLCh* AbstractNumericValidator::getCanonicalRepresentation(const XMLCh* const rawData 00125 , MemoryManager* const memMgr 00126 , bool toValidate) const 00127 { 00128 MemoryManager* toUse = memMgr? memMgr : fMemoryManager; 00129 00130 if (toValidate) 00131 { 00132 AbstractNumericValidator* temp = (AbstractNumericValidator*) this; 00133 00134 try 00135 { 00136 temp->checkContent(rawData, 0, false, toUse); 00137 } 00138 catch (...) 00139 { 00140 return 0; 00141 } 00142 } 00143 00144 // XMLAbstractDoubleFloat::getCanonicalRepresentation handles 00145 // exceptional cases 00146 return XMLAbstractDoubleFloat::getCanonicalRepresentation(rawData, toUse); 00147 00148 } 00149 00150 /*** 00151 * Support for Serialization/De-serialization 00152 ***/ 00153 00154 IMPL_XSERIALIZABLE_NOCREATE(AbstractNumericValidator) 00155 00156 void AbstractNumericValidator::serialize(XSerializeEngine& serEng) 00157 { 00158 AbstractNumericFacetValidator::serialize(serEng); 00159 00160 /*** 00161 * Need not to do anything else here 00162 * 00163 * Note: its derivatives, Doubledv, Floatdv and Decimaldv writes 00164 * number type info into the binary data stream to be read 00165 * by AbstractNumericFacetVaildator during loading, therefore 00166 * this class can NOT write/read anything into/from the binary 00167 * data stream. 00168 * 00169 * Later on, if this class has to write/read something into/from 00170 * the binary data stream, we need to add a numberType data 00171 * to XMLNumber and let AbstractNumericFacetValidator to write/read 00172 * this number type info. 00173 ***/ 00174 } 00175 00176 XERCES_CPP_NAMESPACE_END 00177