Author: mukulg
Date: Thu Feb 10 09:15:08 2011
New Revision: 1069296
URL: http://svn.apache.org/viewvc?rev=1069296&view=rev
Log:
committing changes for jira issue XERCESJ-1496. the commit also does
miscellaneous refactoring of code base.
Modified:
xerces/java/branches/xml-schema-1.1-dev/samples/jaxp/SourceValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/samples/jaxp/SourceValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/samples/jaxp/SourceValidator.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/samples/jaxp/SourceValidator.java
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/samples/jaxp/SourceValidator.java
Thu Feb 10 09:15:08 2011
@@ -88,6 +88,9 @@ public class SourceValidator
/** Generate synthetic schema annotations feature id
(http://apache.org/xml/features/generate-synthetic-annotations). */
protected static final String GENERATE_SYNTHETIC_ANNOTATIONS_ID =
"http://apache.org/xml/features/generate-synthetic-annotations";
+ /** Enable/prohibit XML Schema 1.1 assertion evaluations on each
simpleType list item */
+ protected static final String SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE =
"http://apache.org/xml/features/validation/foldedSTlist-assertion-evaluation";
+
// property ids
/** StAX support for reporting line and column numbers property id
(javax.xml.stream.isSupportingLocationCoordinates). */
@@ -119,6 +122,9 @@ public class SourceValidator
/** Default generate synthetic schema annotations (false). */
protected static final boolean DEFAULT_GENERATE_SYNTHETIC_ANNOTATIONS =
false;
+ /** Default XML Schema 1.1 simpleType folded list assertion evaluation
(false). */
+ protected static final boolean
DEFAULT_SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION = false;
+
/** Default memory usage report (false). */
protected static final boolean DEFAULT_MEMORY_USAGE = false;
@@ -310,6 +316,7 @@ public class SourceValidator
boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS;
boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS;
boolean generateSyntheticAnnotations =
DEFAULT_GENERATE_SYNTHETIC_ANNOTATIONS;
+ boolean simpleTypeFoldedListAssertionEvaluation =
DEFAULT_SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION;
boolean memoryUsage = DEFAULT_MEMORY_USAGE;
// process arguments
@@ -403,6 +410,10 @@ public class SourceValidator
memoryUsage = option.equals("m");
continue;
}
+ if (option.equalsIgnoreCase("fL11")) {
+ simpleTypeFoldedListAssertionEvaluation =
option.equals("fL11");
+ continue;
+ }
if (option.equals("h")) {
printUsage();
continue;
@@ -511,6 +522,15 @@ public class SourceValidator
catch (SAXNotSupportedException e) {
System.err.println("warning: Validator does not support
feature ("+GENERATE_SYNTHETIC_ANNOTATIONS_ID+")");
}
+ try {
+ validator.setFeature(SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE,
simpleTypeFoldedListAssertionEvaluation);
+ }
+ catch (SAXNotRecognizedException e) {
+ System.err.println("warning: Validator does not recognize
feature ("+SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE+")");
+ }
+ catch (SAXNotSupportedException e) {
+ System.err.println("warning: Validator does not support
feature ("+SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE+")");
+ }
// Validate instance documents
if (instances != null && instances.size() > 0) {
@@ -588,22 +608,24 @@ public class SourceValidator
System.err.println();
System.err.println("options:");
- System.err.println(" -l name Select schema language by name.");
- System.err.println(" -x number Select number of repetitions.");
- System.err.println(" -a uri ... Provide a list of schema documents");
- System.err.println(" -i uri ... Provide a list of instance documents
to validate");
- System.err.println(" -vs source Select validation source
(sax|dom|stax|stream)");
- System.err.println(" -f | -F Turn on/off Schema full checking.");
- System.err.println(" NOTE: Not supported by all schema
factories and validators.");
- System.err.println(" -hs | -HS Turn on/off honouring of all schema
locations.");
- System.err.println(" NOTE: Not supported by all schema
factories and validators.");
- System.err.println(" -va | -VA Turn on/off validation of schema
annotations.");
- System.err.println(" NOTE: Not supported by all schema
factories and validators.");
- System.err.println(" -ga | -GA Turn on/off generation of synthetic
schema annotations.");
- System.err.println(" NOTE: Not supported by all schema
factories and validators.");
- System.err.println(" -m | -M Turn on/off memory usage report");
- System.err.println(" -xsd11 Turn on XSD 1.1 support.");
- System.err.println(" -h This help screen.");
+ System.err.println(" -l name Select schema language by
name.");
+ System.err.println(" -x number Select number of repetitions.");
+ System.err.println(" -a uri ... Provide a list of schema
documents");
+ System.err.println(" -i uri ... Provide a list of instance
documents to validate");
+ System.err.println(" -vs source Select validation source
(sax|dom|stax|stream)");
+ System.err.println(" -f | -F Turn on/off Schema full
checking.");
+ System.err.println(" NOTE: Not supported by all
schema factories and validators.");
+ System.err.println(" -hs | -HS Turn on/off honouring of all
schema locations.");
+ System.err.println(" NOTE: Not supported by all
schema factories and validators.");
+ System.err.println(" -va | -VA Turn on/off validation of schema
annotations.");
+ System.err.println(" NOTE: Not supported by all
schema factories and validators.");
+ System.err.println(" -ga | -GA Turn on/off generation of
synthetic schema annotations.");
+ System.err.println(" NOTE: Not supported by all
schema factories and validators.");
+ System.err.println(" -m | -M Turn on/off memory usage
report");
+ System.err.println(" -xsd11 Turn on XSD 1.1 support.");
+ System.err.println(" -fL11 Turn on/off simpleType folded
list XSD 1.1 assertion evaluation mode.");
+ System.err.println(" NOTE: Not supported by all
schema factories and validators.");
+ System.err.println(" -h This help screen.");
System.err.println();
System.err.println("defaults:");
@@ -618,6 +640,8 @@ public class SourceValidator
System.err.println(DEFAULT_VALIDATE_ANNOTATIONS ? "on" : "off");
System.err.print(" Generate synthetic annotations: ");
System.err.println(DEFAULT_GENERATE_SYNTHETIC_ANNOTATIONS ? "on" :
"off");
+ System.err.print(" Simple Type folded list XSD 1.1 assertion
evaluation: ");
+ System.err.println(DEFAULT_SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION
? "true" : "false");
System.err.print(" Memory: ");
System.err.println(DEFAULT_MEMORY_USAGE ? "on" : "off");
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
Thu Feb 10 09:15:08 2011
@@ -334,6 +334,9 @@ public final class Constants {
/** Feature to ignore errors caused by type alternatives */
public static final String TYPE_ALTERNATIVES_CHEKING_FEATURE =
"validation/type-alternative-checking";
+ /** Feature to enable/prohibit XML Schema 1.1 assertion evaluations on
each simpleType list item */
+ public static final String SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE =
"validation/foldedSTlist-assertion-evaluation";
+
/** Feature to ignore errors caused by unparsed entities
("validation/unparsed-entity-checking") */
public static final String UNPARSED_ENTITY_CHECKING_FEATURE =
"validation/unparsed-entity-checking";
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
Thu Feb 10 09:15:08 2011
@@ -170,8 +170,7 @@ public class XMLAssertPsychopathImpl ext
List assertionList = (List) augs.getItem("ASSERT");
- // if we have assertions applicable to this element, store the element
reference and the assertions on it,
- // on the runtime stacks.
+ // if we have assertions applicable to this element, store the element
reference and the assertions on it on the runtime stacks.
if (assertionList != null) {
fAssertRootStack.push(fCurrentAssertDomNode);
fAssertListStack.push(assertionList);
@@ -209,7 +208,7 @@ public class XMLAssertPsychopathImpl ext
List assertions = (List) fAssertListStack.pop();
Boolean isAssertProcessingNeeded = (Boolean)
augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION");
if (isAssertProcessingNeeded.booleanValue()) {
- // if in a pre-processing step in XMLSchemaValidator, a
member type of union in XML Schema namespace successfully
+ // if in a pre-processing step in XMLSchemaValidator a
member type of union in XML Schema namespace successfully
// validated an atomic value, we don't process assertions
on such union types. For all other use-cases (non union
// simple types or complex types, applicable assertions
would always be processed.
processAllAssertionsOnElement(element, assertions,
elemPSVI);
@@ -226,7 +225,7 @@ public class XMLAssertPsychopathImpl ext
/*
* Method to evaluate all of XML schema 1.1 assertions for an element
tree. This is the root method
- * which evaluates all XML schema assertions, in a single XML instance
validation episode.
+ * which evaluates all XML schema assertions in an XML instance validation
episode.
*/
private void processAllAssertionsOnElement(QName element, List assertions,
ElementPSVI elemPSVI) throws Exception {
@@ -256,7 +255,7 @@ public class XMLAssertPsychopathImpl ext
int textChildCount = 0;
// we are only interested in text & element nodes. Store count of them
in this variable.
- int effectiveChildCount = 0;
+ int effectiveChildNodeCount = 0;
// there could be adjacent text nodes in a DOM tree. merge them to get
the value.
NodeList childList = fCurrentAssertDomNode.getChildNodes();
@@ -267,35 +266,35 @@ public class XMLAssertPsychopathImpl ext
short nodeType = node.getNodeType();
if (nodeType == Node.TEXT_NODE) {
textChildCount++;
- effectiveChildCount++;
+ effectiveChildNodeCount++;
textValueContents.append(node.getNodeValue());
}
else if (nodeType == Node.ELEMENT_NODE) {
- effectiveChildCount++;
+ effectiveChildNodeCount++;
}
}
- String value = "";
+ String strValue = "";
- if (textChildCount == effectiveChildCount) {
+ if (textChildCount == effectiveChildNodeCount) {
// the DOM tree we are inspecting has simple content. therefore we
can find the desired string value.
XSElementDeclaration elemDecl = pElemPSVI.getElementDeclaration();
if
((elemDecl.getTypeDefinition()).derivedFrom(SchemaSymbols.URI_SCHEMAFORSCHEMA,
SchemaSymbols.ATTVAL_STRING, XSConstants.DERIVATION_RESTRICTION)) {
// if element's schema type is derived by restriction from
xs:string, white-space normalization is not needed for the
// string value for context variable $value.
- value = textValueContents.toString();
+ strValue = textValueContents.toString();
}
else {
// white-space normalization is needed for the string value of
$value in case of derivation from non xs:string atomic types.
- value = XMLChar.trim(textValueContents.toString());
+ strValue = XMLChar.trim(textValueContents.toString());
}
}
else {
- // the DOM tree we are inspecting, has 'mixed/element only'
content.
- value = null;
+ // the DOM tree we are inspecting has 'element only/mixed' content.
+ strValue = null;
}
- return value;
+ return strValue;
} // getStringValueOf$Value
@@ -307,11 +306,10 @@ public class XMLAssertPsychopathImpl ext
if (value != null) {
// complex type with simple content
- setTypedValueFor$value(value, null, null);
+ setTypedValueFor$value(value, null, null, false);
} else {
// complex type with complex content. set xpath context variable
$value to an empty sequence.
- fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
- "value"),
getXPath2ResultSequence(new ArrayList()));
+ fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
getXPath2ResultSequence(new ArrayList()));
}
XSObjectList assertList = (XSObjectList) assertions;
@@ -336,7 +334,7 @@ public class XMLAssertPsychopathImpl ext
final boolean isTypeDerivedFromUnion = ((XSSimpleType)
attrType.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
if (assertImpl.getVariety() ==
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
// evaluating assertions for "simpleType -> restriction"
(not derived by union)
- setTypedValueFor$value(value, null, attrType);
+ setTypedValueFor$value(value, null, attrType, false);
AssertionError assertError = evaluateOneAssertion(element,
assertImpl, value, xpathContextExists, false);
if (assertError != null) {
reportAssertionsError(assertError);
@@ -368,7 +366,7 @@ public class XMLAssertPsychopathImpl ext
*/
private void evaluateAssertionsFromASimpleType(QName element, List
assertions, String value, ElementPSVI elemPSVI) throws Exception {
- // find the itemType and memberTypes of xs:list and xs:union
respectively (only one of these will be applicable)
+ // find the itemType and memberTypes of xs:list and xs:union
respectively (only one of these would be applicable)
XSSimpleTypeDefinition itemType = null;
XSObjectList memberTypes = null;
@@ -394,7 +392,7 @@ public class XMLAssertPsychopathImpl ext
}
if (memberTypes != null && memberTypes.getLength() == 0) {
// evaluating assertions for "simpleType -> restriction" (not
derived by union)
- setTypedValueFor$value(value, null, null);
+ setTypedValueFor$value(value, null, null, false);
AssertionError assertError = evaluateOneAssertion(element,
assertImpl, value, false, false);
if (assertError != null) {
reportAssertionsError(assertError);
@@ -414,23 +412,35 @@ public class XMLAssertPsychopathImpl ext
/*
- * Evaluate assertion on a simpleType xs:list value. Assertion is
evaluated on each list item.
+ * Evaluate assertion on a simpleType xs:list value. Assertion would be
evaluated on each list item, or only once for the entire
+ * list depending on status of the JAXP validator feature
http://apache.org/xml/features/validation/foldedSTlist-assertion-evaluation.
*/
- private void evaluateAssertionOnSTListValue(QName element, String
listStrValue, XSAssertImpl assertImpl, boolean xpathContextExists,
- XSSimpleTypeDefinition
itemType) throws Exception {
+ private void evaluateAssertionOnSTListValue(QName element, String
listStrValue, XSAssertImpl assertImpl, boolean xpathContextExists,
XSSimpleTypeDefinition itemType)
+ throws Exception {
- // tokenize the list value by the longest sequence of white-spaces.
- StringTokenizer values = new StringTokenizer(listStrValue, " \n\t\r");
+ boolean isFoldedSTListAssertionEvaluation = ((Boolean)
fAssertParams.get("FOLDED_STLIST_ASSERT_FEATURE")).booleanValue();
- // evaluate assertion on all of list items
- while (values.hasMoreTokens()) {
- String itemValue = values.nextToken();
- setValueOf$valueForAListItem(itemValue, itemType);
- AssertionError assertError = evaluateOneAssertion(element,
assertImpl, itemValue, xpathContextExists, true);
+ if (isFoldedSTListAssertionEvaluation) {
+ setValueOf$valueForSTVarietyList(listStrValue, itemType,
isFoldedSTListAssertionEvaluation);
+ AssertionError assertError = evaluateOneAssertion(element,
assertImpl, listStrValue, xpathContextExists, true);
if (assertError != null) {
+
assertError.setIsFoldedSTListEvaluationMode(isFoldedSTListAssertionEvaluation);
reportAssertionsError(assertError);
}
}
+ else {
+ // evaluate assertion on all of list items
+ // split the "string value" of list contents into non white-space
tokens.
+ StringTokenizer lstStrTokens = new StringTokenizer(listStrValue, "
\n\t\r");
+ while (lstStrTokens.hasMoreTokens()) {
+ String itemValue = lstStrTokens.nextToken();
+ setValueOf$valueForSTVarietyList(itemValue, itemType,
isFoldedSTListAssertionEvaluation);
+ AssertionError assertError = evaluateOneAssertion(element,
assertImpl, itemValue, xpathContextExists, true);
+ if (assertError != null) {
+ reportAssertionsError(assertError);
+ }
+ }
+ }
} // evaluateAssertionOnSTListValue
@@ -446,14 +456,14 @@ public class XMLAssertPsychopathImpl ext
// (perhaps impossible?) to determine statically that what all
assertions can cause validation failure,
// when participating in an XML schema union.
if (isValidationFailedForUnion) {
- fValidator.reportSchemaError("cvc-assertion.union.3.13.4.1",
new Object[] { element.rawname, value } );
+ fValidator.reportSchemaError("cvc-assertion.union.3.13.4.1",
new Object[] {element.rawname, value});
}
}
else if (isTypeDerivedFromUnion) {
// although Xerces XSModel treats this case as a simpleType with
variety union, but from assertions perspective
// this is treated like a "simpleType -> restriction" case (which
also appears to be syntactically true in every case?).
// REVISIT...
- setValueOf$ValueForSTVarietyUnion(value, memberTypes);
+ setValueOf$valueForSTVarietyUnion(value, memberTypes);
AssertionError assertError = evaluateOneAssertion(element,
assertImpl, value, false, false);
if (assertError != null) {
reportAssertionsError(assertError);
@@ -464,47 +474,6 @@ public class XMLAssertPsychopathImpl ext
/*
- * Set a typed value of XPath2 context variable $value if an atomic value
on which assertion is been evaluated, is validated by a
- * simpleType with variety union.
- */
- private void setValueOf$ValueForSTVarietyUnion(String value, XSObjectList
memberTypes) {
-
- // check member types of union in order to find which member type can
successfully validate the string value,
- // and set value of XPath2 context variable $value accordingly.
- for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength();
memTypeIdx++) {
- XSSimpleType simpleTypeDv = (XSSimpleType)
memberTypes.item(memTypeIdx);
- if (XSTypeHelper.isValueValidForASimpleType(value, simpleTypeDv)) {
- short xsdTypecode = getXercesXSDTypeCodeFor$Value(simpleTypeDv);
- setValueOf$ValueForSTVarietyAtomic(value, xsdTypecode);
- break;
- }
- }
-
- } // setValueOf$ValueForSTVarietyUnion
-
-
- /*
- * Set a typed value of XPath2 context variable $value if an atomic value
on which assertion is been evaluated,
- * is an item of a schema component xs:list.
- */
- private void setValueOf$valueForAListItem(String value,
XSSimpleTypeDefinition simpType) throws Exception {
-
- XSObjectList memberTypes = simpType.getMemberTypes();
- if (memberTypes.getLength() > 0) {
- // the list item's type has variety 'union'.
- XSSimpleTypeDefinition actualListItemType =
getActualListItemTypeForVarietyUnion(memberTypes, value);
- // set a schema 'typed value' to variable $value
- setTypedValueFor$value(value, actualListItemType, null);
- }
- else {
- // the list item's type has variety 'atomic'.
- setTypedValueFor$value(value, simpType, null);
- }
-
- } // setValueOf$valueForAListItem
-
-
- /*
* Determine if an validation must fail due to assertions evaluation for
"simpleType -> union" member types.
*/
private boolean isValidationFailedForUnion(XSObjectList memberTypes, QName
element, String value, boolean isAttribute) {
@@ -527,7 +496,7 @@ public class XMLAssertPsychopathImpl ext
for (Iterator iter = assertFacets.iterator();
iter.hasNext(); ) {
XSAssertImpl assertImpl = (XSAssertImpl)
iter.next();
try {
- setTypedValueFor$value(value, memType, null);
+ setTypedValueFor$value(value, memType, null,
false);
AssertionError assertError =
evaluateOneAssertion(element, assertImpl, value, false, false);
if (assertError == null) {
assertsSucceeded++;
@@ -639,14 +608,26 @@ public class XMLAssertPsychopathImpl ext
/*
* Find a "schema typed value" (of kind xs:anyAtomicType*) to assign to
XPath2 context variable $value.
*/
- private void setTypedValueFor$value(String value, XSSimpleTypeDefinition
listOrUnionType, XSTypeDefinition attrType) throws Exception {
+ private void setTypedValueFor$value(String value, XSSimpleTypeDefinition
listOrUnionType, XSTypeDefinition attrType, boolean
isFoldedListAssertionEvaluation) throws Exception {
- // dummy short code initializer
+ // dummy "schema type" short code initializer
short xsdTypecode = -100;
if (listOrUnionType != null) {
- xsdTypecode = getXercesXSDTypeCodeFor$Value(listOrUnionType);
- setValueOf$ValueForSTVarietyAtomic(value, xsdTypecode);
+ if (isFoldedListAssertionEvaluation) {
+ List xdmItemList = new ArrayList();
+ // split the "string value" of list contents into non
white-space tokens
+ StringTokenizer lstStrTokens = new StringTokenizer(value, "
\n\t\r");
+ while (lstStrTokens.hasMoreTokens()) {
+ String itemValue = lstStrTokens.nextToken();
+
xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listOrUnionType.getBuiltInKind(),
itemValue));
+ }
+ fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
getXPath2ResultSequence(xdmItemList));
+ }
+ else {
+ xsdTypecode = getXercesXSDTypeCodeFor$Value(listOrUnionType);
+ setValueOf$ValueForSTVarietyAtomic(value, xsdTypecode);
+ }
}
else {
if (attrType != null) {
@@ -675,7 +656,6 @@ public class XMLAssertPsychopathImpl ext
} // setTypedValueFor$value
-
/*
* Set value of XPath2 context variable $value, when variety of it's
schema type is "simpleType -> atomic".
*/
@@ -684,6 +664,45 @@ public class XMLAssertPsychopathImpl ext
fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
"value"), (AnyAtomicType)
psychoPathType);
} // setValueOf$ValueForSTVarietyAtomic
+
+ /*
+ * Set a typed value of XPath2 context variable $value if the value on
which assertion is been evaluated, is value of simpleType list.
+ */
+ private void setValueOf$valueForSTVarietyList(String value,
XSSimpleTypeDefinition simpType, boolean isFoldedListAssertionEvaluation)
throws Exception {
+
+ XSObjectList memberTypes = simpType.getMemberTypes();
+ if (memberTypes.getLength() > 0) {
+ // the list item's type has variety 'union'.
+ XSSimpleTypeDefinition actualListItemType =
getActualListItemTypeForVarietyUnion(memberTypes, value);
+ // set a schema 'typed value' to variable $value
+ setTypedValueFor$value(value, actualListItemType, null,
isFoldedListAssertionEvaluation);
+ }
+ else {
+ // the list item's type has variety 'atomic'.
+ setTypedValueFor$value(value, simpType, null,
isFoldedListAssertionEvaluation);
+ }
+
+ } // setValueOf$valueForSTVarietyList
+
+
+ /*
+ * Set a typed value of XPath2 context variable $value if an atomic value
on which assertion is been evaluated, is validated by a
+ * simpleType with variety union.
+ */
+ private void setValueOf$valueForSTVarietyUnion(String value, XSObjectList
memberTypes) {
+
+ // check member types of union in order to find which member type can
successfully validate the string value,
+ // and set value of XPath2 context variable $value accordingly.
+ for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength();
memTypeIdx++) {
+ XSSimpleType simpleTypeDv = (XSSimpleType)
memberTypes.item(memTypeIdx);
+ if (XSTypeHelper.isValueValidForASimpleType(value, simpleTypeDv)) {
+ short xsdTypecode = getXercesXSDTypeCodeFor$Value(simpleTypeDv);
+ setValueOf$ValueForSTVarietyAtomic(value, xsdTypecode);
+ break;
+ }
+ }
+
+ } // setValueOf$ValueForSTVarietyUnion
/*
@@ -693,34 +712,32 @@ public class XMLAssertPsychopathImpl ext
XSComplexTypeDefinition cmplxTypeDef =
(XSComplexTypeDefinition)typeDef;
XSSimpleTypeDefinition complexTypeSimplContentType =
cmplxTypeDef.getSimpleType();
+
if (complexTypeSimplContentType.getVariety() ==
XSSimpleTypeDefinition.VARIETY_LIST) {
// simple content type has variety xs:list
XSSimpleTypeDefinition listItemType =
complexTypeSimplContentType.getItemType();
- // split the "string value" of list contents, into non white-space
tokens.
- StringTokenizer values = new StringTokenizer(value, " \n\t\r");
-
- // construct a list of atomic XDM items, to assign to XPath2
context variable $value.
+ // construct a list of atomic XDM items to assign to XPath2
context variable $value.
List xdmItemList = new ArrayList();
final XSObjectList memberTypes = listItemType.getMemberTypes();
+ // split the "string value" of list contents into non white-space
tokens
+ StringTokenizer lstStrTokens = new StringTokenizer(value, "
\n\t\r");
if (memberTypes.getLength() > 0) {
// itemType of xs:list has variety 'union'. here list items may
have different types, which are determined below.
- while (values.hasMoreTokens()) {
- String itemValue = values.nextToken();
+ while (lstStrTokens.hasMoreTokens()) {
+ String itemValue = lstStrTokens.nextToken();
XSSimpleTypeDefinition listItemTypeForUnion =
getActualListItemTypeForVarietyUnion(memberTypes, itemValue);
xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemTypeForUnion.getBuiltInKind(),
itemValue));
}
}
else {
// every list item has a same type (the itemType of xs:list).
- while (values.hasMoreTokens()) {
- String itemValue = values.nextToken();
+ while (lstStrTokens.hasMoreTokens()) {
+ String itemValue = lstStrTokens.nextToken();
xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemType.getBuiltInKind(),
itemValue));
}
}
-
// assign an XPath2 sequence to xpath context variable $value
- fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
- "value"),
getXPath2ResultSequence(xdmItemList));
+ fXpath2DynamicContext.set_variable(new
org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
getXPath2ResultSequence(xdmItemList));
}
else if (complexTypeSimplContentType.getVariety() ==
XSSimpleTypeDefinition.VARIETY_UNION) {
// simple content type has variety xs:union
@@ -737,29 +754,27 @@ public class XMLAssertPsychopathImpl ext
/*
- Find the built-in Xerces schema 'type code' for XPath2 variable,
$value. This function recursively
- searches the XML schema type hierarchy navigating up the base types, to
find the needed built-in type.
+ Find the built-in Xerces schema 'type code' for XPath2 variable $value.
This function recursively searches the XML schema type hierarchy
+ navigating up the base types to find the needed built-in type.
*/
private short getXercesXSDTypeCodeFor$Value(XSTypeDefinition elementType) {
if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) {
- short typeCode = -100; // dummy initializer
-
- boolean isxsd11Type = false;
-
+ short xsdTypeCode = -100; // dummy initializer
+ boolean isxsd11Type = false;
// the below 'if else' clauses are written to process few special
cases handling few of schema types,
// within PsychoPath XPath engine.
final String elementTypeName = elementType.getName();
if ("dayTimeDuration".equals(elementTypeName)) {
- typeCode = PsychoPathTypeHelper.DAYTIMEDURATION_DT;
+ xsdTypeCode = PsychoPathTypeHelper.DAYTIMEDURATION_DT;
isxsd11Type = true;
}
else if ("yearMonthDuration".equals(elementTypeName)) {
- typeCode = PsychoPathTypeHelper.YEARMONTHDURATION_DT;
+ xsdTypeCode = PsychoPathTypeHelper.YEARMONTHDURATION_DT;
isxsd11Type = true;
}
- return (isxsd11Type) ? typeCode : ((XSSimpleTypeDefinition)
elementType).getBuiltInKind();
+ return (isxsd11Type) ? xsdTypeCode : ((XSSimpleTypeDefinition)
elementType).getBuiltInKind();
}
else {
return getXercesXSDTypeCodeFor$Value(elementType.getBaseType());
@@ -769,7 +784,7 @@ public class XMLAssertPsychopathImpl ext
/*
- * Construct an PsychoPath XPath2 "result sequence", given a list of XDM
items as input.
+ * Construct an PsychoPath XPath2 "result sequence" given a list of XDM
items as input.
*/
private ResultSequence getXPath2ResultSequence(List xdmItems) {
@@ -785,6 +800,29 @@ public class XMLAssertPsychopathImpl ext
/*
+ * Find the actual schema type of "list item" instance, if the "item type"
of list has variety union.
+ */
+ private XSSimpleTypeDefinition
getActualListItemTypeForVarietyUnion(XSObjectList memberTypes, String value) {
+
+ XSSimpleTypeDefinition simpleTypeDefn = null;
+
+ // iterate the member types of union in order, to find that which
schema type can successfully validate an atomic value first.
+ final int memberTypesLength = memberTypes.getLength();
+ for (int memTypeIdx = 0; memTypeIdx < memberTypesLength; memTypeIdx++)
{
+ XSSimpleType memSimpleType = (XSSimpleType)
memberTypes.item(memTypeIdx);
+ if (XSTypeHelper.isValueValidForASimpleType(value, memSimpleType)) {
+ // no more memberTypes need to be checked
+ simpleTypeDefn = memSimpleType;
+ break;
+ }
+ }
+
+ return simpleTypeDefn;
+
+ } // getActualListItemTypeForVarietyUnion
+
+
+ /*
* Method to report assertions error messages.
*/
private void reportAssertionsError(AssertionError assertError) {
@@ -792,17 +830,17 @@ public class XMLAssertPsychopathImpl ext
String key = assertError.getErrorCode();
QName element = assertError.getElement();
XSAssertImpl assertImpl = assertError.getAssertion();
- boolean isList = assertError.isList();
- String value = assertError.getValue();
+ boolean isList = assertError.isSimpleTypeList();
+ String value = assertError.getValue();
XSTypeDefinition typeDef = assertImpl.getTypeDefinition();
- String typeString = "";
+ String typeNameStrValue = "";
if (typeDef != null) {
- typeString = (typeDef.getName() != null) ? typeDef.getName() :
"#anonymous";
+ typeNameStrValue = (typeDef.getName() != null) ? typeDef.getName()
: "#anonymous";
}
else {
- typeString = "#anonymous";
+ typeNameStrValue = "#anonymous";
}
String elemErrorAnnotation = element.rawname;
@@ -812,60 +850,41 @@ public class XMLAssertPsychopathImpl ext
String listAssertErrMessage = "";
if (isList) {
- listAssertErrMessage = "Assertion failed for an xs:list member
value '" + assertError.getValue() + "'.";
+ if (assertError.getIsFoldedListEvaluationMode()) {
+ listAssertErrMessage = "Assertion failed for xs:list '" +
assertError.getValue() + "'.";
+ }
+ else {
+ listAssertErrMessage = "Assertion failed for an xs:list member
value '" + assertError.getValue() + "'.";
+ }
}
String message = assertImpl.getMessage();
if (message != null) {
// substitute all placeholder macro instances of "{$value}" with
atomic value stored in variable "value".
if (value != null && !"".equals(value)) {
- message = message.replaceAll(ERROR_PLACEHOLDER_REGEX, value);
+ message = message.replaceAll(ERROR_PLACEHOLDER_REGEX, value);
}
if (!message.endsWith(".")) {
- message = message + ".";
+ message = message + ".";
}
if (key.equals("cvc-assertion.4.3.15.3")) {
- message = "Assertion failed (undefined context) for schema type
'" + typeString + "'. " + message;
+ message = "Assertion failed (undefined context) for schema type
'" + typeNameStrValue + "'. " + message;
}
else {
- message = "Assertion failed for schema type '" + typeString +
"'. " + message;
+ message = "Assertion failed for schema type '" +
typeNameStrValue + "'. " + message;
}
- fValidator.reportSchemaError("cvc-assertion.failure", new Object[]
{ message, listAssertErrMessage } );
+ fValidator.reportSchemaError("cvc-assertion.failure", new Object[]
{message, listAssertErrMessage});
}
else {
- fValidator.reportSchemaError(key, new Object[]
{elemErrorAnnotation, assertImpl.getTest().getXPath().toString(),
- typeString,
listAssertErrMessage} );
+ fValidator.reportSchemaError(key, new Object[]
{elemErrorAnnotation, assertImpl.getTest().getXPath().toString(),
typeNameStrValue, listAssertErrMessage});
}
} // reportAssertionsError
/*
- * Find the actual schema type of "list item" instance, if the "item type"
of list has variety union.
- */
- private XSSimpleTypeDefinition
getActualListItemTypeForVarietyUnion(XSObjectList memberTypes, String value) {
-
- XSSimpleTypeDefinition simpleTypeDefn = null;
-
- // iterate the member types of union in order, to find that which
schema type can successfully validate an atomic value first.
- final int memberTypesLength = memberTypes.getLength();
- for (int memTypeIdx = 0; memTypeIdx < memberTypesLength; memTypeIdx++)
{
- XSSimpleType memSimpleType = (XSSimpleType)
memberTypes.item(memTypeIdx);
- if (XSTypeHelper.isValueValidForASimpleType(value, memSimpleType)) {
- // no more memberTypes need to be checked
- simpleTypeDefn = memSimpleType;
- break;
- }
- }
-
- return simpleTypeDefn;
-
- } // getActualListItemTypeForVarietyUnion
-
-
- /*
- * Class to store "assertion evaluation" error details.
+ * Class to store assertion evaluation error details.
*/
final class AssertionError {
@@ -875,7 +894,8 @@ public class XMLAssertPsychopathImpl ext
private final XSAssertImpl assertImpl;
private final String value;
// does this error concerns "simpleType -> list"
- private final boolean isList;
+ private final boolean isSimpleTypeList;
+ private boolean isFoldedSTListAssertionEvaluation = false;
// class constructor
public AssertionError(String errorCode, QName element, XSAssertImpl
assertImpl, String value, boolean isList) {
@@ -883,9 +903,13 @@ public class XMLAssertPsychopathImpl ext
this.element = element;
this.assertImpl = assertImpl;
this.value = value;
- this.isList = isList;
+ this.isSimpleTypeList = isList;
}
+ public void setIsFoldedSTListEvaluationMode(boolean
isFoldedSTListAssertionEvaluation) {
+ this.isFoldedSTListAssertionEvaluation =
isFoldedSTListAssertionEvaluation;
+ }
+
public String getErrorCode() {
return errorCode;
}
@@ -902,8 +926,12 @@ public class XMLAssertPsychopathImpl ext
return value;
}
- public boolean isList() {
- return isList;
+ public boolean isSimpleTypeList() {
+ return isSimpleTypeList;
+ }
+
+ public boolean getIsFoldedListEvaluationMode() {
+ return isFoldedSTListAssertionEvaluation;
}
} // class AssertionError
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
Thu Feb 10 09:15:08 2011
@@ -209,6 +209,10 @@ public class XMLSchemaValidator
/** Feature identifier: whether to ignore type alternatives */
protected static final String TYPE_ALTERNATIVES_CHECKING =
Constants.XERCES_FEATURE_PREFIX +
Constants.TYPE_ALTERNATIVES_CHEKING_FEATURE;
+
+ /** Feature identifier: whether to evaluate assertions on each simpleType
list item */
+ protected static final String SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION =
+ Constants.XERCES_FEATURE_PREFIX +
Constants.SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE;
// property identifiers
@@ -1312,6 +1316,8 @@ public class XMLSchemaValidator
private boolean fIDCChecking;
private boolean fTypeAlternativesChecking;
+
+ private boolean fSTFoldedSTListAssertionEvaluation;
/** temporary validated info */
private ValidatedInfo fValidatedInfo = new ValidatedInfo();
@@ -1501,9 +1507,7 @@ public class XMLSchemaValidator
fAugPSVI = true;
}
try {
- fSchemaType =
- (String) componentManager.getProperty(
- Constants.JAXP_PROPERTY_PREFIX +
Constants.SCHEMA_LANGUAGE);
+ fSchemaType = (String)
componentManager.getProperty(Constants.JAXP_PROPERTY_PREFIX +
Constants.SCHEMA_LANGUAGE);
} catch (XMLConfigurationException e) {
fSchemaType = null;
}
@@ -1604,6 +1608,13 @@ public class XMLSchemaValidator
fTypeAlternativesChecking = true;
}
+ try {
+ fSTFoldedSTListAssertionEvaluation =
componentManager.getFeature(SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION);
+ }
+ catch (XMLConfigurationException e) {
+ fSTFoldedSTListAssertionEvaluation = false;
+ }
+
// get schema location properties
try {
fExternalSchemas = (String)
componentManager.getProperty(SCHEMA_LOCATION);
@@ -2161,8 +2172,7 @@ public class XMLSchemaValidator
//process type alternatives
if (fTypeAlternativesChecking && fCurrentElemDecl != null) {
- XSTypeDefinition currentType =
fTypeAlternativeValidator.getCurrentType(fCurrentElemDecl,
-
element, attributes);
+ XSTypeDefinition currentType =
fTypeAlternativeValidator.getCurrentType(fCurrentElemDecl, element,
attributes);
if (currentType != null) {
fCurrentType = currentType;
}
@@ -2405,7 +2415,7 @@ public class XMLSchemaValidator
// delegate to assertions validator subcomponent
if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
- fAssertionValidator.handleStartElement(element, attributes);
+ fAssertionValidator.handleStartElement(element, attributes,
fSTFoldedSTListAssertionEvaluation);
}
return augs;
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
Thu Feb 10 09:15:08 2011
@@ -82,7 +82,7 @@ public class XSDAssertionValidator {
/*
* Assertions processing interface during the XNI event,
'handleStartElement' in XMLSchemaValidator.
*/
- public void handleStartElement(QName element, XMLAttributes attributes) {
+ public void handleStartElement(QName element, XMLAttributes attributes,
boolean stFoldedListAssertionEvaluation) {
// get list of assertions for processing
List assertionList = getAssertsForEvaluation(element, attributes);
@@ -101,6 +101,7 @@ public class XSDAssertionValidator {
Map assertProcessorParams = new HashMap();
assertProcessorParams.put("XPATH2_NS_CONTEXT",
xpathNamespaceContext);
+ assertProcessorParams.put("FOLDED_STLIST_ASSERT_FEATURE",
Boolean.valueOf(stFoldedListAssertionEvaluation));
// initialize the assertions processor
initializeAssertProcessor(assertProcessorParams);
}
@@ -109,7 +110,7 @@ public class XSDAssertionValidator {
if (fAssertionProcessor != null) {
// construct the augmentations object, for assertions
AugmentationsImpl assertAugs = new AugmentationsImpl();
- assertAugs.putItem("ASSERT", assertionList);
+ assertAugs.putItem("ASSERT", assertionList);
fAssertionProcessor.startElement(element, attributes, assertAugs);
}
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java?rev=1069296&r1=1069295&r2=1069296&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/XMLSchemaValidatorComponentManager.java
Thu Feb 10 09:15:08 2011
@@ -87,6 +87,10 @@ final class XMLSchemaValidatorComponentM
private static final String TYPE_ALTERNATIVES_CHECKING =
Constants.XERCES_FEATURE_PREFIX +
Constants.TYPE_ALTERNATIVES_CHEKING_FEATURE;
+ /** Feature identifier: whether to evaluate assertions on each simpleType
list item */
+ private static final String SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION =
+ Constants.XERCES_FEATURE_PREFIX +
Constants.SIMPLETYPE_FOLDEDLIST_ASSERTION_FEATURE;
+
/** Feature identifier: disallow DOCTYPE declaration */
private static final String DISALLOW_DOCTYPE_DECL_FEATURE =
Constants.XERCES_FEATURE_PREFIX +
Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
@@ -255,13 +259,15 @@ final class XMLSchemaValidatorComponentM
DISALLOW_DOCTYPE_DECL_FEATURE,
NORMALIZE_DATA,
SCHEMA_ELEMENT_DEFAULT,
- SCHEMA_AUGMENT_PSVI
+ SCHEMA_AUGMENT_PSVI,
+ SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(DISALLOW_DOCTYPE_DECL_FEATURE, Boolean.FALSE);
fFeatures.put(NORMALIZE_DATA, Boolean.FALSE);
fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.FALSE);
fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
+ fFeatures.put(SIMPLETYPE_FOLDEDLIST_ASSERTION_EVALUATION,
Boolean.FALSE);
addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer);
addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer);
@@ -286,6 +292,7 @@ final class XMLSchemaValidatorComponentM
fFeatures.put(ID_IDREF_CHECKING, Boolean.TRUE);
fFeatures.put(IDENTITY_CONSTRAINT_CHECKING, Boolean.TRUE);
fFeatures.put(UNPARSED_ENTITY_CHECKING, Boolean.TRUE);
+ fFeatures.put(TYPE_ALTERNATIVES_CHECKING, Boolean.TRUE);
fFeatures.put(TYPE_ALTERNATIVES_CHECKING, Boolean.TRUE);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]