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: AbstractStringValidator.cpp 834826 2009-11-11 10:03:53Z borisk $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/validators/datatype/AbstractStringValidator.hpp> 00026 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp> 00027 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp> 00028 #include <xercesc/util/NumberFormatException.hpp> 00029 00030 #include <xercesc/internal/XTemplateSerializer.hpp> 00031 00032 XERCES_CPP_NAMESPACE_BEGIN 00033 00034 static const int BUF_LEN = 64; 00035 00036 #define REPORT_FACET_ERROR(val1, val2, except_code, manager) \ 00037 XMLCh value1[BUF_LEN+1]; \ 00038 XMLCh value2[BUF_LEN+1]; \ 00039 XMLString::sizeToText(val1, value1, BUF_LEN, 10, manager); \ 00040 XMLString::sizeToText(val2, value2, BUF_LEN, 10, manager); \ 00041 ThrowXMLwithMemMgr2(InvalidDatatypeFacetException \ 00042 , except_code \ 00043 , value1 \ 00044 , value2 \ 00045 , manager); 00046 00047 #define REPORT_VALUE_ERROR(data, val1, val2, except_code, manager) \ 00048 XMLCh value1[BUF_LEN+1]; \ 00049 XMLCh value2[BUF_LEN+1]; \ 00050 XMLString::sizeToText(val1, value1, BUF_LEN, 10, manager); \ 00051 XMLString::sizeToText(val2, value2, BUF_LEN, 10, manager); \ 00052 ThrowXMLwithMemMgr3(InvalidDatatypeValueException \ 00053 , except_code \ 00054 , data \ 00055 , value1 \ 00056 , value2 \ 00057 , manager); 00058 00059 // --------------------------------------------------------------------------- 00060 // Constructors and Destructor 00061 // --------------------------------------------------------------------------- 00062 AbstractStringValidator::~AbstractStringValidator() 00063 { 00064 //~RefVectorOf will delete all adopted elements 00065 if ( !fEnumerationInherited && fEnumeration) 00066 { 00067 delete fEnumeration; 00068 fEnumeration = 0; 00069 } 00070 } 00071 00072 AbstractStringValidator::AbstractStringValidator( 00073 DatatypeValidator* const baseValidator 00074 , RefHashTableOf<KVStringPair>* const facets 00075 , const int finalSet 00076 , const ValidatorType type 00077 , MemoryManager* const manager) 00078 :DatatypeValidator(baseValidator, facets, finalSet, type, manager) 00079 ,fLength(0) 00080 ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE) 00081 ,fMinLength(0) 00082 ,fEnumerationInherited(false) 00083 ,fEnumeration(0) 00084 { 00085 // init() is invoked from derived class's ctor instead of from 00086 // here to allow correct resolution of virutal method, such as 00087 // assigneAdditionalFacet(), inheritAdditionalFacet(). 00088 } 00089 00090 void AbstractStringValidator::init(RefArrayVectorOf<XMLCh>* const enums 00091 ,MemoryManager* const manager) 00092 { 00093 00094 if (enums) 00095 { 00096 setEnumeration(enums, false); 00097 normalizeEnumeration(manager); 00098 } 00099 00100 assignFacet(manager); 00101 inspectFacet(manager); 00102 inspectFacetBase(manager); 00103 inheritFacet(); 00104 00105 } 00106 00107 // 00108 // Assign facets 00109 // assign common facets 00110 // assign additional facet 00111 // 00112 void AbstractStringValidator::assignFacet(MemoryManager* const manager) 00113 { 00114 00115 RefHashTableOf<KVStringPair>* facets = getFacets(); 00116 00117 if (!facets) 00118 return; 00119 00120 XMLCh* key; 00121 RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); 00122 00123 while (e.hasMoreElements()) 00124 { 00125 KVStringPair pair = e.nextElement(); 00126 key = pair.getKey(); 00127 XMLCh* value = pair.getValue(); 00128 00129 if (XMLString::equals(key, SchemaSymbols::fgELT_LENGTH)) 00130 { 00131 int val; 00132 try 00133 { 00134 val = XMLString::parseInt(value, manager); 00135 } 00136 catch (NumberFormatException&) 00137 { 00138 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value, manager); 00139 } 00140 00141 if ( val < 0 ) 00142 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value, manager); 00143 00144 setLength(val); 00145 setFacetsDefined(DatatypeValidator::FACET_LENGTH); 00146 } 00147 else if (XMLString::equals(key, SchemaSymbols::fgELT_MINLENGTH)) 00148 { 00149 int val; 00150 try 00151 { 00152 val = XMLString::parseInt(value, manager); 00153 } 00154 catch (NumberFormatException&) 00155 { 00156 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value, manager); 00157 } 00158 00159 if ( val < 0 ) 00160 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value, manager); 00161 00162 setMinLength(val); 00163 setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); 00164 } 00165 else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXLENGTH)) 00166 { 00167 int val; 00168 try 00169 { 00170 val = XMLString::parseInt(value, manager); 00171 } 00172 catch (NumberFormatException&) 00173 { 00174 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value, manager); 00175 } 00176 00177 if ( val < 0 ) 00178 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value, manager); 00179 00180 setMaxLength(val); 00181 setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); 00182 } 00183 else if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) 00184 { 00185 setPattern(value); 00186 if (getPattern()) 00187 setFacetsDefined(DatatypeValidator::FACET_PATTERN); 00188 // do not construct regex until needed 00189 } 00190 else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) 00191 { 00192 unsigned int val; 00193 bool retStatus; 00194 try 00195 { 00196 retStatus = XMLString::textToBin(value, val, fMemoryManager); 00197 } 00198 catch (RuntimeException&) 00199 { 00200 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); 00201 } 00202 00203 if (!retStatus) 00204 { 00205 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); 00206 } 00207 00208 setFixed(val); 00209 //no setFacetsDefined here 00210 } 00211 // 00212 // else if (XMLString::equals(key, SchemaSymbols::fgELT_SPECIAL_TOKEN)) 00213 // TODO 00214 // 00215 // Note: whitespace is taken care of by TraverseSchema. 00216 // 00217 else 00218 { 00219 assignAdditionalFacet(key, value, manager); 00220 } 00221 }//while 00222 }//end of assigneFacet() 00223 00224 // 00225 // Check facet among self 00226 // check common facets 00227 // check Additional Facet Constraint 00228 // 00229 void AbstractStringValidator::inspectFacet(MemoryManager* const manager) 00230 { 00231 00232 int thisFacetsDefined = getFacetsDefined(); 00233 00234 if (!thisFacetsDefined) 00235 return; 00236 00237 // check 4.3.1.c1 error: length & (maxLength | minLength) 00238 if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) 00239 { 00240 if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) 00241 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen, manager); 00242 else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0)) 00243 ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen, manager); 00244 } 00245 00246 // check 4.3.2.c1 must: minLength <= maxLength 00247 if ((thisFacetsDefined & (DatatypeValidator::FACET_MINLENGTH 00248 |DatatypeValidator::FACET_MAXLENGTH)) != 0) 00249 { 00250 XMLSize_t thisMinLength = getMinLength(); 00251 XMLSize_t thisMaxLength = getMaxLength(); 00252 if ( thisMinLength > thisMaxLength ) 00253 { 00254 REPORT_FACET_ERROR(thisMaxLength 00255 , thisMinLength 00256 , XMLExcepts::FACET_maxLen_minLen 00257 , manager) 00258 } 00259 } 00260 00261 }// end of inspectFacet() 00262 00263 // 00264 // Check vs base 00265 // check common facets 00266 // check enumeration 00267 // check Additional Facet Constraint 00268 // 00269 void AbstractStringValidator::inspectFacetBase(MemoryManager* const manager) 00270 { 00271 00272 AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator(); 00273 int thisFacetsDefined = getFacetsDefined(); 00274 00275 if ( (!thisFacetsDefined && !fEnumeration) || 00276 (!pBaseValidator) ) 00277 return; 00278 00279 int baseFacetsDefined = pBaseValidator->getFacetsDefined(); 00280 00281 XMLSize_t thisLength = getLength(); 00282 XMLSize_t thisMinLength = getMinLength(); 00283 XMLSize_t thisMaxLength = getMaxLength(); 00284 00285 XMLSize_t baseLength = pBaseValidator->getLength(); 00286 XMLSize_t baseMinLength = pBaseValidator->getMinLength(); 00287 XMLSize_t baseMaxLength = pBaseValidator->getMaxLength(); 00288 int baseFixed = pBaseValidator->getFixed(); 00289 00290 /*** 00291 check facets against base.facets 00292 Note: later we need to check the "fix" option of the base type 00293 and apply that to every individual facet. 00294 ***/ 00295 00296 /*** 00297 Non coexistence of derived' length and base' (minLength | maxLength) 00298 base' length and derived' (minLength | maxLength) 00299 00300 E2-35 00301 It is an error for both length and either of minLength or maxLength to be members of {facets}, 00302 unless they are specified in different derivation steps in which case the following must be true: 00303 the {value} of minLength <= the {value} of length <= the {value} of maxLength 00304 ***/ 00305 00306 // error: length > base.maxLength 00307 // length < base.minLength 00308 if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) 00309 { 00310 if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) && 00311 (thisLength > baseMaxLength) ) 00312 { 00313 REPORT_FACET_ERROR(thisLength 00314 , baseMaxLength 00315 , XMLExcepts::FACET_Len_baseMaxLen 00316 , manager) 00317 } 00318 00319 if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) && 00320 (thisLength < baseMinLength) ) 00321 { 00322 REPORT_FACET_ERROR(thisLength 00323 , baseMinLength 00324 , XMLExcepts::FACET_Len_baseMinLen 00325 , manager) 00326 } 00327 } 00328 00329 // error: baseLength > maxLength 00330 // baseLength < minLength 00331 if ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) 00332 { 00333 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) && 00334 (baseLength > thisMaxLength) ) 00335 { 00336 REPORT_FACET_ERROR(thisMaxLength 00337 , baseLength 00338 , XMLExcepts::FACET_maxLen_baseLen 00339 , manager) 00340 } 00341 00342 if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) && 00343 (baseLength < thisMinLength) ) 00344 { 00345 REPORT_FACET_ERROR(thisMinLength 00346 , baseLength 00347 , XMLExcepts::FACET_minLen_baseLen 00348 , manager) 00349 } 00350 } 00351 00352 // check 4.3.1.c2 error: length != base.length 00353 if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) && 00354 ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)) 00355 { 00356 if ( thisLength != baseLength ) 00357 { 00358 REPORT_FACET_ERROR(thisLength 00359 , baseLength 00360 , XMLExcepts::FACET_Len_baseLen 00361 , manager) 00362 } 00363 } 00364 00365 /*** 00366 |--- derived ---| 00367 base.minLength <= minLength <= maxLength <= base.maxLength 00368 |------------------- base -------------------| 00369 ***/ 00370 00371 // check 4.3.2.c1 must: minLength <= base.maxLength 00372 if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH ) != 0) && 00373 ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH ) != 0)) 00374 { 00375 if ( thisMinLength > baseMaxLength ) 00376 { 00377 REPORT_FACET_ERROR(thisMinLength 00378 , baseMaxLength 00379 , XMLExcepts::FACET_minLen_basemaxLen 00380 , manager) 00381 } 00382 } 00383 00384 // check 4.3.2.c2 error: minLength < base.minLength 00385 if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) && 00386 ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0)) 00387 { 00388 if ((baseFixed & DatatypeValidator::FACET_MINLENGTH) !=0) 00389 { 00390 if ( thisMinLength != baseMinLength ) 00391 { 00392 REPORT_FACET_ERROR(thisMinLength 00393 , baseMinLength 00394 , XMLExcepts::FACET_minLen_base_fixed 00395 , manager) 00396 } 00397 00398 } 00399 else 00400 { 00401 if ( thisMinLength < baseMinLength ) 00402 { 00403 REPORT_FACET_ERROR(thisMinLength 00404 , baseMinLength 00405 , XMLExcepts::FACET_minLen_baseminLen 00406 , manager) 00407 } 00408 } 00409 } 00410 00411 // check 4.3.2.c1 must: base.minLength <= maxLength 00412 if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) && 00413 ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)) 00414 { 00415 if ( baseMinLength > thisMaxLength ) 00416 { 00417 REPORT_FACET_ERROR(thisMaxLength 00418 , baseMinLength 00419 , XMLExcepts::FACET_maxLen_baseminLen 00420 , manager) 00421 } 00422 } 00423 00424 // check 4.3.3.c1 error: maxLength > base.maxLength 00425 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) && 00426 ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)) 00427 { 00428 if ((baseFixed & DatatypeValidator::FACET_MAXLENGTH) !=0) 00429 { 00430 if ( thisMaxLength != baseMaxLength ) 00431 { 00432 REPORT_FACET_ERROR(thisMaxLength 00433 , baseMaxLength 00434 , XMLExcepts::FACET_maxLen_base_fixed 00435 , manager) 00436 } 00437 } 00438 else 00439 { 00440 if ( thisMaxLength > baseMaxLength ) 00441 { 00442 REPORT_FACET_ERROR(thisMaxLength 00443 , baseMaxLength 00444 , XMLExcepts::FACET_maxLen_basemaxLen 00445 , manager) 00446 } 00447 } 00448 } 00449 00450 // check 4.3.5.c0 must: enumeration values from the value space of base 00451 if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) && 00452 (getEnumeration() !=0)) 00453 { 00454 XMLSize_t i = 0; 00455 XMLSize_t enumLength = getEnumeration()->size(); 00456 for ( ; i < enumLength; i++) 00457 { 00458 // ask parent do a complete check 00459 pBaseValidator->checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager); 00460 #if 0 00461 // spec says that only base has to checkContent 00462 // enum shall pass this->checkContent() as well. 00463 checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager); 00464 #endif 00465 } 00466 } 00467 00468 checkAdditionalFacetConstraints(manager); 00469 00470 } //end of inspectFacetBase 00471 00472 // 00473 // Inherit facet from base 00474 // a. inherit common facets 00475 // b. inherit additional facet 00476 // 00477 void AbstractStringValidator::inheritFacet() 00478 { 00479 /*** 00480 P3. Inherit facets from base.facets 00481 00482 The reason of this inheriting (or copying values) is to ease 00483 schema constraint checking, so that we need NOT trace back to our 00484 very first base validator in the hierachy. Instead, we are pretty 00485 sure checking against immediate base validator is enough. 00486 ***/ 00487 00488 AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator(); 00489 00490 if (!pBaseValidator) 00491 return; 00492 00493 int thisFacetsDefined = getFacetsDefined(); 00494 int baseFacetsDefined = pBaseValidator->getFacetsDefined(); 00495 00496 // inherit length 00497 if (((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) && 00498 ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) == 0)) 00499 { 00500 setLength(pBaseValidator->getLength()); 00501 setFacetsDefined(DatatypeValidator::FACET_LENGTH); 00502 } 00503 00504 // inherit minLength 00505 if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) && 00506 ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) == 0)) 00507 { 00508 setMinLength(pBaseValidator->getMinLength()); 00509 setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); 00510 } 00511 00512 // inherit maxLength 00513 if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) && 00514 ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) == 0)) 00515 { 00516 setMaxLength(pBaseValidator->getMaxLength()); 00517 setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); 00518 } 00519 00520 // inherit enumeration 00521 if (((baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) !=0) && 00522 ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0)) 00523 { 00524 setEnumeration(pBaseValidator->getEnumeration(), true); 00525 } 00526 00527 // we don't inherit pattern 00528 00529 // inherit "fixed" option 00530 setFixed(getFixed() | pBaseValidator->getFixed()); 00531 00532 // inherit additional facet 00533 inheritAdditionalFacet(); 00534 00535 } // end of inheritance 00536 00537 00538 // ----------------------------------------------------------------------- 00539 // Compare methods 00540 // ----------------------------------------------------------------------- 00541 int AbstractStringValidator::compare(const XMLCh* const lValue 00542 , const XMLCh* const rValue 00543 , MemoryManager* const) 00544 { 00545 return XMLString::compareString(lValue, rValue); 00546 } 00547 00548 void AbstractStringValidator::validate( const XMLCh* const content 00549 , ValidationContext* const context 00550 , MemoryManager* const manager) 00551 { 00552 checkContent(content, context, false, manager); 00553 } 00554 00555 void AbstractStringValidator::checkContent( const XMLCh* const content 00556 , ValidationContext* const context 00557 , bool asBase 00558 , MemoryManager* const manager 00559 ) 00560 { 00561 00562 //validate against base validator if any 00563 AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) this->getBaseValidator(); 00564 if (pBaseValidator) 00565 pBaseValidator->checkContent(content, context, true, manager); 00566 00567 int thisFacetsDefined = getFacetsDefined(); 00568 00569 // we check pattern first 00570 if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) 00571 { 00572 if (getRegex()->matches(content, manager) ==false) 00573 { 00574 ThrowXMLwithMemMgr2(InvalidDatatypeValueException 00575 , XMLExcepts::VALUE_NotMatch_Pattern 00576 , content 00577 , getPattern() 00578 , manager); 00579 } 00580 } 00581 00582 // if this is a base validator, we only need to check pattern facet 00583 // all other facet were inherited by the derived type 00584 if (asBase) 00585 return; 00586 00587 checkValueSpace(content, manager); 00588 XMLSize_t length = getLength(content, manager); 00589 00590 if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) && 00591 (length > getMaxLength())) 00592 { 00593 REPORT_VALUE_ERROR(content 00594 , length 00595 , getMaxLength() 00596 , XMLExcepts::VALUE_GT_maxLen 00597 , manager) 00598 } 00599 00600 if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) && 00601 (length < getMinLength())) 00602 { 00603 REPORT_VALUE_ERROR(content 00604 , length 00605 , getMinLength() 00606 , XMLExcepts::VALUE_LT_minLen 00607 , manager) 00608 } 00609 00610 if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) && 00611 (length != getLength())) 00612 { 00613 REPORT_VALUE_ERROR(content 00614 , length 00615 , getLength() 00616 , XMLExcepts::VALUE_NE_Len 00617 , manager) 00618 } 00619 00620 if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 && 00621 (getEnumeration() != 0)) 00622 { 00623 XMLCh* normContent = XMLString::replicate(content, manager); 00624 ArrayJanitor<XMLCh> jan(normContent, manager); 00625 normalizeContent(normContent, manager); 00626 00627 XMLSize_t i=0; 00628 XMLSize_t enumLength = getEnumeration()->size(); 00629 for ( ; i < enumLength; i++) 00630 { 00631 if (XMLString::equals(normContent, getEnumeration()->elementAt(i))) 00632 break; 00633 } 00634 00635 if (i == enumLength) 00636 ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); 00637 } 00638 00639 checkAdditionalFacet(content, manager); 00640 00641 } 00642 00643 const RefArrayVectorOf<XMLCh>* AbstractStringValidator::getEnumString() const 00644 { 00645 return getEnumeration(); 00646 } 00647 00648 void AbstractStringValidator::normalizeEnumeration(MemoryManager* const manager) 00649 { 00650 AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator(); 00651 00652 if (!fEnumeration || !pBaseValidator) 00653 return; 00654 00655 int baseFacetsDefined = pBaseValidator->getFacetsDefined(); 00656 if ((baseFacetsDefined & DatatypeValidator::FACET_WHITESPACE) == 0) 00657 return; 00658 00659 short whiteSpace = pBaseValidator->getWSFacet(); 00660 00661 if ( whiteSpace == DatatypeValidator::PRESERVE ) 00662 { 00663 return; 00664 } 00665 else if ( whiteSpace == DatatypeValidator::REPLACE ) 00666 { 00667 XMLSize_t enumLength = getEnumeration()->size(); 00668 for ( XMLSize_t i=0; i < enumLength; i++) 00669 { 00670 XMLString::replaceWS(getEnumeration()->elementAt(i), manager); 00671 } 00672 } 00673 else if ( whiteSpace == DatatypeValidator::COLLAPSE ) 00674 { 00675 XMLSize_t enumLength = getEnumeration()->size(); 00676 for ( XMLSize_t i=0; i < enumLength; i++) 00677 { 00678 XMLString::collapseWS(getEnumeration()->elementAt(i), manager); 00679 } 00680 } 00681 } 00682 00683 void AbstractStringValidator::normalizeContent(XMLCh* const, MemoryManager* const) const 00684 { 00685 // default implementation: do nothing 00686 return; 00687 } 00688 00689 00690 void AbstractStringValidator::checkAdditionalFacetConstraints(MemoryManager* const) const 00691 { 00692 return; 00693 } 00694 00695 void AbstractStringValidator::checkAdditionalFacet(const XMLCh* const 00696 , MemoryManager* const) const 00697 { 00698 return; 00699 } 00700 00701 void AbstractStringValidator::inheritAdditionalFacet() 00702 { 00703 return; 00704 } 00705 00706 void AbstractStringValidator::assignAdditionalFacet( const XMLCh* const key 00707 , const XMLCh* const 00708 , MemoryManager* const manager) 00709 { 00710 ThrowXMLwithMemMgr1(InvalidDatatypeFacetException 00711 , XMLExcepts::FACET_Invalid_Tag 00712 , key 00713 , manager); 00714 } 00715 00716 XMLSize_t AbstractStringValidator::getLength(const XMLCh* const content 00717 , MemoryManager* const) const 00718 { 00719 return XMLString::stringLen(content); 00720 } 00721 00722 /*** 00723 * Support for Serialization/De-serialization 00724 ***/ 00725 00726 IMPL_XSERIALIZABLE_NOCREATE(AbstractStringValidator) 00727 00728 void AbstractStringValidator::serialize(XSerializeEngine& serEng) 00729 { 00730 00731 DatatypeValidator::serialize(serEng); 00732 00733 if (serEng.isStoring()) 00734 { 00735 serEng.writeSize (fLength); 00736 serEng.writeSize (fMaxLength); 00737 serEng.writeSize (fMinLength); 00738 serEng<<fEnumerationInherited; 00739 00740 /*** 00741 * 00742 * Serialize RefArrayVectorOf<XMLCh> 00743 * 00744 ***/ 00745 XTemplateSerializer::storeObject(fEnumeration, serEng); 00746 00747 } 00748 else 00749 { 00750 serEng.readSize (fLength); 00751 serEng.readSize (fMaxLength); 00752 serEng.readSize (fMinLength); 00753 serEng>>fEnumerationInherited; 00754 00755 /*** 00756 * 00757 * Deserialize RefArrayVectorOf<XMLCh> 00758 * 00759 ***/ 00760 XTemplateSerializer::loadObject(&fEnumeration, 8, true, serEng); 00761 00762 } 00763 00764 } 00765 00766 XERCES_CPP_NAMESPACE_END 00767