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 Base64BinaryDatatypeValidator::normalizeEnumeration(MemoryManager* const manager) { XMLSize_t enumLength = getEnumeration()->size(); for ( XMLSize_t i=0; i < enumLength; i++) { XMLString::removeWS(getEnumeration()->elementAt(i), manager); } }
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); }
// ----------------------------------------------------------------------- // 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); }
// // 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 }
// ----------------------------------------------------------------------- // 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); } }
const RefArrayVectorOf<XMLCh>* UnionDatatypeValidator::getEnumString() const { return getEnumeration(); }
// // 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 }
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); } }