// // Check facet among self // check common facets // check Additional Facet Constraint // void AbstractStringValidator::inspectFacet(MemoryManager* const manager) { int thisFacetsDefined = getFacetsDefined(); if (!thisFacetsDefined) return; // check 4.3.1.c1 error: length & (maxLength | minLength) if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) { if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen, manager); else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0)) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen, manager); } // check 4.3.2.c1 must: minLength <= maxLength if ((thisFacetsDefined & (DatatypeValidator::FACET_MINLENGTH |DatatypeValidator::FACET_MAXLENGTH)) != 0) { int thisMinLength = getMinLength(); int thisMaxLength = getMaxLength(); if ( thisMinLength > thisMaxLength ) { REPORT_FACET_ERROR(thisMaxLength , thisMinLength , XMLExcepts::FACET_maxLen_minLen , manager) } }
void AbstractNumericValidator::boundsCheck(const XMLNumber* const theData , MemoryManager* const manager) { int thisFacetsDefined = getFacetsDefined(); int result; try { // must be < MaxExclusive if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0 ) { result = compareValues(theData, getMaxExclusive()); if ( result != -1) { REPORT_VALUE_ERROR(theData , getMaxExclusive() , XMLExcepts::VALUE_exceed_maxExcl , manager) } } // must be <= MaxInclusive if ( (thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0 ) { result = compareValues(theData, getMaxInclusive()); if (result == 1) { REPORT_VALUE_ERROR(theData , getMaxInclusive() , XMLExcepts::VALUE_exceed_maxIncl , manager) } }
void DecimalDatatypeValidator::inheritAdditionalFacet() { DecimalDatatypeValidator *numBase = (DecimalDatatypeValidator*) getBaseValidator(); if (!numBase) return; int thisFacetsDefined = getFacetsDefined(); int baseFacetsDefined = numBase->getFacetsDefined(); // inherit totalDigits if ((( baseFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) && (( thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) == 0) ) { setTotalDigits(numBase->fTotalDigits); setFacetsDefined(DatatypeValidator::FACET_TOTALDIGITS); } // inherit fractionDigits if ((( baseFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) && (( thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) == 0) ) { setFractionDigits(numBase->fFractionDigits); setFacetsDefined(DatatypeValidator::FACET_FRACTIONDIGITS); } }
void ListDatatypeValidator::inspectFacetBase(MemoryManager* const manager) { // // we are pretty sure baseValidator is not null // if (getBaseValidator()->getType() == DatatypeValidator::List) { AbstractStringValidator::inspectFacetBase(manager); } else { // the first level ListDTV // check 4.3.5.c0 must: enumeration values from the value space of base if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) && (getEnumeration() !=0) ) { int i; int enumLength = getEnumeration()->size(); try { for ( i = 0; i < enumLength; i++) { // ask the itemType for a complete check BaseRefVectorOf<XMLCh>* tempList = XMLString::tokenizeString(getEnumeration()->elementAt(i), manager); Janitor<BaseRefVectorOf<XMLCh> > jan(tempList); int tokenNumber = tempList->size(); try { for ( int j = 0; j < tokenNumber; j++) getBaseValidator()->validate(tempList->elementAt(j), (ValidationContext*)0, manager); } catch(const OutOfMemoryException&) { jan.release(); throw; } // enum shall pass this->checkContent() as well. checkContent(getEnumeration()->elementAt(i), (ValidationContext*)0, false, manager); } } catch ( XMLException& ) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException , XMLExcepts::FACET_enum_base , getEnumeration()->elementAt(i) , manager); } } } }// End of inspectFacetBase()
void NOTATIONDatatypeValidator::checkContent( const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager ) { //validate against base validator if any NOTATIONDatatypeValidator *pBaseValidator = (NOTATIONDatatypeValidator*) this->getBaseValidator(); if (pBaseValidator) pBaseValidator->checkContent(content, context, true, manager); int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; checkValueSpace(content, manager); if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 && (getEnumeration() != 0)) { XMLCh* normContent = XMLString::replicate(content, manager); ArrayJanitor<XMLCh> jan(normContent, manager); normalizeContent(normContent, manager); int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (XMLString::equals(normContent, getEnumeration()->elementAt(i))) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } checkAdditionalFacet(content, manager); }
void StringDatatypeValidator::inheritAdditionalFacet() { StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator(); if (!pBaseValidator) return; // inherit whitespace if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) !=0) && ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) == 0)) { setWhiteSpace(getBaseValidator()->getWSFacet()); setFacetsDefined(DatatypeValidator::FACET_WHITESPACE); } }
// ----------------------------------------------------------------------- // Abstract interface from AbstractNumericValidator // ----------------------------------------------------------------------- void FloatDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any FloatDatatypeValidator *pBase = (FloatDatatypeValidator*) this->getBaseValidator(); if (pBase) pBase->checkContent(content, context, true, manager); // we check pattern first if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; XMLFloat theValue(content, manager); XMLFloat *theData = &theValue; if (getEnumeration() != 0) { int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (compareValues(theData, (XMLFloat*) getEnumeration()->elementAt(i))==0) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } boundsCheck(theData, manager); }
void BooleanDatatypeValidator::checkContent( const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any BooleanDatatypeValidator *pBaseValidator = (BooleanDatatypeValidator*) this->getBaseValidator(); if (pBaseValidator !=0) pBaseValidator->checkContent(content, context, true, manager); // we check pattern first if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; unsigned int i = 0; for ( ; i < XMLUni::fgBooleanValueSpaceArraySize; i++ ) { if ( XMLString::equals(content, XMLUni::fgBooleanValueSpace[i])) break; } if (i == XMLUni::fgBooleanValueSpaceArraySize) ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_Invalid_Name , content , SchemaSymbols::fgDT_BOOLEAN , manager); //Not valid boolean type }
void StringDatatypeValidator::checkAdditionalFacet(const XMLCh* const content , MemoryManager* const manager) const { // // check WhiteSpace // if ((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 ) { if ( getWSFacet() == DatatypeValidator::REPLACE ) { if (!XMLString::isWSReplaced(content)) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_WS_replaced, content, manager); } else if ( getWSFacet() == DatatypeValidator::COLLAPSE ) { if (!XMLString::isWSCollapsed(content)) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_WS_collapsed, content, manager); } } }
// // 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); // // minExclusive < minInclusive <= maxInclusive < maxExclusive // // check 4.3.7.c1 must: minInclusive <= maxInclusive if (((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_MININCLUSIVE) != 0) ) { int result = compareValues(thisMinInclusive, thisMaxInclusive); if ( result == 1 || result == INDETERMINATE ) { REPORT_FACET_ERROR(thisMinInclusive , thisMaxInclusive , XMLExcepts::FACET_maxIncl_minIncl , manager) } }
void DecimalDatatypeValidator::checkAdditionalFacetConstraints(MemoryManager* const manager) const { int thisFacetsDefined = getFacetsDefined(); // check 4.3.12.c1 must: fractionDigits <= totalDigits if ( ((thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) && ((thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) ) { if ( fFractionDigits > fTotalDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(getFractionDigits(), value1, BUF_LEN, 10, manager); XMLString::binToText(getTotalDigits(), value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_TotDigit_FractDigit , value2 , value1 , manager); } } }
void StringDatatypeValidator::checkAdditionalFacetConstraints(MemoryManager* const manager) const { StringDatatypeValidator *pBaseValidator = (StringDatatypeValidator*) getBaseValidator(); if (!pBaseValidator) return; short thisWSFacet = getWSFacet(); short baseWSFacet = pBaseValidator->getWSFacet(); // check 4.3.6.c1 error: whitespace if (((getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0) && ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_WHITESPACE) != 0 )) { if ((baseWSFacet == DatatypeValidator::COLLAPSE) && ((thisWSFacet == DatatypeValidator::PRESERVE) || (thisWSFacet == DatatypeValidator::REPLACE))) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_collapse, manager); if ((baseWSFacet == DatatypeValidator::REPLACE) && (thisWSFacet == DatatypeValidator::PRESERVE)) ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_WS_replace, manager); if (((pBaseValidator->getFixed() & DatatypeValidator::FACET_WHITESPACE) !=0) && ( thisWSFacet != baseWSFacet)) { ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_whitespace_base_fixed , getWSstring(thisWSFacet) , getWSstring(baseWSFacet) , manager); } } }
void DecimalDatatypeValidator::checkAdditionalFacetConstraintsBase(MemoryManager* const manager) const { DecimalDatatypeValidator *numBase = (DecimalDatatypeValidator*) getBaseValidator(); if (!numBase) return; int thisFacetsDefined = getFacetsDefined(); int baseFacetsDefined = numBase->getFacetsDefined(); // check 4.3.11.c1 error: totalDigits > base.totalDigits // totalDigits != base.totalDigits if (base.fixed) if (( thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) { if ( (( baseFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) && ( fTotalDigits > numBase->fTotalDigits )) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(fTotalDigits, value1, BUF_LEN, 10, manager); XMLString::binToText(numBase->fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_totalDigit_base_totalDigit , value1 , value2 , manager); } if ( (( baseFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) && (( numBase->getFixed() & DatatypeValidator::FACET_TOTALDIGITS) != 0) && ( fTotalDigits != numBase->fTotalDigits )) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(fTotalDigits, value1, BUF_LEN, 10, manager); XMLString::binToText(numBase->fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_totalDigit_base_fixed , value1 , value2 , manager); } } if (( thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) { // check question error: fractionDigits > base.fractionDigits ??? if ( (( baseFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) && ( fFractionDigits > numBase->fFractionDigits )) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(fFractionDigits, value1, BUF_LEN, 10, manager); XMLString::binToText(numBase->fFractionDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_fractDigit_base_fractDigit , value1 , value2 , manager); } // check question error: fractionDigits > base.totalDigits ??? if ( (( baseFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0) && ( fFractionDigits > numBase->fTotalDigits )) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(fFractionDigits, value1, BUF_LEN, 10, manager); XMLString::binToText(numBase->fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_fractDigit_base_totalDigit , value1 , value2 , manager); } // fractionDigits != base.fractionDigits if (base.fixed) if ( (( baseFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) && (( numBase->getFixed() & DatatypeValidator::FACET_FRACTIONDIGITS) != 0) && ( fFractionDigits != numBase->fFractionDigits )) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(fFractionDigits, value1, BUF_LEN, 10, manager); XMLString::binToText(numBase->fFractionDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr2(InvalidDatatypeFacetException , XMLExcepts::FACET_fractDigit_base_fixed , value1 , value2 , manager); } } }
// // here content is a list of items // void ListDatatypeValidator::checkContent( BaseRefVectorOf<XMLCh>* tokenVector , const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { DatatypeValidator* bv = getBaseValidator(); if (bv->getType() == DatatypeValidator::List) ((ListDatatypeValidator*)bv)->checkContent(tokenVector, content, context, true, manager); else { // the ultimate itemType DTV for (unsigned int i = 0; i < tokenVector->size(); i++) bv->validate(tokenVector->elementAt(i), context, manager); } int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { // lazy construction if (getRegex() == 0) { try { setRegex(new (fMemoryManager) RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption, fMemoryManager)); } catch (XMLException &e) { ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage(), manager); } } //check every item in the list as a whole if (getRegex()->matches(content, manager) == false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; unsigned int tokenNumber = tokenVector->size(); if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) && (tokenNumber > getMaxLength())) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager); XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeValueException , XMLExcepts::VALUE_GT_maxLen , getContent() , value1 , value2 , manager); } if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) && (tokenNumber < getMinLength())) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager); XMLString::binToText(getMinLength(), value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeValueException , XMLExcepts::VALUE_LT_minLen , getContent() , value1 , value2 , manager); } if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) && (tokenNumber != AbstractStringValidator::getLength())) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager); XMLString::binToText(AbstractStringValidator::getLength(), value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeValueException , XMLExcepts::VALUE_NE_Len , getContent() , value1 , value2 , manager); } if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 && (getEnumeration() != 0)) { int i; int enumLength = getEnumeration()->size(); for ( i = 0; i < enumLength; i++) { //optimization: we do a lexical comparision first // this may be faster for string and its derived if (XMLString::equals(getEnumeration()->elementAt(i), getContent())) break; // a match found // do a value space check // this is needed for decimal (and probably other types // such as datetime related) // eg. // tokenVector = "1 2 3.0 4" vs enumeration = "1 2 3 4.0" // if (valueSpaceCheck(tokenVector, getEnumeration()->elementAt(i), manager)) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, getContent(), manager); } // enumeration }
void DateTimeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any DateTimeValidator *pBaseValidator = (DateTimeValidator*) this->getBaseValidator(); if (pBaseValidator) pBaseValidator->checkContent(content, context, true, manager); int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; // the derived classes' parse() method constructs an // XMLDateTime object anc invokes appropriate XMLDateTime's // parser to parse the content. XMLDateTime dateTimeValue(content, manager); XMLDateTime* dateTime = &dateTimeValue; parse(dateTime); // must be < MaxExclusive if ((thisFacetsDefined & DatatypeValidator::FACET_MAXEXCLUSIVE) != 0) { if (compareValues(dateTime, getMaxExclusive()) != XMLDateTime::LESS_THAN) { REPORT_VALUE_ERROR( dateTime , getMaxExclusive() , XMLExcepts::VALUE_exceed_maxExcl , manager) } } // must be <= MaxInclusive if ((thisFacetsDefined & DatatypeValidator::FACET_MAXINCLUSIVE) != 0) { int result = compareValues(dateTime, getMaxInclusive()); if ( result == XMLDateTime::GREATER_THAN || result == XMLDateTime::INDETERMINATE ) { REPORT_VALUE_ERROR( dateTime , getMaxInclusive() , XMLExcepts::VALUE_exceed_maxIncl , manager) } }
// ----------------------------------------------------------------------- // Abstract interface from AbstractNumericValidator // ----------------------------------------------------------------------- void DecimalDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { //validate against base validator if any DecimalDatatypeValidator *pBase = (DecimalDatatypeValidator*) this->getBaseValidator(); if (pBase) pBase->checkContent(content, context, true, manager); int thisFacetsDefined = getFacetsDefined(); // we check pattern first if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 ) { // lazy construction if (getRegex() ==0) { try { // REVISIT: cargillmem fMemoryManager vs manager setRegex(new (fMemoryManager) RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption, fMemoryManager)); } catch (XMLException &e) { ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage(), manager); } } if (getRegex()->matches(content, manager) ==false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; XMLCh *errorMsg = 0; try { XMLBigDecimal compareDataValue(content, manager); XMLBigDecimal* compareData = &compareDataValue; if (getEnumeration()) { int i=0; int enumLength = getEnumeration()->size(); for ( ; i < enumLength; i++) { if (compareValues(compareData, (XMLBigDecimal*) getEnumeration()->elementAt(i)) ==0 ) break; } if (i == enumLength) ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } boundsCheck(compareData, manager); if ( (thisFacetsDefined & DatatypeValidator::FACET_FRACTIONDIGITS) != 0 ) { if ( compareData->getScale() > fFractionDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getScale(), value1, BUF_LEN, 10, manager); XMLString::binToText(fFractionDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_fractDigit , compareData->getRawData() , value1 , value2 , manager); } } if ( (thisFacetsDefined & DatatypeValidator::FACET_TOTALDIGITS) != 0 ) { if ( compareData->getTotalDigit() > fTotalDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getTotalDigit(), value1, BUF_LEN, 10, manager); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit , compareData->getRawData() , value1 , value2 , manager); } /*** E2-44 totalDigits ... by restricting it to numbers that are expressible as i � 10^-n where i and n are integers such that |i| < 10^totalDigits and 0 <= n <= totalDigits. ***/ if ( compareData->getScale() > fTotalDigits ) { XMLCh value1[BUF_LEN+1]; XMLCh value2[BUF_LEN+1]; XMLString::binToText(compareData->getScale(), value1, BUF_LEN, 10, manager); XMLString::binToText(fTotalDigits, value2, BUF_LEN, 10, manager); ThrowXMLwithMemMgr3(InvalidDatatypeFacetException , XMLExcepts::VALUE_exceed_totalDigit , compareData->getRawData() , value1 , value2 , manager); } } } catch (XMLException &e) { errorMsg = XMLString::replicate(e.getMessage(), manager); } if(errorMsg) { ArrayJanitor<XMLCh> jan(errorMsg, manager); ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::RethrowError, errorMsg, manager); } }
void UnionDatatypeValidator::init(DatatypeValidator* const baseValidator , RefHashTableOf<KVStringPair>* const facets , RefArrayVectorOf<XMLCh>* const enums , MemoryManager* const manager) { if (enums) setEnumeration(enums, false); // Set Facets if any defined if (facets) { 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 { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException , XMLExcepts::FACET_Invalid_Tag , key , manager); } }//while /*** Schema constraint: Part I -- self checking ***/ // Nil /*** Schema constraint: Part II base vs derived checking ***/ // check 4.3.5.c0 must: enumeration values from the value space of base if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) && (getEnumeration() !=0)) { int i = 0; int enumLength = getEnumeration()->size(); try { for ( ; i < enumLength; i++) { // ask parent do a complete check // // enum need NOT be passed this->checkContent() // since there are no other facets for Union, parent // checking is good enough. // baseValidator->validate(getEnumeration()->elementAt(i), (ValidationContext*)0, manager); } } catch ( XMLException& ) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException , XMLExcepts::FACET_enum_base , getEnumeration()->elementAt(i) , manager); } } }// End of Facet setting /*** Inherit facets from base.facets The reason of this inheriting (or copying values) is to ease schema constraint checking, so that we need NOT trace back to our very first base validator in the hierachy. Instead, we are pretty sure checking against immediate base validator is enough. ***/ UnionDatatypeValidator *pBaseValidator = (UnionDatatypeValidator*) baseValidator; // inherit enumeration if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) !=0) && ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) == 0)) { setEnumeration(pBaseValidator->getEnumeration(), true); } }
// // 1) the bottom level UnionDTV would check against // pattern and enumeration as well // 2) each UnionDTV(s) above the bottom level UnionDTV and // below the native UnionDTV (the top level DTV) // would check against pattern only. // 3) the natvie Union DTV (the top level DTV) would invoke // memberTypeValidator to validate // void UnionDatatypeValidator::checkContent(const XMLCh* const content , ValidationContext* const context , bool asBase , MemoryManager* const manager) { DatatypeValidator* bv = getBaseValidator(); if (bv) ((UnionDatatypeValidator*)bv)->checkContent(content, context, true, manager); else { // 3) native union type // check content against each member type validator in Union // report an error only in case content is not valid against all member datatypes. // bool memTypeValid = false; for ( unsigned int i = 0; i < fMemberTypeValidators->size(); ++i ) { if ( memTypeValid ) break; try { fMemberTypeValidators->elementAt(i)->validate(content, context, manager); memTypeValid = true; //set the validator of the type actually used to validate the content DatatypeValidator *dtv = fMemberTypeValidators->elementAt(i); fValidatedDatatype = dtv; // context will be null during schema construction if(context) context->setValidatingMemberType(dtv); } catch (XMLException&) { //absorbed } } // for if ( !memTypeValid ) { ThrowXMLwithMemMgr1(InvalidDatatypeValueException , XMLExcepts::VALUE_no_match_memberType , content , manager); //( "Content '"+content+"' does not match any union types" ); } } // 1) and 2). we check pattern first if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 ) { if (getRegex()->matches(content, manager) == false) { ThrowXMLwithMemMgr2(InvalidDatatypeValueException , XMLExcepts::VALUE_NotMatch_Pattern , content , getPattern() , manager); } } // if this is a base validator, we only need to check pattern facet // all other facet were inherited by the derived type if (asBase) return; if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 && (getEnumeration() != 0)) { // If the content match (compare equal) any enumeration with // any of the member types, it is considerd valid. // RefVectorOf<DatatypeValidator>* memberDTV = getMemberTypeValidators(); RefArrayVectorOf<XMLCh>* tmpEnum = getEnumeration(); unsigned int memberTypeNumber = memberDTV->size(); unsigned int enumLength = tmpEnum->size(); for ( unsigned int memberIndex = 0; memberIndex < memberTypeNumber; ++memberIndex) { for ( unsigned int enumIndex = 0; enumIndex < enumLength; ++enumIndex) { try { if (memberDTV->elementAt(memberIndex)->compare(content, tmpEnum->elementAt(enumIndex), manager) == 0) return; } catch (XMLException&) { //absorbed } } // for enumIndex } // for memberIndex ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager); } // enumeration }