abstractnumericfacetvalidator.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,053 行 · 第 1/3 页
CPP
1,053 行
/* * Copyright 2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: AbstractNumericFacetValidator.cpp,v 1.20 2004/09/08 13:56:52 peiyongz Exp $ * $Log: AbstractNumericFacetValidator.cpp,v $ * Revision 1.20 2004/09/08 13:56:52 peiyongz * Apache License Version 2.0 * * Revision 1.19 2004/03/19 01:18:08 peiyongz * Let base dv to store/load (Max,Min)(Inc,Exc)sives * * Revision 1.18 2004/01/29 11:51:22 cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.17 2003/12/17 00:18:38 cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * * Revision 1.16 2003/11/12 20:32:03 peiyongz * Statless Grammar: ValidationContext * * Revision 1.15 2003/10/17 21:13:43 peiyongz * using XTemplateSerializer * * Revision 1.14 2003/10/07 19:39:37 peiyongz * Use of Template_Class Object Serialization/Deserialization API * * Revision 1.13 2003/10/02 19:21:06 peiyongz * Implementation of Serialization/Deserialization * * Revision 1.12 2003/05/15 18:53:26 knoaman * Partial implementation of the configurable memory manager. * * Revision 1.11 2003/02/03 16:34:35 peiyongz * fix to misplaced derived and base value in error message. * * Revision 1.10 2003/02/02 23:55:40 peiyongz * getFormattedString() added to return original and converted value. * * Revision 1.9 2003/01/30 21:56:22 tng * Performance: call getRawData instead of toString * * Revision 1.8 2003/01/25 16:33:25 peiyongz * wrong error code. * * Revision 1.7 2002/12/18 14:17:55 gareth * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf. * * Revision 1.6 2002/11/26 22:19:15 peiyongz * Schema Errata E2-16 maxExclusive * * Revision 1.5 2002/11/04 14:53:27 tng * C++ Namespace Support. * * Revision 1.4 2002/09/24 19:44:40 tng * Performance: use XMLString::equals instead of XMLString::compareString * * Revision 1.3 2002/04/01 20:17:46 peiyongz * Bug#7551: Exceptions are caught by value, rather than by reference * * Revision 1.2 2002/02/14 15:17:31 peiyongz * getEnumString() * * Revision 1.1.1.1 2002/02/01 22:22:39 peiyongz * sane_include * * Revision 1.6 2001/12/13 16:48:29 peiyongz * Avoid dangling pointer * * Revision 1.5 2001/12/10 22:13:21 peiyongz * swap checking to avoid "dangling pointer" reported by BoundsChecker * * Revision 1.4 2001/11/12 20:37:57 peiyongz * SchemaDateTimeException defined * * Revision 1.3 2001/10/16 16:29:34 tng * Schema: Fix Typo * * Revision 1.2 2001/10/09 21:17:41 peiyongz * . macro to simplify code * .save get***() to temp vars. * * Revision 1.1 2001/10/01 16:13:56 peiyongz * DTV Reorganization:new classes: AbstractNumericFactValidator/ AbstractNumericValidator * */// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include <xercesc/validators/datatype/AbstractNumericFacetValidator.hpp>#include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>#include <xercesc/util/NumberFormatException.hpp>//since we need to dynamically created each and every derivatives //during deserialization by XSerializeEngine>>Derivative, we got//to include all hpp#include <xercesc/util/XMLFloat.hpp>#include <xercesc/util/XMLDouble.hpp>#include <xercesc/util/XMLBigDecimal.hpp>#include <xercesc/util/XMLDateTime.hpp>#include <xercesc/internal/XTemplateSerializer.hpp>XERCES_CPP_NAMESPACE_BEGINconst int AbstractNumericFacetValidator::INDETERMINATE = 2;#define REPORT_FACET_ERROR(val1, val2, except_code, manager) \ ThrowXMLwithMemMgr2(InvalidDatatypeFacetException \ , except_code \ , val1->getFormattedString() \ , val2->getFormattedString() \ , manager);#define FROM_BASE_VALUE_SPACE(val, facetFlag, except_code, manager) \ if ((thisFacetsDefined & facetFlag) != 0) \{ \ try \{ \ numBase->checkContent(val->getRawData(), (ValidationContext*)0, false, manager); \} \ catch ( XMLException& ) \{ \ ThrowXMLwithMemMgr1(InvalidDatatypeFacetException \ , except_code \ , val->getRawData() \ , manager); \} \}// ---------------------------------------------------------------------------// Constructors and Destructor// ---------------------------------------------------------------------------AbstractNumericFacetValidator::~AbstractNumericFacetValidator(){ if (!fMaxInclusiveInherited && fMaxInclusive) delete fMaxInclusive; if (!fMaxExclusiveInherited && fMaxExclusive) delete fMaxExclusive; if (!fMinInclusiveInherited && fMinInclusive) delete fMinInclusive; if (!fMinExclusiveInherited && fMinExclusive) delete fMinExclusive; //~RefVectorOf will delete all adopted elements if (!fEnumerationInherited && fEnumeration) delete fEnumeration; if (!fEnumerationInherited && fStrEnumeration) delete fStrEnumeration;}AbstractNumericFacetValidator::AbstractNumericFacetValidator( DatatypeValidator* const baseValidator , RefHashTableOf<KVStringPair>* const facets , const int finalSet , const ValidatorType type , MemoryManager* const manager):DatatypeValidator(baseValidator, facets, finalSet, type, manager), fMaxInclusiveInherited(false), fMaxExclusiveInherited(false), fMinInclusiveInherited(false), fMinExclusiveInherited(false), fEnumerationInherited(false), fMaxInclusive(0), fMaxExclusive(0), fMinInclusive(0), fMinExclusive(0), fEnumeration(0), fStrEnumeration(0){ //do not invoke init() here !!!}//// P1. Enumeration//void AbstractNumericFacetValidator::init(RefArrayVectorOf<XMLCh>* const enums , MemoryManager* const manager){ fStrEnumeration = enums; // save the literal value // which is needed for getEnumString() if (enums) { setFacetsDefined(DatatypeValidator::FACET_ENUMERATION); } assignFacet(manager); inspectFacet(manager); inspectFacetBase(manager); inheritFacet();}//// Assign facets// assign common facets// assign additional facet//void AbstractNumericFacetValidator::assignFacet(MemoryManager* const manager){ RefHashTableOf<KVStringPair>* facets = getFacets(); if (!facets) // no facets defined return; XMLCh* key; XMLCh* value; RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); while (e.hasMoreElements()) { KVStringPair pair = e.nextElement(); key = pair.getKey(); value = pair.getValue(); if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) { setPattern(value); if (getPattern()) setFacetsDefined(DatatypeValidator::FACET_PATTERN); // do not construct regex until needed } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXINCLUSIVE)) { try { setMaxInclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxIncl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MAXINCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXEXCLUSIVE)) { try { setMaxExclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MaxExcl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MAXEXCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MININCLUSIVE)) { try { setMinInclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinIncl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MININCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MINEXCLUSIVE)) { try { setMinExclusive(value); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_MinExcl, value, manager); } setFacetsDefined(DatatypeValidator::FACET_MINEXCLUSIVE); } else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) { unsigned int val; bool retStatus; try { retStatus = XMLString::textToBin(value, val, fMemoryManager); } catch (RuntimeException&) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } if (!retStatus) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } setFixed(val); //no setFacetsDefined here } else { assignAdditionalFacet(key, value, manager); } }//while}// end of assigneFacet()//// Check facet among self// check common facets// check Additional Facet Constraint//void AbstractNumericFacetValidator::inspectFacet(MemoryManager* const manager){ int thisFacetsDefined = getFacetsDefined(); XMLNumber *thisMaxInclusive = getMaxInclusive(); XMLNumber *thisMaxExclusive = getMaxExclusive(); XMLNumber *thisMinInclusive = getMinInclusive(); XMLNumber *thisMinExclusive = getMinExclusive(); if (!thisFacetsDefined) return; // non co-existence checking // check 4.3.8.c1 error: maxInclusive + maxExclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) ) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_max_Incl_Excl, manager); // non co-existence checking // check 4.3.9.c1 error: minInclusive + minExclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MINEXCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_min_Incl_Excl, manager);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?