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: AbstractNumericFacetValidator.cpp 471747 2006-11-06 14:31:56Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/datatype/AbstractNumericFacetValidator.hpp> 00026 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp> 00027 #include <xercesc/util/NumberFormatException.hpp> 00028 00029 //since we need to dynamically created each and every derivatives 00030 //during deserialization by XSerializeEngine>>Derivative, we got 00031 //to include all hpp 00032 #include <xercesc/util/XMLFloat.hpp> 00033 #include <xercesc/util/XMLDouble.hpp> 00034 #include <xercesc/util/XMLBigDecimal.hpp> 00035 #include <xercesc/util/XMLDateTime.hpp> 00036 #include <xercesc/internal/XTemplateSerializer.hpp> 00037 00038 XERCES_CPP_NAMESPACE_BEGIN 00039 00040 const int AbstractNumericFacetValidator::INDETERMINATE = 2; 00041 00042 #define REPORT_FACET_ERROR(val1, val2, except_code, manager) \ 00043 ThrowXMLwithMemMgr2(InvalidDatatypeFacetException \ 00044 , except_code \ 00045 , val1->getFormattedString() \ 00046 , val2->getFormattedString() \ 00047 , manager); 00048 00049 #define FROM_BASE_VALUE_SPACE(val, facetFlag, except_code, manager) \ 00050 if ((thisFacetsDefined & facetFlag) != 0) \ 00051 { \ 00052 try \ 00053 { \ 00054 numBase->checkContent(val->getRawData(), (ValidationContext*)0, false, manager); \ 00055 } \ 00056 catch ( XMLException& ) \ 00057 { \ 00058 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException \ 00059 , except_code \ 00060 , val->getRawData() \ 00061 , manager); \ 00062 } \ 00063 } 00064 00065 00066 // --------------------------------------------------------------------------- 00067 // Constructors and Destructor 00068 // --------------------------------------------------------------------------- 00069 AbstractNumericFacetValidator::~AbstractNumericFacetValidator() 00070 { 00071 if (!fMaxInclusiveInherited && fMaxInclusive) 00072 delete fMaxInclusive; 00073 00074 if (!fMaxExclusiveInherited && fMaxExclusive) 00075 delete fMaxExclusive; 00076 00077 if (!fMinInclusiveInherited && fMinInclusive) 00078 delete fMinInclusive; 00079 00080 if (!fMinExclusiveInherited && fMinExclusive) 00081 delete fMinExclusive; 00082 00083 //~RefVectorOf will delete all adopted elements 00084 if (!fEnumerationInherited && fEnumeration) 00085 delete fEnumeration; 00086 00087 if (!fEnumerationInherited && fStrEnumeration) 00088 delete fStrEnumeration; 00089 } 00090 00091 AbstractNumericFacetValidator::AbstractNumericFacetValidator( 00092 DatatypeValidator* const baseValidator 00093 , RefHashTableOf<KVStringPair>* const facets 00094 , const int finalSet 00095 , const ValidatorType type 00096 , MemoryManager* const manager) 00097 :DatatypeValidator(baseValidator, facets, finalSet, type, manager) 00098 , fMaxInclusiveInherited(false) 00099 , fMaxExclusiveInherited(false) 00100 , fMinInclusiveInherited(false) 00101 , fMinExclusiveInherited(false) 00102 , fEnumerationInherited(false) 00103 , fMaxInclusive(0) 00104 , fMaxExclusive(0) 00105 , fMinInclusive(0) 00106 , fMinExclusive(0) 00107 , fEnumeration(0) 00108 , fStrEnumeration(0) 00109 { 00110 //do not invoke init() here !!! 00111 } 00112 00113 // 00114 // P1. Enumeration 00115 // 00116 void AbstractNumericFacetValidator::init(RefArrayVectorOf<XMLCh>* const enums 00117 , MemoryManager* const manager) 00118 { 00119 00120 fStrEnumeration = enums; // save the literal value 00121 // which is needed for getEnumString() 00122 00123 if (enums) 00124 { 00125 setFacetsDefined(DatatypeValidator::FACET_ENUMERATION); 00126 } 00127 00128 assignFacet(manager); 00129 inspectFacet(manager); 00130 inspectFacetBase(manager); 00131 inheritFacet(); 00132 } 00133 00134 // 00135 // Assign facets 00136 // assign common facets 00137 // assign additional facet 00138 // 00139 void AbstractNumericFacetValidator::assignFacet(MemoryManager* const manager) 00140 { 00141 00142 RefHashTableOf<KVStringPair>* facets = getFacets(); 00143 00144 if (!facets) // no facets defined 00145 return; 00146 00147 XMLCh* key; 00148 00149 RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); 00150 00151 while (e.hasMoreElements()) 00152 { 00153 KVStringPair pair = e.nextElement(); 00154 key = pair.getKey(); 00155 XMLCh* value = pair.getValue(); 00156 00157 if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) 00158 { 00159 setPattern(value); 00160 if (getPattern()) 00161 setFacetsDefined(DatatypeValidator::FACET_PATTERN); 00162 // do not construct regex until needed 00163 } 00164 else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXINCLUSIVE)) 00165 { 00166 try 00167 { 00168 setMaxInclusive(value); 00169 } 00170 catch (NumberFormatException&) 00171 { 00172 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxIncl, value, manager); 00173 } 00174 setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE); 00175 } 00176 else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXEXCLUSIVE)) 00177 { 00178 try 00179 { 00180 setMaxExclusive(value); 00181 } 00182 catch (NumberFormatException&) 00183 { 00184 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxExcl, value, manager); 00185 } 00186 setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE); 00187 } 00188 else if (XMLString::equals(key, SchemaSymbols::fgELT_MININCLUSIVE)) 00189 { 00190 try 00191 { 00192 setMinInclusive(value); 00193 } 00194 catch (NumberFormatException&) 00195 { 00196 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinIncl, value, manager); 00197 } 00198 setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE); 00199 } 00200 else if (XMLString::equals(key, SchemaSymbols::fgELT_MINEXCLUSIVE)) 00201 { 00202 try 00203 { 00204 setMinExclusive(value); 00205 } 00206 catch (NumberFormatException&) 00207 { 00208 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinExcl, value, manager); 00209 } 00210 setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE); 00211 } 00212 else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) 00213 { 00214 unsigned int val; 00215 bool retStatus; 00216 try 00217 { 00218 retStatus = XMLString::textToBin(value, val, fMemoryManager); 00219 } 00220 catch (RuntimeException&) 00221 { 00222 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); 00223 } 00224 00225 if (!retStatus) 00226 { 00227 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); 00228 } 00229 00230 setFixed(val); 00231 //no setFacetsDefined here 00232 00233 } 00234 else 00235 { 00236 assignAdditionalFacet(key, value, manager); 00237 } 00238 00239 }//while 00240 00241 }// end of assigneFacet() 00242 00243 // 00244 // Check facet among self 00245 // check common facets 00246 // check Additional Facet Constraint 00247 // 00248 void AbstractNumericFacetValidator::inspectFacet(MemoryManager* const manager) 00249 { 00250 00251 int thisFacetsDefined = getFacetsDefined(); 00252 XMLNumber *thisMaxInclusive = getMaxInclusive(); 00253 XMLNumber *thisMaxExclusive = getMaxExclusive(); 00254 XMLNumber *thisMinInclusive = getMinInclusive(); 00255 XMLNumber *thisMinExclusive = getMinExclusive(); 00256 00257 if (!thisFacetsDefined) 00258 return; 00259 00260 // non co-existence checking 00261 // check 4.3.8.c1 error: maxInclusive + maxExclusive 00262 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && 00263 ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) ) 00264 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_max_Incl_Excl, manager); 00265 00266 // non co-existence checking 00267 // check 4.3.9.c1 error: minInclusive + minExclusive 00268 if (((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) && 00269 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) 00270 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_min_Incl_Excl, manager); 00271 00272 // 00273 // minExclusive < minInclusive <= maxInclusive < maxExclusive 00274 // 00275 // check 4.3.7.c1 must: minInclusive <= maxInclusive 00276 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && 00277 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) 00278 { 00279 int result = compareValues(thisMinInclusive, thisMaxInclusive); 00280 if ( result == 1 || result == INDETERMINATE ) 00281 { 00282 REPORT_FACET_ERROR(thisMinInclusive 00283 , thisMaxInclusive 00284 , XMLExcepts::FACET_maxIncl_minIncl 00285 , manager) 00286 } 00287 } 00288 00289 // check 4.3.8.c2 must: minExclusive <= maxExclusive 00290 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && 00291 ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) ) 00292 { 00293 int result = compareValues(getMinExclusive(), getMaxExclusive()); 00294 if ( result == 1 || result == INDETERMINATE ) 00295 { 00296 REPORT_FACET_ERROR(thisMinExclusive 00297 , thisMaxExclusive 00298 , XMLExcepts::FACET_maxExcl_minExcl 00299 , manager) 00300 } 00301 } 00302 00303 // check 4.3.9.c2 must: minExclusive < maxInclusive 00304 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && 00305 ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) ) 00306 { 00307 int result = compareValues(getMinExclusive(), getMaxInclusive()); 00308 if ( result != -1 ) 00309 { 00310 REPORT_FACET_ERROR(thisMinExclusive 00311 , thisMaxInclusive 00312 , XMLExcepts::FACET_maxIncl_minExcl 00313 , manager) 00314 } 00315 } 00316 00317 // check 4.3.10.c1 must: minInclusive < maxExclusive 00318 if ( ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && 00319 ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) 00320 { 00321 int result = compareValues(getMinInclusive(), getMaxExclusive()); 00322 if ( result != -1) 00323 { 00324 REPORT_FACET_ERROR(thisMinInclusive 00325 , thisMaxExclusive 00326 , XMLExcepts::FACET_maxExcl_minIncl 00327 , manager) 00328 } 00329 } 00330 00331 checkAdditionalFacetConstraints(manager); 00332 00333 }// end of inspectFacet() 00334 00335 // 00336 // Check vs base 00337 // check common facets 00338 // check enumeration 00339 // check Additional Facet Constraint 00340 // 00341 void AbstractNumericFacetValidator::inspectFacetBase(MemoryManager* const manager) 00342 { 00343 00344 AbstractNumericFacetValidator* numBase = (AbstractNumericFacetValidator*) getBaseValidator(); 00345 int thisFacetsDefined = getFacetsDefined(); 00346 00347 if ( (!thisFacetsDefined && !fEnumeration) || 00348 !numBase ) 00349 return; 00350 00351 int baseFacetsDefined = numBase->getFacetsDefined(); 00352 00353 XMLNumber *thisMaxInclusive = getMaxInclusive(); 00354 XMLNumber *thisMaxExclusive = getMaxExclusive(); 00355 XMLNumber *thisMinInclusive = getMinInclusive(); 00356 XMLNumber *thisMinExclusive = getMinExclusive(); 00357 00358 XMLNumber *baseMaxInclusive = numBase->getMaxInclusive(); 00359 XMLNumber *baseMaxExclusive = numBase->getMaxExclusive(); 00360 XMLNumber *baseMinInclusive = numBase->getMinInclusive(); 00361 XMLNumber *baseMinExclusive = numBase->getMinExclusive(); 00362 int baseFixed = numBase->getFixed(); 00363 00364 // this 00365 // minExclusive maxExclusive 00366 // minInclusive maxInclusive 00367 // 00368 // base 00369 // minExclusive maxExclusive 00370 // minInclusive maxInclusive 00371 // 00372 00373 // check 4.3.7.c2 error: 00374 // maxInclusive > base.maxInclusive && maxInclusive != base.maxInclusive if (base.fixed) 00375 // maxInclusive >= base.maxExclusive 00376 // maxInclusive < base.minInclusive 00377 // maxInclusive <= base.minExclusive 00378 00379 if ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) 00380 { 00381 if ((baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) 00382 { 00383 int result = compareValues(thisMaxInclusive, baseMaxInclusive); 00384 00385 if (((baseFixed & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && 00386 (result != 0 )) 00387 { 00388 REPORT_FACET_ERROR(thisMaxInclusive 00389 , baseMaxInclusive 00390 , XMLExcepts::FACET_maxIncl_base_fixed 00391 , manager) 00392 } 00393 00394 if (result == 1 || result == INDETERMINATE) 00395 { 00396 REPORT_FACET_ERROR(thisMaxInclusive 00397 , baseMaxInclusive 00398 , XMLExcepts::FACET_maxIncl_base_maxIncl 00399 , manager) 00400 } 00401 00402 } 00403 00404 if ((baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) 00405 { 00406 int result = compareValues(thisMaxInclusive, baseMaxExclusive); 00407 if (result != -1 ) 00408 { 00409 REPORT_FACET_ERROR(thisMaxInclusive 00410 , baseMaxExclusive 00411 , XMLExcepts::FACET_maxIncl_base_maxExcl 00412 , manager) 00413 } 00414 } 00415 00416 00417 if ((baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) 00418 { 00419 int result = compareValues(thisMaxInclusive, baseMinInclusive); 00420 if (result == -1 || result == INDETERMINATE) 00421 { 00422 REPORT_FACET_ERROR(thisMaxInclusive 00423 , baseMinInclusive 00424 , XMLExcepts::FACET_maxIncl_base_minIncl 00425 , manager) 00426 } 00427 } 00428 00429 if ((baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) 00430 { 00431 int result = compareValues(thisMaxInclusive, baseMinExclusive); 00432 if (result != 1 ) 00433 { 00434 REPORT_FACET_ERROR(thisMaxInclusive 00435 , baseMinExclusive 00436 , XMLExcepts::FACET_maxIncl_base_minExcl 00437 , manager) 00438 } 00439 } 00440 00441 } 00442 00443 // check 4.3.8.c3 error: 00444 // maxExclusive > base.maxExclusive && maxExclusive != base.maxExclusive if (base.fixed) 00445 // maxExclusive > base.maxInclusive 00446 // maxExclusive <= base.minInclusive 00447 // maxExclusive <= base.minExclusive 00448 00449 if ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) 00450 { 00451 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) 00452 { 00453 int result = compareValues(thisMaxExclusive, baseMaxExclusive); 00454 00455 if (((baseFixed & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && 00456 (result != 0 )) 00457 { 00458 REPORT_FACET_ERROR(thisMaxExclusive 00459 , baseMaxExclusive 00460 , XMLExcepts::FACET_maxExcl_base_fixed 00461 , manager) 00462 } 00463 00464 if (result == 1 || result == INDETERMINATE) 00465 { 00466 REPORT_FACET_ERROR(thisMaxExclusive 00467 , baseMaxExclusive 00468 , XMLExcepts::FACET_maxExcl_base_maxExcl 00469 , manager) 00470 } 00471 00481 if (result != 0) 00482 { 00483 FROM_BASE_VALUE_SPACE(thisMaxExclusive 00484 , DatatypeValidator::FACET_MAXEXCLUSIVE 00485 , XMLExcepts::FACET_maxExcl_notFromBase 00486 , manager) 00487 } 00488 } 00489 else // base has no maxExclusive 00490 { 00491 FROM_BASE_VALUE_SPACE(thisMaxExclusive 00492 , DatatypeValidator::FACET_MAXEXCLUSIVE 00493 , XMLExcepts::FACET_maxExcl_notFromBase 00494 , manager) 00495 } 00496 00497 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) 00498 { 00499 int result = compareValues(thisMaxExclusive, baseMaxInclusive); 00500 if (result == 1 || result == INDETERMINATE) 00501 { 00502 REPORT_FACET_ERROR(thisMaxExclusive 00503 , baseMaxInclusive 00504 , XMLExcepts::FACET_maxExcl_base_maxIncl 00505 , manager) 00506 } 00507 } 00508 00509 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) 00510 { 00511 int result = compareValues(thisMaxExclusive, baseMinExclusive); 00512 if (result != 1) 00513 { 00514 REPORT_FACET_ERROR(thisMaxExclusive 00515 , baseMinExclusive 00516 , XMLExcepts::FACET_maxExcl_base_minExcl 00517 , manager) 00518 } 00519 } 00520 00521 if (( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) 00522 { 00523 int result = compareValues(thisMaxExclusive, baseMinInclusive); 00524 if (result != 1) 00525 { 00526 REPORT_FACET_ERROR(thisMaxExclusive 00527 , baseMinInclusive 00528 , XMLExcepts::FACET_maxExcl_base_minIncl 00529 , manager) 00530 } 00531 } 00532 } 00533 00534 // check 4.3.9.c3 error: 00535 // minExclusive < base.minExclusive minExclusive != base.minExclusive if (base.fixed) 00536 // minExclusive > base.maxInclusive ??? minExclusive >= base.maxInclusive 00537 // minExclusive < base.minInclusive 00538 // minExclusive >= base.maxExclusive 00539 00540 if ((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) 00541 { 00542 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) 00543 { 00544 int result = compareValues(thisMinExclusive, baseMinExclusive); 00545 00546 if (((baseFixed & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) && 00547 (result != 0 )) 00548 { 00549 REPORT_FACET_ERROR(thisMinExclusive 00550 , baseMinExclusive 00551 , XMLExcepts::FACET_minExcl_base_fixed 00552 , manager) 00553 } 00554 00555 if (result == -1 || result == INDETERMINATE) 00556 { 00557 REPORT_FACET_ERROR(thisMinExclusive 00558 , baseMinExclusive 00559 , XMLExcepts::FACET_minExcl_base_minExcl 00560 , manager) 00561 } 00562 00573 if (result != 0) 00574 { 00575 FROM_BASE_VALUE_SPACE(thisMinExclusive 00576 , DatatypeValidator::FACET_MINEXCLUSIVE 00577 , XMLExcepts::FACET_minExcl_notFromBase 00578 , manager) 00579 } 00580 } 00581 else // base has no minExclusive 00582 { 00583 00584 FROM_BASE_VALUE_SPACE(thisMinExclusive 00585 , DatatypeValidator::FACET_MINEXCLUSIVE 00586 , XMLExcepts::FACET_minExcl_notFromBase 00587 , manager) 00588 } 00589 00590 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) 00591 { 00592 int result = compareValues(thisMinExclusive, baseMaxInclusive); 00593 if (result == 1 || result == INDETERMINATE) 00594 { 00595 REPORT_FACET_ERROR(thisMinExclusive 00596 , baseMaxInclusive 00597 , XMLExcepts::FACET_minExcl_base_maxIncl 00598 , manager) 00599 } 00600 } 00601 00602 if (( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) 00603 { 00604 int result = compareValues(thisMinExclusive, baseMinInclusive); 00605 if (result == -1 || result == INDETERMINATE) 00606 { 00607 REPORT_FACET_ERROR(thisMinExclusive 00608 , baseMinInclusive 00609 , XMLExcepts::FACET_minExcl_base_minIncl 00610 , manager) 00611 } 00612 } 00613 00614 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) 00615 { 00616 int result = compareValues(thisMinExclusive, baseMaxExclusive); 00617 if (result != -1) 00618 { 00619 REPORT_FACET_ERROR(thisMinExclusive 00620 , baseMaxExclusive 00621 , XMLExcepts::FACET_minExcl_base_maxExcl 00622 , manager) 00623 } 00624 } 00625 00626 } 00627 00628 // check 4.3.10.c2 error: 00629 // minInclusive < base.minInclusive minInclusive != base.minInclusive if (base.fixed) 00630 // minInclusive > base.maxInclusive 00631 // minInclusive <= base.minExclusive 00632 // minInclusive >= base.maxExclusive 00633 00634 00635 if ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) 00636 { 00637 if ((baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) 00638 { 00639 int result = compareValues(thisMinInclusive, baseMinInclusive); 00640 00641 if (((baseFixed & DatatypeValidator::FACET_MININCLUSIVE) != 0) && 00642 (result != 0 )) 00643 { 00644 REPORT_FACET_ERROR(thisMinInclusive 00645 , baseMinInclusive 00646 , XMLExcepts::FACET_minIncl_base_fixed 00647 , manager) 00648 } 00649 00650 if (result == -1 || result == INDETERMINATE) 00651 { 00652 REPORT_FACET_ERROR(thisMinInclusive 00653 , baseMinInclusive 00654 , XMLExcepts::FACET_minIncl_base_minIncl 00655 , manager) 00656 } 00657 } 00658 00659 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) 00660 { 00661 int result = compareValues(thisMinInclusive, baseMaxInclusive); 00662 if (result == 1 || result == INDETERMINATE) 00663 { 00664 REPORT_FACET_ERROR(thisMinInclusive 00665 , baseMaxInclusive 00666 , XMLExcepts::FACET_minIncl_base_maxIncl 00667 , manager) 00668 } 00669 } 00670 00671 if (( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) 00672 { 00673 int result = compareValues(thisMinInclusive, baseMinExclusive); 00674 if (result != 1) 00675 { 00676 REPORT_FACET_ERROR(thisMinInclusive 00677 , baseMinExclusive 00678 , XMLExcepts::FACET_minIncl_base_minExcl 00679 , manager) 00680 } 00681 } 00682 00683 if (( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) 00684 { 00685 int result = compareValues(thisMinInclusive, baseMaxExclusive); 00686 if (result != -1) 00687 { 00688 REPORT_FACET_ERROR(thisMinInclusive 00689 , baseMaxExclusive 00690 , XMLExcepts::FACET_minIncl_base_maxExcl 00691 , manager) 00692 } 00693 } 00694 00695 } 00696 00697 checkAdditionalFacetConstraintsBase(manager); 00698 00699 // check 4.3.5.c0 must: enumeration values from the value space of base 00700 // 00701 // In fact, the values in the enumeration shall go through validation 00702 // of this class as well. 00703 // this->checkContent(value, false); 00704 // 00705 if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) && 00706 ( fStrEnumeration )) 00707 { 00708 setEnumeration(manager); 00709 } 00710 00711 // 00712 // maxInclusive, maxExclusive, minInclusive and minExclusive 00713 // shall come from the base's value space as well 00714 // 00715 00716 FROM_BASE_VALUE_SPACE(thisMaxInclusive 00717 , DatatypeValidator::FACET_MAXINCLUSIVE 00718 , XMLExcepts::FACET_maxIncl_notFromBase 00719 , manager) 00720 00721 FROM_BASE_VALUE_SPACE(thisMinInclusive 00722 , DatatypeValidator::FACET_MININCLUSIVE 00723 , XMLExcepts::FACET_minIncl_notFromBase 00724 , manager) 00725 00726 } //end of inspectFacetBase 00727 00728 // 00729 // Inherit facet from base 00730 // a. inherit common facets 00731 // b. inherit additional facet 00732 // 00733 void AbstractNumericFacetValidator::inheritFacet() 00734 { 00735 00736 AbstractNumericFacetValidator* numBase = (AbstractNumericFacetValidator*) getBaseValidator(); 00737 if (!numBase) 00738 return; 00739 00740 int thisFacetsDefined = getFacetsDefined(); 00741 int baseFacetsDefined = numBase->getFacetsDefined(); 00742 00743 // inherit enumeration 00744 if ((( baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) && 00745 (( thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0)) 00746 { 00747 fEnumeration = numBase->fEnumeration; 00748 fEnumerationInherited = true; 00749 setFacetsDefined(DatatypeValidator::FACET_ENUMERATION); 00750 } 00751 00752 // inherit maxInclusive 00753 if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && 00754 (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) && 00755 (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) ) 00756 { 00757 fMaxInclusive = numBase->getMaxInclusive(); 00758 fMaxInclusiveInherited = true; 00759 setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE); 00760 } 00761 00762 // inherit maxExclusive 00763 if ((( baseFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && 00764 (( thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) == 0) && 00765 (( thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) == 0) ) 00766 { 00767 fMaxExclusive = numBase->getMaxExclusive(); 00768 fMaxExclusiveInherited = true; 00769 setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE); 00770 } 00771 00772 // inherit minExclusive 00773 if ((( baseFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) && 00774 (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) && 00775 (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) ) 00776 { 00777 fMinInclusive = numBase->getMinInclusive(); 00778 fMinInclusiveInherited = true; 00779 setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE); 00780 } 00781 00782 // inherit minExclusive 00783 if ((( baseFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) && 00784 (( thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) == 0) && 00785 (( thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) == 0) ) 00786 { 00787 fMinExclusive = numBase->getMinExclusive(); 00788 fMinExclusiveInherited = true; 00789 setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE); 00790 } 00791 00792 inheritAdditionalFacet(); 00793 00794 // inherit "fixed" option 00795 setFixed(getFixed() | numBase->getFixed()); 00796 00797 } 00798 00799 const RefArrayVectorOf<XMLCh>* AbstractNumericFacetValidator::getEnumString() const 00800 { 00801 return (fEnumerationInherited? getBaseValidator()->getEnumString() : fStrEnumeration ); 00802 } 00803 00804 00805 void AbstractNumericFacetValidator::checkAdditionalFacetConstraints(MemoryManager* const) const 00806 { 00807 return; 00808 } 00809 00810 void AbstractNumericFacetValidator::checkAdditionalFacetConstraintsBase(MemoryManager* const) const 00811 { 00812 return; 00813 } 00814 00815 void AbstractNumericFacetValidator::inheritAdditionalFacet() 00816 { 00817 return; 00818 } 00819 00820 void AbstractNumericFacetValidator::assignAdditionalFacet( const XMLCh* const key 00821 , const XMLCh* const 00822 , MemoryManager* const manager) 00823 { 00824 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException 00825 , XMLExcepts::FACET_Invalid_Tag 00826 , key 00827 , manager); 00828 } 00829 00830 00831 00832 /*** 00833 * Support for Serialization/De-serialization 00834 ***/ 00835 00836 IMPL_XSERIALIZABLE_NOCREATE(AbstractNumericFacetValidator) 00837 00838 /*** 00839 * This dv needs to serialize/deserialize four boundary data members 00840 * which are derivatives of XMLlNumber. 00841 * The derivatives of this class, namely, Deciamldv, Doubledv, Floatdv and 00842 * DateTimedv needs to write a typeEnum into the binary data stream, so 00843 * during loading, this method reads the typeEnum first, and then instantiate 00844 * the right type of objects, say XMLDouble, XMLFloat, XMLBigDecimal and 00845 * XMLDateTime. 00846 * 00847 * 00848 ***/ 00849 void AbstractNumericFacetValidator::serialize(XSerializeEngine& serEng) 00850 { 00851 00852 if (serEng.isStoring()) 00853 { 00854 00855 /*** 00856 * don't move this line out of the if statement, 00857 * it is done purposely to allow AbstractNumericFacetValidator 00858 * read the number type information before DatatypeValidator 00859 * during loading 00860 ***/ 00861 DatatypeValidator::serialize(serEng); 00862 00863 // need not write type info for the XMLNumber since 00864 // the derivative class has done that 00865 storeClusive(serEng, fMaxInclusiveInherited, fMaxInclusive); 00866 storeClusive(serEng, fMaxExclusiveInherited, fMaxExclusive); 00867 storeClusive(serEng, fMinInclusiveInherited, fMinInclusive); 00868 storeClusive(serEng, fMinExclusiveInherited, fMinExclusive); 00869 00870 serEng<<fEnumerationInherited; 00871 00872 /*** 00873 * Serialize RefArrayVectorOf<XMLCh> 00874 * Serialize RefVectorOf<XMLNumber> 00875 ***/ 00876 XTemplateSerializer::storeObject(fStrEnumeration, serEng); 00877 XTemplateSerializer::storeObject(fEnumeration, serEng); 00878 00879 } 00880 else 00881 { 00882 // Read the number type info for the XMLNumber FIRST!!! 00883 int nType; 00884 XMLNumber::NumberType numType; 00885 serEng>>nType; 00886 numType = (XMLNumber::NumberType) nType; 00887 00888 DatatypeValidator::serialize(serEng); 00889 00890 loadClusive(serEng, fMaxInclusiveInherited, fMaxInclusive, numType, 1); 00891 loadClusive(serEng, fMaxExclusiveInherited, fMaxExclusive, numType, 2); 00892 loadClusive(serEng, fMinInclusiveInherited, fMinInclusive, numType, 3); 00893 loadClusive(serEng, fMinExclusiveInherited, fMinExclusive, numType, 4); 00894 00895 serEng>>fEnumerationInherited; 00896 00897 /*** 00898 * Deserialize RefArrayVectorOf<XMLCh> 00899 * Deserialize RefVectorOf<XMLNumber> 00900 ***/ 00901 XTemplateSerializer::loadObject(&fStrEnumeration, 8, true, serEng); 00902 XTemplateSerializer::loadObject(&fEnumeration, 8, true, numType, serEng); 00903 00904 } 00905 00906 } 00907 00908 // 00909 // A user defined dv may inherit any of the Max/Min/Inc/Exc from a 00910 // built dv, which will create its own Max/Min/Inc/Exc during the 00911 // loading. Therefore if the user defined store and load this 00912 // facet, and does not own it, that will cause leakage. 00913 // 00914 // To avoid checking if the facet belongs to a builtIn dv or not, we 00915 // do this way, for any inherited *clusive, we will not store it, and later 00916 // on during loading, we get it from the base dv. 00917 // 00918 void AbstractNumericFacetValidator::storeClusive(XSerializeEngine& serEng 00919 , bool inherited 00920 , XMLNumber* data) 00921 { 00922 serEng<<inherited; 00923 00924 //store only if own it 00925 if (!inherited) 00926 serEng<<data; 00927 00928 } 00929 00930 // it is guranteed that the base dv is loaded before this dv 00931 // 00932 void AbstractNumericFacetValidator::loadClusive(XSerializeEngine& serEng 00933 , bool& inherited 00934 , XMLNumber*& data 00935 , XMLNumber::NumberType numType 00936 , int flag) 00937 { 00938 serEng>>inherited; 00939 00940 if (!inherited) 00941 data = XMLNumber::loadNumber(numType, serEng); 00942 else 00943 { 00944 AbstractNumericFacetValidator* basedv = (AbstractNumericFacetValidator*) getBaseValidator(); 00945 00946 switch(flag) 00947 { 00948 case 1: 00949 data = basedv->getMaxInclusive(); 00950 break; 00951 case 2: 00952 data = basedv->getMaxExclusive(); 00953 break; 00954 case 3: 00955 data = basedv->getMinInclusive(); 00956 break; 00957 case 4: 00958 data = basedv->getMinExclusive(); 00959 break; 00960 default: 00961 break; 00962 } 00963 00964 } 00965 00966 } 00967 00968 XERCES_CPP_NAMESPACE_END 00969