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: StringDatatypeValidator.cpp 471747 2006-11-06 14:31:56Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/datatype/StringDatatypeValidator.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 StringDatatypeValidator::StringDatatypeValidator(MemoryManager* const manager) 00036 :AbstractStringValidator(0, 0, 0, DatatypeValidator::String, manager) 00037 { 00038 setWhiteSpace(DatatypeValidator::PRESERVE); 00039 } 00040 00041 StringDatatypeValidator::StringDatatypeValidator( 00042 DatatypeValidator* const baseValidator 00043 , RefHashTableOf<KVStringPair>* const facets 00044 , RefArrayVectorOf<XMLCh>* const enums 00045 , const int finalSet 00046 , MemoryManager* const manager) 00047 :AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::String, manager) 00048 { 00049 setWhiteSpace(DatatypeValidator::PRESERVE); 00050 init(enums, manager); 00051 } 00052 00053 StringDatatypeValidator::~StringDatatypeValidator() 00054 {} 00055 00056 DatatypeValidator* StringDatatypeValidator::newInstance 00057 ( 00058 RefHashTableOf<KVStringPair>* const facets 00059 , RefArrayVectorOf<XMLCh>* const enums 00060 , const int finalSet 00061 , MemoryManager* const manager 00062 ) 00063 { 00064 return (DatatypeValidator*) new (manager) StringDatatypeValidator(this, facets, enums, finalSet, manager); 00065 } 00066 00067 StringDatatypeValidator::StringDatatypeValidator( 00068 DatatypeValidator* const baseValidator 00069 , RefHashTableOf<KVStringPair>* const facets 00070 , const int finalSet 00071 , const ValidatorType type 00072 , MemoryManager* const manager) 00073 :AbstractStringValidator(baseValidator, facets, finalSet, type, manager) 00074 { 00075 setWhiteSpace(DatatypeValidator::PRESERVE); 00076 // do not invoke init() here!!! 00077 } 00078 00079 // --------------------------------------------------------------------------- 00080 // Utilities 00081 // --------------------------------------------------------------------------- 00082 void StringDatatypeValidator::assignAdditionalFacet(const XMLCh* const key 00083 , const XMLCh* const value 00084 , MemoryManager* const manager) 00085 { 00086 if (XMLString::equals(key, SchemaSymbols::fgELT_WHITESPACE)) 00087 { 00088 // whiteSpace = preserve | replace | collapse 00089 if (XMLString::equals(value, SchemaSymbols::fgWS_PRESERVE)) 00090 setWhiteSpace(DatatypeValidator::PRESERVE); 00091 else if (XMLString::equals(value, SchemaSymbols::fgWS_REPLACE)) 00092 setWhiteSpace(DatatypeValidator::REPLACE); 00093 else if (XMLString::equals(value, SchemaSymbols::fgWS_COLLAPSE)) 00094 setWhiteSpace(DatatypeValidator::COLLAPSE); 00095 else 00096 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_WS, value, manager); 00097 //("whiteSpace value '" + ws + "' must be one of 'preserve', 'replace', 'collapse'."); 00098 00099 setFacetsDefined(DatatypeValidator::FACET_WHITESPACE); 00100 } 00101 else 00102 { 00103 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException 00104 , XMLExcepts::FACET_Invalid_Tag 00105 , key 00106 , manager); 00107 } 00108 } 00109 00110 void StringDatatypeValidator::inheritAdditionalFacet() 00111 { 00112 StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator(); 00113 00114 if (!pBaseValidator) 00115 return; 00116 00117 // inherit whitespace 00118 if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) !=0) && 00119 ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) == 0)) 00120 { 00121 setWhiteSpace(getBaseValidator()->getWSFacet()); 00122 setFacetsDefined(DatatypeValidator::FACET_WHITESPACE); 00123 } 00124 } 00125 00126 void StringDatatypeValidator::checkAdditionalFacetConstraints(MemoryManager* const manager) const 00127 { 00128 00129 StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator(); 00130 00131 if (!pBaseValidator) 00132 return; 00133 00134 short thisWSFacet = getWSFacet(); 00135 short baseWSFacet = pBaseValidator->getWSFacet(); 00136 00137 // check 4.3.6.c1 error: whitespace 00138 if (((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0) && 00139 ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 )) 00140 { 00141 if ((baseWSFacet == DatatypeValidator::COLLAPSE) && 00142 ((thisWSFacet == DatatypeValidator::PRESERVE) || 00143 (thisWSFacet == DatatypeValidator::REPLACE))) 00144 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_collapse, manager); 00145 00146 if ((baseWSFacet == DatatypeValidator::REPLACE) && 00147 (thisWSFacet == DatatypeValidator::PRESERVE)) 00148 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_replace, manager); 00149 00150 if (((pBaseValidator->getFixed() & DatatypeValidator::FACET_WHITESPACE) !=0) && 00151 ( thisWSFacet != baseWSFacet)) 00152 { 00153 ThrowXMLwithMemMgr2(InvalidDatatypeFacetException 00154 , XMLExcepts::FACET_whitespace_base_fixed 00155 , getWSstring(thisWSFacet) 00156 , getWSstring(baseWSFacet) 00157 , manager); 00158 } 00159 } 00160 00161 } 00162 00163 void StringDatatypeValidator::checkAdditionalFacet(const XMLCh* const content 00164 , MemoryManager* const manager) const 00165 { 00166 // 00167 // check WhiteSpace 00168 // 00169 if ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 ) 00170 { 00171 if ( getWSFacet() == DatatypeValidator::REPLACE ) 00172 { 00173 if (!XMLString::isWSReplaced(content)) 00174 ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_WS_replaced, content, manager); 00175 } 00176 else if ( getWSFacet() == DatatypeValidator::COLLAPSE ) 00177 { 00178 if (!XMLString::isWSCollapsed(content)) 00179 ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_WS_collapsed, content, manager); 00180 } 00181 00182 } 00183 } 00184 00185 void StringDatatypeValidator::checkValueSpace(const XMLCh* const 00186 , MemoryManager* const) 00187 {} 00188 00189 /*** 00190 * Support for Serialization/De-serialization 00191 ***/ 00192 00193 IMPL_XSERIALIZABLE_TOCREATE(StringDatatypeValidator) 00194 00195 void StringDatatypeValidator::serialize(XSerializeEngine& serEng) 00196 { 00197 AbstractStringValidator::serialize(serEng); 00198 } 00199 00200 XERCES_CPP_NAMESPACE_END 00201