You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2001/10/09 23:00:54 UTC
cvs commit: xml-xerces/c/src/validators/datatype AbstractStringValidator.cpp AbstractStringValidator.hpp
peiyongz 01/10/09 14:00:54
Modified: c/src/validators/datatype AbstractStringValidator.cpp
AbstractStringValidator.hpp
Log:
. init() take 1 arg,
. make inspectFacetBase() virtual to allow ListDTV provide its own method,
. reorganize init() into assignFacet(), inspectFacet(), inspectFacetBase() and
inheritFacet() to improve mantainability.
. macro to simplify code
. save get***() to temp vars
Revision Changes Path
1.5 +395 -380 xml-xerces/c/src/validators/datatype/AbstractStringValidator.cpp
Index: AbstractStringValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/AbstractStringValidator.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractStringValidator.cpp 2001/09/24 15:30:16 1.4
+++ AbstractStringValidator.cpp 2001/10/09 21:00:54 1.5
@@ -56,6 +56,14 @@
/*
* $Log: AbstractStringValidator.cpp,v $
+ * Revision 1.5 2001/10/09 21:00:54 peiyongz
+ * . init() take 1 arg,
+ * . make inspectFacetBase() virtual to allow ListDTV provide its own method,
+ * . reorganize init() into assignFacet(), inspectFacet(), inspectFacetBase() and
+ * inheritFacet() to improve mantainability.
+ * . macro to simplify code
+ * . save get***() to temp vars
+ *
* Revision 1.4 2001/09/24 15:30:16 peiyongz
* DTV Reorganization: init() to be invoked from derived class' ctor to allow
* correct resolution of virtual methods like assignAdditionalFacet(),
@@ -87,6 +95,23 @@
static XMLCh value1[BUF_LEN+1];
static XMLCh value2[BUF_LEN+1];
+#define REPORT_FACET_ERROR(val1, val2, except_code) \
+ XMLString::binToText(val1, value1, BUF_LEN, 10); \
+ XMLString::binToText(val2, value2, BUF_LEN, 10); \
+ ThrowXML2(InvalidDatatypeFacetException \
+ , except_code \
+ , value1 \
+ , value2);
+
+#define REPORT_VALUE_ERROR(data, val1, val2, except_code) \
+ XMLString::binToText(val1, value1, BUF_LEN, 10); \
+ XMLString::binToText(val2, value2, BUF_LEN, 10); \
+ ThrowXML3(InvalidDatatypeValueException \
+ , except_code \
+ , data \
+ , value1 \
+ , value2);
+
// ---------------------------------------------------------------------------
// Constructors and Destructor
// ---------------------------------------------------------------------------
@@ -117,356 +142,358 @@
// assigneAdditionalFacet(), inheritAdditionalFacet().
}
-//
-// P1. Enumeration
+void AbstractStringValidator::init(RefVectorOf<XMLCh>* const enums)
+{
+
+ if (enums)
+ setEnumeration(enums, false);
+
+ assignFacet();
+ inspectFacet();
+ inspectFacetBase();
+ inheritFacet();
+
+}
+
//
-// P2. Facets
-// a. assign facets
+// Assign facets
// assign common facets
// assign additional facet
//
-// b. check facet among self
-// c. check vs base
-// check common facets
-// check enumeration
-// check Additional Facet Constraint
-//
-// P3. Inherit facet from base
-// a. inherit common facets
-// b. inherit additional facet
-//
-void AbstractStringValidator::init(DatatypeValidator* const baseValidator
- , RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums)
+void AbstractStringValidator::assignFacet()
{
- // P1. process enumeration
- if (enums)
- setEnumeration(enums, false);
+ RefHashTableOf<KVStringPair>* facets = getFacets();
+
+ if (!facets)
+ return;
+
+ XMLCh* key;
+ XMLCh* value;
+ RefHashTableOfEnumerator<KVStringPair> e(facets);
- // P2. process facets
- if (facets)
+ while (e.hasMoreElements())
{
- XMLCh* key;
- XMLCh* value;
- RefHashTableOfEnumerator<KVStringPair> e(facets);
-
- while (e.hasMoreElements())
- {
- KVStringPair pair = e.nextElement();
- key = pair.getKey();
- value = pair.getValue();
-
- if (XMLString::compareString(key, SchemaSymbols::fgELT_LENGTH)==0)
- {
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value);
- }
+ KVStringPair pair = e.nextElement();
+ key = pair.getKey();
+ value = pair.getValue();
+
+ if (XMLString::compareString(key, SchemaSymbols::fgELT_LENGTH)==0)
+ {
+ int val;
+ try
+ {
+ val = XMLString::parseInt(value);
+ }
+ catch (NumberFormatException nfe)
+ {
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value);
+ }
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value);
+ if ( val < 0 )
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value);
setLength(val);
setFacetsDefined(DatatypeValidator::FACET_LENGTH);
+ }
+ else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0)
+ {
+ int val;
+ try
+ {
+ val = XMLString::parseInt(value);
}
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0)
+ catch (NumberFormatException nfe)
{
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value);
- }
-
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value);
-
- setMinLength(val);
- setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0)
- {
- int val;
- try
- {
- val = XMLString::parseInt(value);
- }
- catch (NumberFormatException nfe)
- {
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value);
- }
-
- if ( val < 0 )
- ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value);
-
- setMaxLength(val);
- setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgELT_PATTERN)==0)
- {
- setPattern(value);
- if (getPattern())
- setFacetsDefined(DatatypeValidator::FACET_PATTERN);
- // do not construct regex until needed
- }
- else if (XMLString::compareString(key, SchemaSymbols::fgATT_FIXED)==0)
- {
- unsigned int val;
- bool retStatus;
- try
- {
- retStatus = XMLString::textToBin(value, val);
- }
- catch (RuntimeException)
- {
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
- }
-
- if (!retStatus)
- {
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
- }
-
- setFixed(val);
- //no setFacetsDefined here
- }
- //
- // else if (XMLString::compareString(key, SchemaSymbols::fgELT_SPECIAL_TOKEN)==0)
- // TODO
- //
- // Note: whitespace is taken care of by TraverseSchema.
- //
- else
- {
- assignAdditionalFacet(key, value);
-
- }
- }//while
-
- /***
- Schema constraint: Part I -- self checking
- ***/
-
- int thisFacetsDefined = getFacetsDefined();
-
- // check 4.3.1.c1 error: length & (maxLength | minLength)
- if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0)
- {
- if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
- else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
- }
-
- // check 4.3.2.c1 must: minLength <= maxLength
- if ((thisFacetsDefined & (DatatypeValidator::FACET_MINLENGTH
- |DatatypeValidator::FACET_MAXLENGTH)) != 0)
- {
- if ( getMinLength() > getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_minLen
- , value1
- , value2);
- }
- }
-
- /***
- Schema constraint: Part II base vs derived checking
- ***/
- if (baseValidator)
- {
- /***
- check facets against base.facets
- Note: later we need to check the "fix" option of the base type
- and apply that to every individual facet.
- ***/
- AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) baseValidator;
- int baseFacetsDefined = pBaseValidator->getFacetsDefined();
- /***
- Non coexistence of derived' length and base' (minLength | maxLength)
- base' length and derived' (minLength | maxLength)
- ***/
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value);
+ }
+
+ if ( val < 0 )
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value);
- // check 4.3.1.c1 error: length & (base.maxLength | base.minLength)
- if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
+ setMinLength(val);
+ setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
+ }
+ else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0)
+ {
+ int val;
+ try
{
- if ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
- else if ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
+ val = XMLString::parseInt(value);
}
-
- // check 4.3.1.c1 error: base.length & (maxLength | minLength)
- if ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
+ catch (NumberFormatException nfe)
{
- if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
- else if ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0)
- ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value);
}
+
+ if ( val < 0 )
+ ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value);
- // check 4.3.1.c2 error: length != base.length
- if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) &&
- ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0))
+ setMaxLength(val);
+ setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
+ }
+ else if (XMLString::compareString(key, SchemaSymbols::fgELT_PATTERN)==0)
+ {
+ setPattern(value);
+ if (getPattern())
+ setFacetsDefined(DatatypeValidator::FACET_PATTERN);
+ // do not construct regex until needed
+ }
+ else if (XMLString::compareString(key, SchemaSymbols::fgATT_FIXED)==0)
+ {
+ unsigned int val;
+ bool retStatus;
+ try
{
- if ( getLength() != pBaseValidator->getLength() )
- {
- XMLString::binToText(getLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getLength(), value2, BUF_LEN, 10);
+ retStatus = XMLString::textToBin(value, val);
+ }
+ catch (RuntimeException)
+ {
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
+ }
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_Len_baseLen
- , value1
- , value2);
- }
+ if (!retStatus)
+ {
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
}
+
+ setFixed(val);
+ //no setFacetsDefined here
+ }
+ //
+ // else if (XMLString::compareString(key, SchemaSymbols::fgELT_SPECIAL_TOKEN)==0)
+ // TODO
+ //
+ // Note: whitespace is taken care of by TraverseSchema.
+ //
+ else
+ {
+ assignAdditionalFacet(key, value);
+ }
+ }//while
+}//end of assigneFacet()
+
+//
+// Check facet among self
+// check common facets
+// check Additional Facet Constraint
+//
+void AbstractStringValidator::inspectFacet()
+{
+
+ 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)
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
+ else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
+ }
+
+ // 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)
+ }
+ }
+
+}// end of inspectFacet()
+
+//
+// Check vs base
+// check common facets
+// check enumeration
+// check Additional Facet Constraint
+//
+void AbstractStringValidator::inspectFacetBase()
+{
+
+ AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator();
+ int thisFacetsDefined = getFacetsDefined();
+
+ if ( (!thisFacetsDefined && !fEnumeration) ||
+ (!pBaseValidator) )
+ return;
+
+ int baseFacetsDefined = pBaseValidator->getFacetsDefined();
+
+ int thisLength = getLength();
+ int thisMinLength = getMinLength();
+ int thisMaxLength = getMaxLength();
+
+ int baseLength = pBaseValidator->getLength();
+ int baseMinLength = pBaseValidator->getMinLength();
+ int baseMaxLength = pBaseValidator->getMaxLength();
+ int baseFixed = pBaseValidator->getFixed();
+
+ /***
+ check facets against base.facets
+ Note: later we need to check the "fix" option of the base type
+ and apply that to every individual facet.
+ ***/
+
+ /***
+ Non coexistence of derived' length and base' (minLength | maxLength)
+ base' length and derived' (minLength | maxLength)
+ ***/
+
+ // check 4.3.1.c1 error: length & (base.maxLength | base.minLength)
+ if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
+ {
+ if ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
+ else if ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0)
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
+ }
+
+ // check 4.3.1.c1 error: base.length & (maxLength | minLength)
+ if ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0)
+ {
+ if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0)
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
+ else if ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0)
+ ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
+ }
+
+ // check 4.3.1.c2 error: length != base.length
+ if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0) &&
+ ((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) !=0))
+ {
+ if ( thisLength != baseLength )
+ {
+ REPORT_FACET_ERROR(thisLength
+ , baseLength
+ , XMLExcepts::FACET_Len_baseLen)
+ }
+ }
- /***
+ /***
|--- derived ---|
base.minLength <= minLength <= maxLength <= base.maxLength
|------------------- base -------------------|
- ***/
+ ***/
- // check 4.3.2.c1 must: minLength <= base.maxLength
- if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH ) != 0) &&
- ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH ) != 0))
- {
- if ( getMinLength() > pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_baseminLen
- , value1
- , value2);
- }
- }
-
- // check 4.3.2.c2 error: minLength < base.minLength
- if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
- {
- if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MINLENGTH) !=0)
- {
- if ( getMinLength() != pBaseValidator->getMinLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_base_fixed
- , value1
- , value2);
- }
- }
- else
- {
- if ( getMinLength() < pBaseValidator->getMinLength() )
- {
- XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_minLen_basemaxLen
- , value1
- , value2);
- }
- }
- }
-
- // check 4.3.2.c1 must: base.minLength <= maxLength
- if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
- {
- if ( pBaseValidator->getMinLength() > getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_baseminLen
- , value1
- , value2);
- }
- }
-
- // check 4.3.3.c1 error: maxLength > base.maxLength
- if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
- ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
- {
- if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MAXLENGTH) !=0)
- {
- if ( getMaxLength() != pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_base_fixed
- , value1
- , value2);
- }
- }
- else
- {
- if ( getMaxLength() > pBaseValidator->getMaxLength() )
- {
- XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
- XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML2(InvalidDatatypeFacetException
- , XMLExcepts::FACET_maxLen_basemaxLen
- , value1
- , value2);
- }
- }
- }
-
- // check 4.3.5.c0 must: enumeration values from the value space of base
- if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&
- (getEnumeration() !=0))
- {
- int i = 0;
- int enumLength = getEnumeration()->size();
- try
- {
- for ( ; i < enumLength; i++)
- {
- // ask parent do a complete check
- pBaseValidator->checkContent(getEnumeration()->elementAt(i), false);
- // enum shall pass this->checkContent() as well.
- checkContent(getEnumeration()->elementAt(i), false);
- }
- }
-
- catch (...) //XMLException&
- {
- ThrowXML1(InvalidDatatypeFacetException
- , XMLExcepts::FACET_enum_base
- , getEnumeration()->elementAt(i));
- }
+ // check 4.3.2.c1 must: minLength <= base.maxLength
+ if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH ) != 0) &&
+ ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH ) != 0))
+ {
+ if ( thisMinLength > baseMaxLength )
+ {
+ REPORT_FACET_ERROR(thisMinLength
+ , baseMaxLength
+ , XMLExcepts::FACET_minLen_basemaxLen)
+ }
+ }
+
+ // check 4.3.2.c2 error: minLength < base.minLength
+ if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
+ ((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
+ {
+ if ((baseFixed & DatatypeValidator::FACET_MINLENGTH) !=0)
+ {
+ if ( thisMinLength != baseMinLength )
+ {
+ REPORT_FACET_ERROR(thisMinLength
+ , baseMinLength
+ , XMLExcepts::FACET_minLen_base_fixed)
}
- checkAdditionalFacetConstraints();
+ }
+ else
+ {
+ if ( thisMinLength < baseMinLength )
+ {
+ REPORT_FACET_ERROR(thisMinLength
+ , baseMinLength
+ , XMLExcepts::FACET_minLen_baseminLen)
+ }
+ }
+ }
- } //if baseValidator
+ // check 4.3.2.c1 must: base.minLength <= maxLength
+ if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
+ ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
+ {
+ if ( baseMinLength > thisMaxLength )
+ {
+ REPORT_FACET_ERROR(thisMaxLength
+ , baseMinLength
+ , XMLExcepts::FACET_maxLen_baseminLen)
+ }
+ }
- }// End of Facet setting
+ // check 4.3.3.c1 error: maxLength > base.maxLength
+ if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
+ ((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0))
+ {
+ if ((baseFixed & DatatypeValidator::FACET_MAXLENGTH) !=0)
+ {
+ if ( thisMaxLength != baseMaxLength )
+ {
+ REPORT_FACET_ERROR(thisMaxLength
+ , baseMaxLength
+ , XMLExcepts::FACET_maxLen_base_fixed)
+ }
+ }
+ else
+ {
+ if ( thisMaxLength > baseMaxLength )
+ {
+ REPORT_FACET_ERROR(thisMaxLength
+ , baseMaxLength
+ , XMLExcepts::FACET_maxLen_basemaxLen)
+ }
+ }
+ }
+ // check 4.3.5.c0 must: enumeration values from the value space of base
+ if ( ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0) &&
+ (getEnumeration() !=0))
+ {
+ int i = 0;
+ int enumLength = getEnumeration()->size();
+ try
+ {
+ for ( ; i < enumLength; i++)
+ {
+ // ask parent do a complete check
+ pBaseValidator->checkContent(getEnumeration()->elementAt(i), false);
+ // enum shall pass this->checkContent() as well.
+ checkContent(getEnumeration()->elementAt(i), false);
+ }
+ }
+
+ catch (...) //XMLException&
+ {
+ ThrowXML1(InvalidDatatypeFacetException
+ , XMLExcepts::FACET_enum_base
+ , getEnumeration()->elementAt(i));
+ }
+ }
+
+ checkAdditionalFacetConstraints();
+
+} //end of inspectFacetBase
+
+//
+// Inherit facet from base
+// a. inherit common facets
+// b. inherit additional facet
+//
+void AbstractStringValidator::inheritFacet()
+{
/***
P3. Inherit facets from base.facets
@@ -475,53 +502,56 @@
very first base validator in the hierachy. Instead, we are pretty
sure checking against immediate base validator is enough.
***/
- if (baseValidator)
+
+ AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) getBaseValidator();
+
+ if (!pBaseValidator)
+ return;
+
+ int thisFacetsDefined = getFacetsDefined();
+ int baseFacetsDefined = pBaseValidator->getFacetsDefined();
+
+ // inherit length
+ if (((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
+ ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) == 0))
{
- AbstractStringValidator *pBaseValidator = (AbstractStringValidator*) baseValidator;
- int thisFacetsDefined = getFacetsDefined();
- int baseFacetsDefined = pBaseValidator->getFacetsDefined();
+ setLength(pBaseValidator->getLength());
+ setFacetsDefined(DatatypeValidator::FACET_LENGTH);
+ }
- // inherit length
- if (((baseFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
- ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) == 0))
- {
- setLength(pBaseValidator->getLength());
- setFacetsDefined(DatatypeValidator::FACET_LENGTH);
- }
+ // inherit minLength
+ if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
+ ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) == 0))
+ {
+ setMinLength(pBaseValidator->getMinLength());
+ setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
+ }
- // inherit minLength
- if (((baseFacetsDefined & DatatypeValidator::FACET_MINLENGTH) !=0) &&
- ((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) == 0))
- {
- setMinLength(pBaseValidator->getMinLength());
- setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
- }
+ // inherit maxLength
+ if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
+ ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) == 0))
+ {
+ setMaxLength(pBaseValidator->getMaxLength());
+ setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
+ }
- // inherit maxLength
- if (((baseFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
- ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) == 0))
- {
- setMaxLength(pBaseValidator->getMaxLength());
- setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
- }
+ // inherit enumeration
+ if (((baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) !=0) &&
+ ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0))
+ {
+ setEnumeration(pBaseValidator->getEnumeration(), true);
+ }
- // inherit enumeration
- if (((baseFacetsDefined & DatatypeValidator::FACET_ENUMERATION) !=0) &&
- ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) == 0))
- {
- setEnumeration(pBaseValidator->getEnumeration(), true);
- }
+ // we don't inherit pattern
- // we don't inherit pattern
+ // inherit "fixed" option
+ setFixed(getFixed() | pBaseValidator->getFixed());
- // inherit "fixed" option
- setFixed(getFixed() | pBaseValidator->getFixed());
+ // inherit additional facet
+ inheritAdditionalFacet();
- // inherit additional facet
- inheritAdditionalFacet();
-
- } // end of inheritance
-}
+} // end of inheritance
+
// -----------------------------------------------------------------------
// Compare methods
@@ -581,40 +611,28 @@
if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
(length > getMaxLength()))
{
- XMLString::binToText(length, value1, BUF_LEN, 10);
- XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10);
-
- ThrowXML3(InvalidDatatypeValueException
- , XMLExcepts::VALUE_GT_maxLen
- , content
- , value1
- , value2);
+ REPORT_VALUE_ERROR(content
+ , length
+ , getMaxLength()
+ , XMLExcepts::VALUE_GT_maxLen)
}
if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) &&
(length < getMinLength()))
{
- XMLString::binToText(length, value1, BUF_LEN, 10);
- XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
-
- ThrowXML3(InvalidDatatypeValueException
- , XMLExcepts::VALUE_LT_minLen
- , content
- , value1
- , value2);
+ REPORT_VALUE_ERROR(content
+ , length
+ , getMinLength()
+ , XMLExcepts::VALUE_LT_minLen)
}
if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
(length != getLength()))
{
- XMLString::binToText(length, value1, BUF_LEN, 10);
- XMLString::binToText(getLength(), value2, BUF_LEN, 10);
-
- ThrowXML3(InvalidDatatypeValueException
- , XMLExcepts::VALUE_NE_Len
- , content
- , value1
- , value2);
+ REPORT_VALUE_ERROR(content
+ , length
+ , getLength()
+ , XMLExcepts::VALUE_NE_Len)
}
if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 &&
1.5 +16 -4 xml-xerces/c/src/validators/datatype/AbstractStringValidator.hpp
Index: AbstractStringValidator.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/AbstractStringValidator.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractStringValidator.hpp 2001/09/27 13:51:25 1.4
+++ AbstractStringValidator.hpp 2001/10/09 21:00:54 1.5
@@ -55,8 +55,16 @@
*/
/*
- * $Id: AbstractStringValidator.hpp,v 1.4 2001/09/27 13:51:25 peiyongz Exp $
+ * $Id: AbstractStringValidator.hpp,v 1.5 2001/10/09 21:00:54 peiyongz Exp $
* $Log: AbstractStringValidator.hpp,v $
+ * Revision 1.5 2001/10/09 21:00:54 peiyongz
+ * . init() take 1 arg,
+ * . make inspectFacetBase() virtual to allow ListDTV provide its own method,
+ * . reorganize init() into assignFacet(), inspectFacet(), inspectFacetBase() and
+ * inheritFacet() to improve mantainability.
+ * . macro to simplify code
+ * . save get***() to temp vars
+ *
* Revision 1.4 2001/09/27 13:51:25 peiyongz
* DTV Reorganization: ctor/init created to be used by derived class
*
@@ -128,9 +136,7 @@
, const int finalSet
, const ValidatorType type);
- void init(DatatypeValidator* const baseValidator
- , RefHashTableOf<KVStringPair>* const facets
- , RefVectorOf<XMLCh>* const enums);
+ void init(RefVectorOf<XMLCh>* const enums);
//
// Abstract interface
@@ -148,6 +154,11 @@
virtual int getLength(const XMLCh* const content) const = 0;
+ //
+ // to Allow ListDTV to overwrite
+ //
+ virtual void inspectFacetBase();
+
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
@@ -175,6 +186,12 @@
private:
void checkContent(const XMLCh* const content, bool asBase);
+
+ void assignFacet();
+
+ void inspectFacet();
+
+ void inheritFacet();
// -----------------------------------------------------------------------
// Private data members
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org