You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mu...@apache.org on 2011/01/28 17:39:17 UTC
svn commit: r1064769 - in
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs:
XMLAssertPsychopathImpl.java XMLSchemaValidator.java
XSDAssertionValidator.java assertion/XSAssertImpl.java
Author: mukulg
Date: Fri Jan 28 16:39:17 2011
New Revision: 1064769
URL: http://svn.apache.org/viewvc?rev=1064769&view=rev
Log:
committing few improvements to schema 1.1 assertions processing (while working on following W3C XML Schema 1.1 test case - assert-simple006.n1.xml "xs:assert on a union of two built-in types").
also doing miscellaneous refactoring, and cleaning some of the javadocs.
Modified:
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/impl/xs/assertion/XSAssertImpl.java
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=1064769&r1=1064768&r2=1064769&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 Fri Jan 28 16:39:17 2011
@@ -69,8 +69,8 @@ import org.w3c.dom.NodeList;
* This class interfaces with the "Eclipse/PsychoPath XPath 2.0" engine for XPath
* expression evaluations for XML Schema assertions.
*
- * The class here constructs Xerces PSVI enabled DOM trees -- "on which PsychoPath XPath
- * engine operates" (for typed XDM instance support) from XNI event calls. XML Schema
+ * We construct here Xerces PSVI enabled DOM trees (on which PsychoPath XPath 2.0
+ * engine operates) from XNI event calls, for typed XDM instance support. XML Schema
* assertions are evaluated on these XPath tree instances in a bottom up fashion.
*
* @xerces.internal
@@ -106,9 +106,6 @@ public class XMLAssertPsychopathImpl ext
// parameters to pass to PsychoPath engine (like, the XML namespace bindings).
private Map fAssertParams = null;
- // an instance variable to track the name of an attribute currently been processed for assertions.
- private String fAttrName = null;
-
// a placeholder definition used for assertions error messages.
private final String ERROR_PLACEHOLDER_REGEX = "\\{\\$value\\}";
@@ -200,21 +197,7 @@ public class XMLAssertPsychopathImpl ext
if (elemDecl != null && elemDecl.fDefault != null && fCurrentAssertDomNode.getChildNodes().getLength() == 0) {
String normalizedDefaultValue = elemDecl.fDefault.normalizedValue;
fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(normalizedDefaultValue));
- }
-
- // itemType for xs:list
- XSSimpleTypeDefinition itemType = null;
-
- // memberTypes for xs:union
- XSObjectList memberTypes = null;
-
- if (elemPSVI.getTypeDefinition().getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
- XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) elemPSVI.getTypeDefinition();
- itemType = simpleTypeDefn.getItemType();
- if (itemType == null) {
- memberTypes = simpleTypeDefn.getMemberTypes();
- }
- }
+ }
if (!fAssertRootStack.empty() && (fCurrentAssertDomNode == fAssertRootStack.peek())) {
// get XSModel instance
@@ -225,11 +208,11 @@ public class XMLAssertPsychopathImpl ext
// get assertions and go one level up on the stack
List assertions = (List) fAssertListStack.pop();
Boolean isAssertProcessingNeeded = (Boolean) augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION");
- if (isAssertProcessingNeeded.booleanValue()) {
+ if (isAssertProcessingNeeded.booleanValue()) {
// if in a pre-processing step in XMLSchemaValidator, a member type of union in XML Schema namespace successfully
- // validated an atomic value, don't process assertions on such union types. For all other use-cases (non union
+ // 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, itemType, memberTypes, assertions, elemPSVI);
+ processAllAssertionsOnElement(element, assertions, elemPSVI);
}
}
@@ -245,9 +228,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.
*/
- private void processAllAssertionsOnElement(QName element, XSSimpleTypeDefinition itemType, XSObjectList memberTypes,
- List assertions, ElementPSVI elemPSVI)
- throws Exception {
+ private void processAllAssertionsOnElement(QName element, List assertions, ElementPSVI elemPSVI) throws Exception {
// initialize the XPath engine
initXPathProcessor();
@@ -260,9 +241,9 @@ public class XMLAssertPsychopathImpl ext
// assertions from a "complex type" definition
evaluateAssertionsFromAComplexType(element, assertions, value);
}
- else if (assertions instanceof Vector) {
+ else if (assertions instanceof Vector) {
// assertions from a "simple type" definition
- evaluateAssertionsFromASimpleType(element, itemType, memberTypes, assertions, value);
+ evaluateAssertionsFromASimpleType(element, assertions, value, elemPSVI);
}
} // processAllAssertionsOnElement
@@ -331,7 +312,7 @@ public class XMLAssertPsychopathImpl ext
// complex type with simple content
setTypedValueFor$value(value, null, null);
} else {
- // complex type with complex content. assign an empty XPath2 sequence to xpath context variable $value.
+ // complex type with complex content. set xpath context variable $value to an empty sequence.
fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
"value"), getXPath2ResultSequence(new ArrayList()));
}
@@ -349,8 +330,9 @@ public class XMLAssertPsychopathImpl ext
// check if this is an assertion, from an attribute
if (assertImpl.getAttrName() != null) {
value = assertImpl.getAttrValue();
- XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) assertImpl.getTypeDefinition();
+ XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) assertImpl.getTypeDefinition();
attrMemberTypes = attrType.getMemberTypes();
+ final boolean isTypeDerivedFromUnion = ((XSSimpleType) attrType.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
if (assertImpl.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST) {
// this assertion belongs to a type, that is an item type of a "simpleType -> list".
// tokenize the list value by the longest sequence of white-spaces.
@@ -359,46 +341,49 @@ public class XMLAssertPsychopathImpl ext
// evaluate assertion on all of list items
while (values.hasMoreTokens()) {
String itemValue = values.nextToken();
- setValueOf$valueForAListItem(attrType, itemValue);
- AssertionError assertError = evaluateAssertion(element, assertImpl, itemValue,
- xpathContextExists, true);
+ setValueOf$valueForAListItem(itemValue, attrType);
+ AssertionError assertError = evaluateAssertion(element, assertImpl, itemValue, xpathContextExists, true);
if (assertError != null) {
reportAssertionsError(assertError);
}
}
}
else if (assertImpl.getVariety() == XSSimpleTypeDefinition.VARIETY_ATOMIC) {
- // evaluating assertions for "simpleType -> restriction"
+ // evaluating assertions for "simpleType -> restriction" (not derived by union)
setTypedValueFor$value(value, null, attrType);
- AssertionError assertError = evaluateAssertion(element, assertImpl, value,
- xpathContextExists, false);
+ AssertionError assertError = evaluateAssertion(element, assertImpl, value, xpathContextExists, false);
+ if (assertError != null) {
+ reportAssertionsError(assertError);
+ }
+ }
+ else if (attrMemberTypes != null && attrMemberTypes.getLength() > 0 && !isTypeDerivedFromUnion) {
+ // evaluate assertions for "simpleType -> union"
+ boolean isValidationFailedForUnion = isValidationFailedForUnion(attrMemberTypes, element, value, false);
+ // only 1 error message is reported for assertion failures on "simpleType -> union", since it is hard
+ // (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 } );
+ }
+ }
+ 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, attrMemberTypes);
+ AssertionError assertError = evaluateAssertion(element, assertImpl, value, false, false);
if (assertError != null) {
reportAssertionsError(assertError);
}
- }
+ }
}
else {
- AssertionError assertError = evaluateAssertion(element, assertImpl, value,
- xpathContextExists, false);
+ AssertionError assertError = evaluateAssertion(element, assertImpl, value, xpathContextExists, false);
if (assertError != null) {
reportAssertionsError(assertError);
}
}
}
-
- // evaluate assertions on "simpleType -> union" on an attribute
- if (attrMemberTypes != null && attrMemberTypes.getLength() > 0) {
- boolean isValidationFailedForUnion = isValidationFailedForUnion(attrMemberTypes, element, value, true);
-
- if (isValidationFailedForUnion) {
- // none of the member types of union (the assertions in them) can successfully validate an atomic value.
- // this results in an overall validation failure. report an error message.
- fValidator.reportSchemaError("cvc-assertion.attr.union.3.13.4.1", new Object[] {
- element.rawname, fAttrName, value } );
- }
-
- fAttrName = null;
- }
} // evaluateAssertionsFromAComplexType
@@ -406,24 +391,36 @@ public class XMLAssertPsychopathImpl ext
/*
* Evaluate assertions on a "simple type".
*/
- private void evaluateAssertionsFromASimpleType(QName element, XSSimpleTypeDefinition itemType,
- XSObjectList memberTypes, List assertions, String value)
- throws Exception {
+ 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)
+ XSSimpleTypeDefinition itemType = null;
+ XSObjectList memberTypes = null;
+
+ if (elemPSVI.getTypeDefinition().getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+ XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) elemPSVI.getTypeDefinition();
+ itemType = simpleTypeDefn.getItemType();
+ if (itemType == null) {
+ memberTypes = simpleTypeDefn.getMemberTypes();
+ }
+ }
+
+ final boolean isTypeDerivedFromUnion = ((XSSimpleType) elemPSVI.getTypeDefinition().getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
- // assertions from a simple type definition
+ // process assertions from a simple type definition
Vector assertList = (Vector) assertions;
final int assertListLength = assertList.size();
- for (int i = 0; i < assertListLength; i++) {
- XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
+
+ for (int assertIdx = 0; assertIdx < assertListLength; assertIdx++) {
+ XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
if (itemType != null) {
- // evaluating assertions for "simpleType -> list". tokenize the list value by the longest sequence of
- // white-spaces.
+ // evaluating assertions for "simpleType -> list". tokenize the list value by the longest sequence of white-spaces.
StringTokenizer values = new StringTokenizer(value, " \n\t\r");
// evaluate assertion on all of list items
while (values.hasMoreTokens()) {
String itemValue = values.nextToken();
- setValueOf$valueForAListItem(itemType, itemValue);
+ setValueOf$valueForAListItem(itemValue, itemType);
AssertionError assertError = evaluateAssertion(element, assertImpl, itemValue, false, true);
if (assertError != null) {
reportAssertionsError(assertError);
@@ -437,17 +434,26 @@ public class XMLAssertPsychopathImpl ext
if (assertError != null) {
reportAssertionsError(assertError);
}
- }
- }
-
- if (memberTypes != null && memberTypes.getLength() > 0) {
- // evaluate assertions for "simpleType -> union"
- boolean isValidationFailedForUnion = isValidationFailedForUnion(memberTypes, element, value, false);
- // only 1 error message is reported for assertion failures on "simpleType -> union",
- // since it is hard (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 } );
+ }
+ else if (memberTypes != null && memberTypes.getLength() > 0 && !isTypeDerivedFromUnion) {
+ // evaluate assertions for "simpleType -> union"
+ boolean isValidationFailedForUnion = isValidationFailedForUnion(memberTypes, element, value, false);
+ // only 1 error message is reported for assertion failures on "simpleType -> union", since it is hard
+ // (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 } );
+ }
+ }
+ 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 in every case?).
+ // REVISIT...
+ setValueOf$ValueForSTVarietyUnion(value, memberTypes);
+ AssertionError assertError = evaluateAssertion(element, assertImpl, value, false, false);
+ if (assertError != null) {
+ reportAssertionsError(assertError);
+ }
}
}
@@ -455,11 +461,30 @@ 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(XSSimpleTypeDefinition simpType, String value)
- throws Exception {
+ private void setValueOf$valueForAListItem(String value, XSSimpleTypeDefinition simpType) throws Exception {
XSObjectList memberTypes = simpType.getMemberTypes();
if (memberTypes.getLength() > 0) {
@@ -481,7 +506,7 @@ public class XMLAssertPsychopathImpl ext
*/
private boolean isValidationFailedForUnion(XSObjectList memberTypes, QName element, String value, boolean isAttribute) {
- boolean validationFailedForUnion = true;
+ boolean isValidationFailedForUnion = true;
final int memberTypesLength = memberTypes.getLength();
for (int memberTypeIdx = 0; memberTypeIdx < memberTypesLength; memberTypeIdx++) {
@@ -504,9 +529,6 @@ public class XMLAssertPsychopathImpl ext
if (assertError == null) {
assertsSucceeded++;
}
- else if (isAttribute && fAttrName == null) {
- fAttrName = assertImpl.getAttrName();
- }
}
catch(Exception ex) {
// An exception may occur if for example, a typed value cannot be constructed by PsychoPath
@@ -525,7 +547,7 @@ public class XMLAssertPsychopathImpl ext
}
}
- return validationFailedForUnion;
+ return isValidationFailedForUnion;
} // isValidationFailedForUnion
@@ -535,19 +557,19 @@ public class XMLAssertPsychopathImpl ext
*/
private boolean simpleTypeHasAsserts(XSSimpleTypeDefinition simpleType) {
- boolean hasAssertions = false;
+ boolean simpleTypehasAsserts = false;
XSObjectList simpleTypeFacets = simpleType.getMultiValueFacets();
final int simpleTypeFacetsLength = simpleTypeFacets.getLength();
for (int facetIdx = 0; facetIdx < simpleTypeFacetsLength; facetIdx++) {
XSMultiValueFacet facet = (XSMultiValueFacet) simpleTypeFacets.item(facetIdx);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT && facet.getAsserts().size() > 0) {
- hasAssertions = true;
+ simpleTypehasAsserts = true;
break;
}
}
- return hasAssertions;
+ return simpleTypehasAsserts;
} // simpleTypeHasAsserts
@@ -560,8 +582,7 @@ public class XMLAssertPsychopathImpl ext
public void characters(XMLString text) {
// add a child text node to the assertions, DOM tree
if (fCurrentAssertDomNode != null) {
- fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(new String(text.ch,
- text.offset, text.length)));
+ fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(new String(text.ch, text.offset, text.length)));
}
}
@@ -618,8 +639,7 @@ 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) throws Exception {
// dummy short code initializer
short xsdTypecode = -100;
@@ -638,10 +658,8 @@ public class XMLAssertPsychopathImpl ext
// is "simple type" value of an element
PSVIElementNSImpl currentAssertPSVINode = (PSVIElementNSImpl) fCurrentAssertDomNode;
XSTypeDefinition typeDef = currentAssertPSVINode.getTypeDefinition();
- if (typeDef instanceof XSComplexTypeDefinition && ((XSComplexTypeDefinition) typeDef).getSimpleType()
- != null) {
- setValueOf$ValueForCTWithSimpleContent(value,
- (XSComplexTypeDefinition) typeDef);
+ if (typeDef instanceof XSComplexTypeDefinition && ((XSComplexTypeDefinition) typeDef).getSimpleType() != null) {
+ setValueOf$ValueForCTWithSimpleContent(value, (XSComplexTypeDefinition) typeDef);
}
else if (typeDef instanceof XSComplexTypeDefinition &&
((XSComplexTypeDefinition) typeDef).getSimpleType() == null) {
@@ -708,11 +726,9 @@ public class XMLAssertPsychopathImpl ext
}
else if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
// simple content type has variety xs:union
- XSSimpleTypeDefinition simpleContentTypeForUnion = getActualListItemTypeForVarietyUnion
- (complexTypeSimplContentType.getMemberTypes(), value);
+ XSSimpleTypeDefinition simpleContentTypeForUnion = getActualListItemTypeForVarietyUnion(complexTypeSimplContentType.getMemberTypes(), value);
fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
- SchemaTypeValueFactory.newSchemaTypeValue(simpleContentTypeForUnion.getBuiltInKind(),
- value));
+ SchemaTypeValueFactory.newSchemaTypeValue(simpleContentTypeForUnion.getBuiltInKind(), value));
}
else {
// simple content type has variety atomic
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=1064769&r1=1064768&r2=1064769&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 Fri Jan 28 16:39:17 2011
@@ -1349,7 +1349,7 @@ public class XMLSchemaValidator
private XSDAssertionValidator fAssertionValidator = null;
// variable to track validity of simple content for union types. if a member type of union in XML Schema namespace, can
- // successfully validate (in a preprocess step in this class) an atomic value, don't process assertions for such union types.
+ // successfully validate (in a preprocess step in this class) an atomic value, we don't process assertions for such union types.
private boolean fisAssertProcessingNeededForUnion = true;
// 'type alternative' validator subcomponent
@@ -2540,10 +2540,8 @@ public class XMLSchemaValidator
// delegate to assertions validator subcomponent
if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
- fAssertionValidator.handleEndElement(element, fCurrentElemDecl,
- fCurrentType, fNotation,
- fGrammarBucket,
- fisAssertProcessingNeededForUnion);
+ fAssertionValidator.handleEndElement(element, fCurrentElemDecl, fCurrentType, fNotation,
+ fGrammarBucket, fisAssertProcessingNeededForUnion);
fisAssertProcessingNeededForUnion = true;
}
@@ -3225,12 +3223,10 @@ public class XMLSchemaValidator
try {
actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
- // additional check for assertions processing, for simple type having
- // variety 'union'.
- if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 &&
- attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
- if (XSTypeHelper.isAtomicValueValidForAnUnion(attDV.getMemberTypes(),
- attrValue, null)) {
+ // additional check for assertions processing, for simple type having variety 'union'.
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION &&
+ ((XSSimpleType) attDV.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (XSTypeHelper.isAtomicValueValidForAnUnion(attDV.getMemberTypes(), attrValue, null)) {
fisAssertProcessingNeededForUnion = false;
}
}
@@ -3381,12 +3377,10 @@ public class XMLSchemaValidator
fValidationState.setFacetChecking(false);
attDV.validate(fValidationState, defaultValue);
- // additional check for assertions processing, for simple type having
- // variety 'union'.
- if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 &&
- attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
- if (XSTypeHelper.isAtomicValueValidForAnUnion(attDV.getMemberTypes(),
- null, defaultValue)) {
+ // additional check for assertions processing, for simple type having variety 'union'.
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION &&
+ ((XSSimpleType) attDV.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (XSTypeHelper.isAtomicValueValidForAnUnion(attDV.getMemberTypes(), null, defaultValue)) {
fisAssertProcessingNeededForUnion = false;
}
}
@@ -3595,13 +3589,10 @@ public class XMLSchemaValidator
}
retValue = dv.validate(textContent, fValidationState, fValidatedInfo);
- // additional check for assertions processing, for simple type having
- // variety 'union'.
- if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 &&
- dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
- if (XSTypeHelper.isAtomicValueValidForAnUnion(dv.getMemberTypes(),
- String.valueOf(textContent),
- null)) {
+ // additional check for assertions processing, for simple type having variety 'union'.
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION &&
+ ((XSSimpleType) dv.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (XSTypeHelper.isAtomicValueValidForAnUnion(dv.getMemberTypes(), String.valueOf(textContent), null)) {
fisAssertProcessingNeededForUnion = false;
}
}
@@ -3646,13 +3637,10 @@ public class XMLSchemaValidator
}
actualValue = dv.validate(textContent, fValidationState, fValidatedInfo);
- // additional check for assertions processing, for simple type having
- // variety 'union'.
- if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 &&
- dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
- if (XSTypeHelper.isAtomicValueValidForAnUnion(dv.getMemberTypes(),
- String.valueOf(textContent),
- null)) {
+ // additional check for assertions processing, for simple type having variety 'union'.
+ if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION &&
+ ((XSSimpleType) dv.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (XSTypeHelper.isAtomicValueValidForAnUnion(dv.getMemberTypes(), String.valueOf(textContent), null)) {
fisAssertProcessingNeededForUnion = false;
}
}
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=1064769&r1=1064768&r2=1064769&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 Fri Jan 28 16:39:17 2011
@@ -92,8 +92,7 @@ public class XSDAssertionValidator {
// construct parameter values for the assertion processor
NamespaceSupport xpathNamespaceContext = null;
if (assertionList instanceof XSObjectList) {
- xpathNamespaceContext = ((XSAssertImpl)((XSObjectList) assertionList).item(0)).
- getXPath2NamespaceContext();
+ xpathNamespaceContext = ((XSAssertImpl)((XSObjectList) assertionList).item(0)).getXPath2NamespaceContext();
}
else {
Vector assertVector = (Vector) assertionList;
@@ -120,8 +119,7 @@ public class XSDAssertionValidator {
/*
* Assertions processing interface during the XNI event, 'handleEndElement' in XMLSchemaValidator.
*/
- public void handleEndElement(QName element, XSElementDecl elemDecl,
- XSTypeDefinition typeDef, XSNotationDecl notation,
+ public void handleEndElement(QName element, XSElementDecl elemDecl, XSTypeDefinition typeDef, XSNotationDecl notation,
XSGrammarBucket grammarBucket, boolean isAssertProcessingNeededForUnion) {
if (fAssertionProcessor != null) {
@@ -264,12 +262,17 @@ public class XSDAssertionValidator {
XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(facetIdx);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
Vector attrAsserts = facet.getAsserts();
- for (int j = 0; j < attrAsserts.size(); j++) {
- XSAssertImpl attrAssert = (XSAssertImpl) attrAsserts.elementAt(j);
+ for (int assertIdx = 0; assertIdx < attrAsserts.size(); assertIdx++) {
+ XSAssertImpl currAssertObject = (XSAssertImpl) attrAsserts.elementAt(assertIdx);
+ XSAssertImpl attrAssert = new XSAssertImpl(currAssertObject.getTypeDefinition(), currAssertObject.getAnnotations(),
+ currAssertObject.getSchemaHandler());
+ // copy couple of assertion attributes, to help completely construct the assert object
+ copyAssertAttributes(currAssertObject, attrAssert);
+ // set rest of assertion attributes
+ attrAssert.setVariety(attrTypeVariety);
attrAssert.setAttrName(attributes.getLocalName(attrIndx));
- attrAssert.setAttrValue(attributes.getValue(attrIndx));
- attrAssert.setVariety(attrTypeVariety);
- attrAssertList.addXSObject(attrAssert);
+ attrAssert.setAttrValue(attributes.getValue(attrIndx));
+ attrAssertList.addXSObject(attrAssert);
}
// break from the for loop
break;
@@ -327,27 +330,31 @@ public class XSDAssertionValidator {
/*
* Get the 1st assertion from the member types of simpleType having variety union. Needed to get an schema
- * "namespace context", which is available for example, in the 1st assertion in the assertions list.
+ * "namespace context" which is available for example, in the 1st assertion in the assertions list.
*/
private XSAssertImpl getFirstAssertFromUnionMemberTypes(XSObjectList memberTypes) {
XSAssertImpl assertImpl = null;
for (int memberTypeIdx = 0; memberTypeIdx < memberTypes.getLength(); memberTypeIdx++) {
+ boolean isAssertFound = false;
XSSimpleTypeDefinition memType = (XSSimpleTypeDefinition) memberTypes.item(memberTypeIdx);
if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(memType.getNamespace())) {
XSObjectList memberTypeFacets = memType.getMultiValueFacets();
- for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < memberTypeFacets.getLength();
- memberTypeFacetIdx++) {
+ for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < memberTypeFacets.getLength(); memberTypeFacetIdx++) {
XSMultiValueFacet facet = (XSMultiValueFacet) memberTypeFacets.item(memberTypeFacetIdx);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
Vector assertFacets = facet.getAsserts();
assertImpl = (XSAssertImpl) assertFacets.get(0);
// return the 1st assertion that's found
- return assertImpl;
+ isAssertFound = true;
+ break;
}
}
}
+ if (isAssertFound) {
+ break;
+ }
}
return assertImpl;
@@ -394,4 +401,19 @@ public class XSDAssertionValidator {
} // initializeAssertProcessor
+
+ /*
+ * Copy assertion attributes (from object assertA to assertB).
+ */
+ private void copyAssertAttributes(XSAssertImpl assertA, XSAssertImpl assertB) {
+
+ assertB.setAssertKind(assertA.getAssertKind());
+ assertB.setTest(assertA.getTest());
+ assertB.setCompiledExpr(assertA.getCompiledXPath());
+ assertB.setXPathDefaultNamespace(assertA.getXPathDefaultNamespace());
+ assertB.setXPath2NamespaceContext(assertA.getXPath2NamespaceContext());
+ assertB.setMessage(assertA.getMessage());
+
+ } // copyAssertAttributes
+
} // class XSDAssertionValidator
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java?rev=1064769&r1=1064768&r2=1064769&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java Fri Jan 28 16:39:17 2011
@@ -37,80 +37,74 @@ import org.eclipse.wst.xml.xpath2.proces
*/
public class XSAssertImpl extends AbstractPsychoPathImpl implements XSAssert {
- protected short assertKind = XSConstants.ASSERTION;
+ // The kind of assertion this is
+ private short fAssertKind = XSConstants.ASSERTION;
- /** The type definition associated with the assertion component */
- protected XSTypeDefinition fTypeDefinition;
+ // The type definition associated with the assertion component
+ private XSTypeDefinition fTypeDefinition;
- /** Xerces object representing the assert 'test' attribute */
- protected Test fTestExpr = null;
+ // Xerces object representing the assert 'test' attribute
+ private Test fTestExpr = null;
- /** Compiled XPath 2.0 expression */
- protected XPath fCompiledXPath = null;
+ // Compiled XPath 2.0 expression
+ private XPath fCompiledXPathExpr = null;
- /** Optional annotations */
- protected XSObjectList fAnnotations = null;
+ // Optional annotations
+ private XSObjectList fAnnotations = null;
- /** Default XPath namespace */
- protected String fXPathDefaultNamespace = null;
+ // Default XPath namespace
+ private String fXPathDefaultNamespace = null;
- /** XPath 2.0 namespace context. Derived from XSDocumentInfo in Xerces
- schema "component traversers".
- */
- protected NamespaceSupport fXPath2NamespaceContext = null;
-
- // a non null value of this object indicates, that this assertion belongs
- // to an attribute's schema type, and value of this object would be the
- // attribute's name.
- protected String attrName = null;
-
- // a non null value of this object indicates, that this assertion belongs
- // to an attribute's schema type, and value of this object would be the
- // attribute's value.
- protected String attrValue = null;
-
- // XSDHandler object, passed on from the Xerces schema "component
- // traversers".
- protected XSDHandler fSchemaHandler = null;
-
- // user-defined message to provide to an user context, during assertion
- // failures.
- protected String message = null;
-
- // representing the schema type's variety, if an assertion belongs to a
- // schema simpleType.
- protected short fVariety = 0;
-
- /** Constructor */
- public XSAssertImpl(XSTypeDefinition type,
- XSObjectList annotations, XSDHandler schemaHandler) {
- // An assert component must correspond to a schema type
+ // XPath 2.0 namespace context. Derived from XSDocumentInfo in Xerces schema "component traversers".
+ private NamespaceSupport fXPath2NamespaceContext = null;
+
+ // a non-null value of this object indicates that this assertion belongs to an attribute's schema type, and
+ // value of this object would be the attribute's name.
+ private String fAttrName = null;
+
+ // a non-null value of this object indicates that this assertion belongs to an attribute's schema type, and
+ // value of this object would be the attribute's value.
+ private String fAttrValue = null;
+
+ // XSDHandler object passed on from the Xerces XSModel traversers.
+ private XSDHandler fSchemaHandler = null;
+
+ // an user-defined message to provide to the user context, during assertion failures.
+ private String fMessage = null;
+
+ // represents the schema type's variety if an assertion belongs to a schema simpleType.
+ private short fVariety = 0;
+
+ /*
+ * Class constructor.
+ */
+ public XSAssertImpl(XSTypeDefinition type, XSObjectList annotations, XSDHandler schemaHandler) {
+ // an assert component corresponds to a schema type
fTypeDefinition = type;
fSchemaHandler = schemaHandler;
fAnnotations = annotations;
}
-
- /** Sets the test attribute value */
+
public void setTest(Test expr) {
fTestExpr = expr;
- // compile the XPath string, into an object
- fCompiledXPath = compileXPathStr(expr.toString(),
- this,
- fSchemaHandler);
+ // compile the XPath string, and keep compiled representation into this object for later use (this helps us to
+ // optimize assertions evaluations).
+ setCompiledExpr(compileXPathStr(expr.toString(), this, fSchemaHandler));
+ }
+
+ public void setCompiledExpr(XPath compiledXPathExpr) {
+ fCompiledXPathExpr = compiledXPathExpr;
}
- /** Sets the assertion annotations */
public void setAnnotations(XSObjectList annotations) {
fAnnotations = annotations;
}
- /** Sets the xpath default namespace */
public void setXPathDefaultNamespace(String namespace) {
fXPathDefaultNamespace = namespace;
}
- /** Sets the XPath 2.0 namespace context */
public void setXPath2NamespaceContext(NamespaceSupport namespaceContext) {
fXPath2NamespaceContext = namespaceContext;
}
@@ -123,24 +117,29 @@ public class XSAssertImpl extends Abstra
* -> an assertion facet from a simpleType : XSConstants.ASSERTION_FACET
*/
public void setAssertKind(short assertKind) {
- this.assertKind = assertKind;
+ this.fAssertKind = assertKind;
}
- /**
- * Sets the attribute name
- */
public void setAttrName(String attrName) {
- this.attrName = attrName;
+ this.fAttrName = attrName;
}
- /**
- * Sets the attribute value
- */
public void setAttrValue(String attrValue) {
- this.attrValue = attrValue;
+ this.fAttrValue = attrValue;
+ }
+
+ public void setTypeDefinition(XSTypeDefinition typeDefn) {
+ fTypeDefinition = typeDefn;
+ }
+
+ public void setMessage(String message) {
+ this.fMessage = message;
+ }
+
+ public void setVariety(short variety) {
+ fVariety = variety;
}
-
public XSObjectList getAnnotations() {
return fAnnotations;
}
@@ -150,7 +149,7 @@ public class XSAssertImpl extends Abstra
}
public XPath getCompiledXPath() {
- return fCompiledXPath;
+ return fCompiledXPathExpr;
}
public Test getTest() {
@@ -161,10 +160,6 @@ public class XSAssertImpl extends Abstra
return fTypeDefinition;
}
- public void setTypeDefinition(XSTypeDefinition typeDefn) {
- fTypeDefinition = typeDefn;
- }
-
public String getXPathDefaultNamespace() {
return fXPathDefaultNamespace;
}
@@ -175,7 +170,7 @@ public class XSAssertImpl extends Abstra
public String getName() {
return null;
}
-
+
/**
* @see org.apache.xerces.xs.XSObject#getNamespace()
*/
@@ -190,80 +185,57 @@ public class XSAssertImpl extends Abstra
return null;
}
- /**
- * Get the type of the object
- */
public short getType() {
- return assertKind;
+ return fAssertKind;
}
- /**
- * Get the attribute name
- */
public String getAttrName() {
- return attrName;
+ return fAttrName;
}
- /**
- * Get the attribute value
- */
public String getAttrValue() {
- return attrValue;
+ return fAttrValue;
}
- /**
- * Get the XPath 2.0 namespace context
- */
public NamespaceSupport getXPath2NamespaceContext() {
return fXPath2NamespaceContext;
}
+ public String getMessage() {
+ return fMessage;
+ }
+
+ public short getVariety() {
+ return fVariety;
+ }
+
+ public XSDHandler getSchemaHandler() {
+ return fSchemaHandler;
+ }
+
+ public short getAssertKind() {
+ return fAssertKind;
+ }
+
/*
* Tests if two assertion components are equal. Xerces has a specific notion of assertions equality,
* as described by the algorithm in this method.
*/
public boolean equals(XSAssertImpl pAssertion) {
- boolean returnVal = false;
-
- String xpathStr = pAssertion.getTest().getXPath().toString();
- String currXpathStr = this.getTest().getXPath().toString();
-
- // if type and the xpath string are same, the asserts are equal
- if (XSTypeHelper.isSchemaTypesIdentical(pAssertion.getTypeDefinition(), fTypeDefinition) &&
- currXpathStr.equals(xpathStr)) {
- returnVal = true;
- }
- return returnVal;
- }
+ boolean returnVal = false;
- /*
- * Set error message, for assertions failures.
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /*
- * Get the error message string.
- */
- public String getMessage() {
- return message;
- }
+ String xpathStr = pAssertion.getTest().getXPath().toString();
+ String currXpathStr = this.getTest().getXPath().toString();
- /*
- * If the assertion belongs to a simpleType, set the variety
- * of the type.
- */
- public void setVariety(short variety) {
- fVariety = variety;
- }
-
+ // if type and the xpath string are same, the asserts are equal
+ if (XSTypeHelper.isSchemaTypesIdentical(pAssertion.getTypeDefinition(), fTypeDefinition) &&
+ currXpathStr.equals(xpathStr)) {
+ returnVal = true;
+ }
+
+ return returnVal;
+
+ } // equals
- /*
- * Get the value of simpleType's variety.
- */
- public short getVariety() {
- return fVariety;
- }
-}
+} // class XSAssertImpl
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org