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 2010/08/25 18:33:04 UTC
svn commit: r989206 - in
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl:
msg/XMLSchemaMessages.properties xs/XMLAssertPsychopathImpl.java
xs/XMLSchemaValidator.java xs/XSDAssertionValidator.java
Author: mukulg
Date: Wed Aug 25 16:33:04 2010
New Revision: 989206
URL: http://svn.apache.org/viewvc?rev=989206&view=rev
Log:
committing few fixes for assertions evaluation on XML schema lists and unions
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
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
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=989206&r1=989205&r2=989206&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Wed Aug 25 16:33:04 2010
@@ -106,6 +106,7 @@
cvc-type.3.1.2 = cvc-type.3.1.2: Element ''{0}'' is a simple type, so it must have no element information item [children].
cvc-type.3.1.3 = cvc-type.3.1.3: The value ''{1}'' of element ''{0}'' is not valid.
cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed. {3}
+ cvc-assertion.union.3.13.4.1 = cvc-assertion.union.3.13.4.1: Element ''{0}'' with value ''{1}'' is not locally valid. One or more of the assertion facets on an element''s type, with variety 'union', have failed.
cvc-assertion.4.3.15.3 = cvc-assertion.4.3.15.3: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed (undefined context). {3}
cvc-assertion.failure = cvc-assertion.failure: {0} {1}
cvc-xpath.3.13.4.2 = cvc-xpath.3.13.4.2: Assertion XPath expression, (''{0}'') on the Schema type ''{1}'' couldn''t compile successfully.
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=989206&r1=989205&r2=989206&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 Wed Aug 25 16:33:04 2010
@@ -17,7 +17,6 @@
package org.apache.xerces.impl.xs;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -193,9 +192,9 @@ public class XMLAssertPsychopathImpl ext
XSObjectList memberTypes = null;
if (elemPSVI.getTypeDefinition().getTypeCategory() ==
- XSTypeDefinition.SIMPLE_TYPE) {
+ XSTypeDefinition.SIMPLE_TYPE) {
XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition)
- elemPSVI.getTypeDefinition();
+ elemPSVI.getTypeDefinition();
itemType = simpleTypeDefn.getItemType();
if (itemType == null) {
memberTypes = simpleTypeDefn.getMemberTypes();
@@ -212,14 +211,19 @@ public class XMLAssertPsychopathImpl ext
assertRootStack.pop();
// get assertions, and go one level up
List assertions = (List) assertListStack.pop();
-
- processAllAssertionsOnElement(element, itemType,
+ Boolean atomicValueValidity = (Boolean) augs.getItem
+ ("ATOMIC_VALUE_VALIDITY");
+ if (atomicValueValidity.booleanValue()) {
+ // depending on simple content's validity status from
+ // XMLSchemaValidator, process XML schema assertions.
+ processAllAssertionsOnElement(element, itemType,
memberTypes, assertions);
+ }
}
if (currentAssertDomNode.getParentNode() instanceof Element) {
- currentAssertDomNode = (Element)currentAssertDomNode.
- getParentNode();
+ currentAssertDomNode = (Element)currentAssertDomNode.
+ getParentNode();
}
}
@@ -287,7 +291,7 @@ public class XMLAssertPsychopathImpl ext
AssertionError assertError = evaluateAssertion(element,
assertImpl, value,
xpathContextExists,
- false, false);
+ false);
if (assertError != null) {
reportError(assertError);
}
@@ -296,86 +300,158 @@ public class XMLAssertPsychopathImpl ext
else if (assertions instanceof Vector) {
// assertions from a simple type definition
Vector assertList = (Vector) assertions;
- List assertUnionErrorList = new ArrayList();
for (int i = 0; i < assertList.size(); i++) {
XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
if (itemType != null) {
// evaluating assertions for simpleType -> list
+
+ // tokenize the list value by the longest sequence of
+ // white-spaces.
String[] values = value.split("\\s+");
+
+ // evaluate assertion on all list items
for (int valIdx = 0; valIdx < values.length; valIdx++) {
setValueOf$value(values[valIdx], itemType, null);
AssertionError assertError = evaluateAssertion(element,
- assertImpl,
- values[valIdx],
- false,
- true, false);
+ assertImpl,
+ values[valIdx],
+ false,
+ true);
if (assertError != null) {
reportError(assertError);
}
}
}
- else if (memberTypes.getLength() > 0) {
- // evaluating assertions for simpleType -> union
- boolean isValueSuccess = true;
- try {
- setValueOf$value(value, (XSSimpleTypeDefinition)
- assertImpl.getTypeDefinition(),
- null);
- }
- catch (Exception ex) {
- // there was some problem in constructing value of the
- // XPath2 context variable $value.
- isValueSuccess = false;
- AssertionError assertError = new AssertionError
- ("cvc-assertion.3.13.4.1",
- element, assertImpl, value,
- false, true);
- assertUnionErrorList.add(assertError);
- }
-
- if (isValueSuccess) {
- AssertionError assertError = evaluateAssertion(element,
- assertImpl,
- value,
- false,
- false, true);
- if (assertError != null) {
- assertUnionErrorList.add(assertError);
- }
- }
- }
- else {
+ else if (memberTypes != null && memberTypes.getLength() == 0) {
// evaluating assertions for simpleType -> restriction
setValueOf$value(value, null, null);
AssertionError assertError = evaluateAssertion(element,
assertImpl,
value,
false,
- false, false);
+ false);
if (assertError != null) {
reportError(assertError);
}
- }
- }
-
- // if all of assertions in the schema component 'simpleType ->
- // union' have failed, then the overall schema validation should
- // fail, and all assertion failures should be reported.
- if (memberTypes != null && assertUnionErrorList.size() ==
- getAssertCountForSimpletypeUnion
- (memberTypes)) {
- for (Iterator iter = assertUnionErrorList.iterator();
- iter.hasNext(); ) {
- AssertionError assertError = (AssertionError) iter.next();
- reportError(assertError);
- }
+ }
}
+ // check for assertions on union member types.
+ // (there's a special handling for union types for assertions,
+ // since validation success on any one of the union member types,
+ // results in the overall validity of the value in the context)
+ if (memberTypes != null && memberTypes.getLength() > 0) {
+ boolean isValidationFailedForUnion =
+ isValidationFailedForUnion
+ (memberTypes,
+ element,
+ value);
+
+ if (isValidationFailedForUnion) {
+ // none of the member types of union (the assertions in
+ // them) can successfully validate an atomic value. this
+ // results in a overall validation failure. report an
+ // error message.
+ validator.reportSchemaError("cvc-assertion.union.3.13.4.1",
+ new Object[] { element.rawname, value } );
+ }
+ }
}
} // processAllAssertionsOnElement
+
+ /*
+ * Determine if validation should fail due to assertions evaluation for
+ * 'simpleType -> union' member types.
+ */
+ private boolean isValidationFailedForUnion(XSObjectList memberTypes,
+ QName element,
+ String value) {
+
+ boolean validationFailedForUnion = true;
+
+ for (int memberTypeIdx = 0; memberTypeIdx < memberTypes.getLength();
+ memberTypeIdx++) {
+ XSSimpleTypeDefinition memType = (XSSimpleTypeDefinition)
+ memberTypes.item(memberTypeIdx);
+ if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(memType.
+ getNamespace()) &&
+ simpleTypeHasAsserts(memType)) {
+ XSObjectList memberTypeFacets = memType.getMultiValueFacets();
+ for (int memberTypeFacetIdx = 0; memberTypeFacetIdx <
+ memberTypeFacets.getLength();
+ memberTypeFacetIdx++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet) memberTypeFacets.
+ item(memberTypeFacetIdx);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
+ Vector assertFacets = facet.getAsserts();
+ int assertsSucceeded = 0;
+ for (Iterator iter = assertFacets.iterator(); iter.hasNext(); ) {
+ XSAssertImpl assertImpl = (XSAssertImpl) iter.next();
+ try {
+ setValueOf$value(value, memType, null);
+ AssertionError assertError = evaluateAssertion(element,
+ assertImpl,
+ value,
+ false, false);
+ if (assertError == null) {
+ assertsSucceeded++;
+ }
+ }
+ catch(Exception ex) {
+ // An exception may occur if for example, a typed
+ // value cannot be constructed by PsychoPath engine
+ // for a given string value (say a value '5' was
+ // attempted to be formed as a typed value xs:date).
+ // This is a known scenario. Exceptions may occur
+ // due to other un-observed scenarios.
+
+ // it's useful to throw warning ... TO DO
+ }
+ }
+ if (assertsSucceeded == assertFacets.size()) {
+ // all assertions on a 'union member type' have
+ // evaluated to 'true', therefore validation with
+ // union has succeeded wrt assertions. return
+ // a boolean value 'false' from this method.
+ return false;
+ }
+ }
+ }
+ }
+ }
+
+ return validationFailedForUnion;
+
+ } // isValidationFailedForUnion
+
+
+ /*
+ * Check if a simple type has assertion facets.
+ */
+ private boolean simpleTypeHasAsserts(XSSimpleTypeDefinition simpleType) {
+
+ boolean hasAssertions = false;
+
+ XSObjectList simpleTypeFacets = simpleType.getMultiValueFacets();
+
+ for (int facetIdx = 0; facetIdx < simpleTypeFacets.getLength();
+ facetIdx++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet) simpleTypeFacets.
+ item(facetIdx);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT &&
+ facet.getAsserts().size() > 0) {
+ hasAssertions = true;
+ break;
+ }
+ }
+
+ return hasAssertions;
+
+ } // simpleTypeHasAsserts
+
/*
* (non-Javadoc)
@@ -400,8 +476,7 @@ public class XMLAssertPsychopathImpl ext
XSAssertImpl assertImpl,
String value,
boolean xPathContextExists,
- boolean isList,
- boolean isUnion) {
+ boolean isList) {
AssertionError assertionError = null;
@@ -425,32 +500,32 @@ public class XMLAssertPsychopathImpl ext
if (!result) {
// assertion evaluation is false
assertionError = new AssertionError("cvc-assertion.3.13.4.1",
- element, assertImpl, value,
- isList, isUnion);
+ element, assertImpl,
+ value, isList);
}
}
catch (DynamicError ex) {
if (ex.code().equals("XPDY0002")) {
// ref: http://www.w3.org/TR/xpath20/#eval_context
assertionError = new AssertionError("cvc-assertion.4.3.15.3",
- element, assertImpl, value,
- isList, isUnion);
+ element, assertImpl,
+ value, isList);
}
else {
assertionError = new AssertionError("cvc-assertion.3.13.4.1",
- element, assertImpl, value,
- isList, isUnion);
+ element, assertImpl,
+ value, isList);
}
}
catch (StaticError ex) {
assertionError = new AssertionError("cvc-assertion.3.13.4.1",
- element, assertImpl, value,
- isList, isUnion);
+ element, assertImpl,
+ value, isList);
}
catch(Exception ex) {
assertionError = new AssertionError("cvc-assertion.3.13.4.1",
- element, assertImpl, value,
- isList, isUnion);
+ element, assertImpl,
+ value, isList);
}
return assertionError;
@@ -525,35 +600,6 @@ public class XMLAssertPsychopathImpl ext
/*
- * Find count of number of assertions within a 'simpleType -> union' schema
- * component.
- */
- private int getAssertCountForSimpletypeUnion(XSObjectList memberTypes) {
-
- int assertCount = 0;
-
- for (int memTypIdx = 0; memTypIdx < memberTypes.getLength();
- memTypIdx++) {
- XSObjectList memberTypeFacets = ((XSSimpleTypeDefinition)
- memberTypes.item(memTypIdx)).
- getMultiValueFacets();
- for (int facetIdx = 0; facetIdx < memberTypeFacets.getLength();
- facetIdx++) {
- XSMultiValueFacet facet = (XSMultiValueFacet) memberTypeFacets.
- item(facetIdx);
- if (facet.getFacetKind() == XSSimpleTypeDefinition.
- FACET_ASSERT) {
- assertCount = assertCount + facet.getAsserts().size();
- }
- }
- }
-
- return assertCount;
-
- } // getAssertCountForSimpletypeUnion
-
-
- /*
* Method to report error messages.
*/
private void reportError(AssertionError assertError) {
@@ -562,7 +608,6 @@ public class XMLAssertPsychopathImpl ext
QName element = assertError.getElement();
XSAssertImpl assertImpl = assertError.getAssertion();
boolean isList = assertError.isList();
- boolean isUnion = assertError.isUnion();
XSTypeDefinition typeDef = assertImpl.getTypeDefinition();
String typeString = "";
@@ -581,17 +626,12 @@ public class XMLAssertPsychopathImpl ext
assertImpl.getAttrName()+ ")";
}
- String listUnionErrMessage = "";
+ String listAssertErrMessage = "";
if (isList) {
- listUnionErrMessage = "Assertion failed for an xs:list member value '" +
+ listAssertErrMessage = "Assertion failed for an xs:list member value '" +
assertError.getValue() +
"'.";
}
- else if (isUnion) {
- listUnionErrMessage = "Assertion failed for an xs:union with data value '" +
- assertError.getValue() +
- "'.";
- }
String message = assertImpl.getMessage();
if (message != null) {
@@ -605,12 +645,12 @@ public class XMLAssertPsychopathImpl ext
message = "Assertion failure. " + message;
}
validator.reportSchemaError("cvc-assertion.failure",
- new Object[] { message, listUnionErrMessage } );
+ new Object[] { message, listAssertErrMessage } );
}
else {
validator.reportSchemaError(key, new Object[] { elemErrorAnnotation,
assertImpl.getTest().getXPath().toString(),
- typeString, listUnionErrMessage} );
+ typeString, listAssertErrMessage} );
}
} // reportError
@@ -628,20 +668,16 @@ public class XMLAssertPsychopathImpl ext
String value = null;
// does this error concerns simpleType -> list
boolean isList;
- // does this error concerns simpleType -> union
- boolean isUnion;
// class constructor
public AssertionError(String errorCode, QName element,
XSAssertImpl assertImpl, String value,
- boolean isList,
- boolean isUnion) {
+ boolean isList) {
this.errorCode = errorCode;
this.element = element;
this.assertImpl = assertImpl;
this.value = value;
this.isList = isList;
- this.isUnion = isUnion;
}
public String getErrorCode() {
@@ -664,10 +700,6 @@ public class XMLAssertPsychopathImpl ext
return isList;
}
- public boolean isUnion() {
- return isUnion;
- }
-
} // class AssertionError
} // class XMLAssertPsychopathImpl
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=989206&r1=989205&r2=989206&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 Wed Aug 25 16:33:04 2010
@@ -83,6 +83,7 @@ import org.apache.xerces.xs.ShortList;
import org.apache.xerces.xs.StringList;
import org.apache.xerces.xs.XSConstants;
import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
import org.apache.xerces.xs.XSTypeDefinition;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@@ -1346,6 +1347,10 @@ public class XMLSchemaValidator
// assertion validator subcomponent
private XSDAssertionValidator fAssertionValidator = null;
+ // variable to track validity of simple content for union types.
+ // used for assertions processing.
+ private boolean fAtomicValueValid = true;
+
// 'type alternative' validator subcomponent
private XSDTypeAlternativeValidator fTypeAlternativeValidator = null;
@@ -2540,7 +2545,9 @@ public class XMLSchemaValidator
if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
fAssertionValidator.handleEndElement(element, fCurrentElemDecl,
fCurrentType, fNotation,
- fGrammarBucket);
+ fGrammarBucket,
+ fAtomicValueValid);
+ fAtomicValueValid = true;
}
// Check if we should modify the xsi:type ignore depth
@@ -3224,6 +3231,16 @@ public class XMLSchemaValidator
Object actualValue = null;
try {
actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
+
+ // additional check for assertions processing, for simple type
+ // variety 'union'.
+ if (attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (isUnionValidationAssertCheck(attDV.getMemberTypes(),
+ attrValue, null)) {
+ fAtomicValueValid = false;
+ }
+ }
+
// store the normalized value
if (fNormalizeData) {
attributes.setValue(index, fValidatedInfo.normalizedValue);
@@ -3246,6 +3263,7 @@ public class XMLSchemaValidator
}
}
catch (InvalidDatatypeValueException idve) {
+ fAtomicValueValid = false;
reportSchemaError(idve.getKey(), idve.getArgs());
reportSchemaError(
"cvc-attribute.3",
@@ -3375,8 +3393,18 @@ public class XMLSchemaValidator
try {
fValidationState.setFacetChecking(false);
attDV.validate(fValidationState, defaultValue);
+
+ // additional check for assertions processing, for simple type
+ // variety 'union'.
+ if (attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (isUnionValidationAssertCheck(attDV.getMemberTypes(),
+ null, defaultValue)) {
+ fAtomicValueValid = false;
+ }
+ }
}
catch (InvalidDatatypeValueException idve) {
+ fAtomicValueValid = false;
reportSchemaError(idve.getKey(), idve.getArgs());
}
fValidationState.setFacetChecking(facetChecking);
@@ -3582,7 +3610,18 @@ public class XMLSchemaValidator
fValidationState.setNormalizationRequired(true);
}
retValue = dv.validate(textContent, fValidationState, fValidatedInfo);
+
+ // additional check for assertions processing, for simple type
+ // variety 'union'.
+ if (dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (isUnionValidationAssertCheck(dv.getMemberTypes(),
+ String.valueOf(textContent),
+ null)) {
+ fAtomicValueValid = false;
+ }
+ }
} catch (InvalidDatatypeValueException e) {
+ fAtomicValueValid = false;
reportSchemaError(e.getKey(), e.getArgs());
reportSchemaError(
"cvc-type.3.1.3",
@@ -3621,7 +3660,18 @@ public class XMLSchemaValidator
fValidationState.setNormalizationRequired(true);
}
actualValue = dv.validate(textContent, fValidationState, fValidatedInfo);
+
+ // additional check for assertions processing, for simple type
+ // variety 'union'.
+ if (dv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
+ if (isUnionValidationAssertCheck(dv.getMemberTypes(),
+ String.valueOf(textContent),
+ null)) {
+ fAtomicValueValid = false;
+ }
+ }
} catch (InvalidDatatypeValueException e) {
+ fAtomicValueValid = false;
reportSchemaError(e.getKey(), e.getArgs());
reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname });
}
@@ -4779,4 +4829,41 @@ public class XMLSchemaValidator
}
}
+ /*
+ * Determine if an atomic value is valid with respect to any of the
+ * union's built-in schema types.
+ */
+ private boolean isUnionValidationAssertCheck(XSObjectList memberTypes,
+ String content,
+ ValidatedInfo validatedInfo) {
+
+ boolean isValid = false;
+
+ for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength();
+ memTypeIdx++) {
+ XSSimpleType simpleTypeDv = (XSSimpleType) memberTypes.item
+ (memTypeIdx);
+ if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(simpleTypeDv.
+ getNamespace())) {
+ try {
+ if (validatedInfo != null) {
+ simpleTypeDv.validate(fValidationState, validatedInfo);
+ }
+ else {
+ simpleTypeDv.validate(content, fValidationState,
+ fValidatedInfo);
+ }
+ isValid = true;
+ break;
+ }
+ catch(InvalidDatatypeValueException idve) {
+ isValid = false;
+ }
+ }
+ }
+
+ return isValid;
+
+ } // isUnionValidationAssertCheck
+
} // class SchemaValidator
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=989206&r1=989205&r2=989206&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 Wed Aug 25 16:33:04 2010
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Vector;
import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.xs.assertion.XMLAssertHandler;
import org.apache.xerces.impl.xs.assertion.XSAssert;
import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
@@ -64,7 +65,7 @@ public class XSDAssertionValidator {
* Class constructor
*/
public XSDAssertionValidator(XMLSchemaValidator xmlSchemaValidator) {
- this.xmlSchemaValidator = xmlSchemaValidator;
+ this.xmlSchemaValidator = xmlSchemaValidator;
}
@@ -96,11 +97,12 @@ public class XSDAssertionValidator {
NamespaceSupport xpathNamespaceContext = null;
if (assertionList instanceof XSObjectList) {
xpathNamespaceContext = ((XSAssertImpl)((XSObjectList)
- assertionList).get(0)).getXPath2NamespaceContext();
+ assertionList).item(0)).getXPath2NamespaceContext();
}
else {
- xpathNamespaceContext = ((XSAssertImpl)((Vector)
- assertionList).get(0)).getXPath2NamespaceContext();
+ Vector assertVector = (Vector) assertionList;
+ xpathNamespaceContext = ((XSAssertImpl)assertVector.
+ get(0)).getXPath2NamespaceContext();
}
Map assertProcessorParams = new HashMap();
@@ -129,7 +131,8 @@ public class XSDAssertionValidator {
XSElementDecl elemDecl,
XSTypeDefinition typeDef,
XSNotationDecl notation,
- XSGrammarBucket grammarBucket) {
+ XSGrammarBucket grammarBucket,
+ boolean atomicValueValid) {
if (fAssertionProcessor != null) {
try {
@@ -143,7 +146,9 @@ public class XSDAssertionValidator {
// construct the augmentations object for assertions.
// store assertPSVI into the augmentations
AugmentationsImpl assertAugs = new AugmentationsImpl();
- assertAugs.putItem(Constants.ELEMENT_PSVI, assertPSVI);
+ assertAugs.putItem(Constants.ELEMENT_PSVI, assertPSVI);
+ assertAugs.putItem("ATOMIC_VALUE_VALIDITY", Boolean.valueOf
+ (atomicValueValid));
fAssertionProcessor.endElement(element, assertAugs);
} catch (Exception ex) {
throw new XNIException(ex.getMessage(), ex);
@@ -163,127 +168,175 @@ public class XSDAssertionValidator {
XSTypeDefinition typeDef = xmlSchemaValidator.fCurrentPSVI.
getTypeDefinition();
+
List assertionList = null;
if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
- // if element's governing type is a "complex type"
- XSObjectListImpl assertions = new XSObjectListImpl();
- XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition)
- typeDef;
+ // if element's governing type is a "complex type"
+ XSObjectListImpl assertions = new XSObjectListImpl();
+ XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition)
+ typeDef;
- XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
- if (complexTypeAsserts.getLength() > 0) {
- for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
- assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
- }
- }
-
- // add assertion facets, from "complexType -> simpleContent ->
- // restriction".
- XSSimpleTypeDefinition simpleTypeDef = complexTypeDef.getSimpleType();
- if (simpleTypeDef != null) {
- XSObjectList complexTypeFacets = simpleTypeDef.getMultiValueFacets();
- for (int i = 0; i < complexTypeFacets.getLength(); i++) {
- XSMultiValueFacet facet = (XSMultiValueFacet)
- complexTypeFacets.item(i);
- if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
- Vector simpleContentAsserts = facet.getAsserts();
- for (int simpleAssertIdx = 0; simpleAssertIdx <
- simpleContentAsserts.size(); simpleAssertIdx++) {
- XSAssert simpleContentAssert = (XSAssert)
- simpleContentAsserts.get(simpleAssertIdx);
- assertions.addXSObject(simpleContentAssert);
- }
+ XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
+ if (complexTypeAsserts.getLength() > 0) {
+ for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
+ assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
}
+ }
+
+ // add assertion facets, from "complexType -> simpleContent ->
+ // restriction".
+ XSSimpleTypeDefinition simpleTypeDef = complexTypeDef.getSimpleType();
+ if (simpleTypeDef != null) {
+ XSObjectList complexTypeFacets = simpleTypeDef.getMultiValueFacets();
+ for (int i = 0; i < complexTypeFacets.getLength(); i++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet)
+ complexTypeFacets.item(i);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
+ Vector simpleContentAsserts = facet.getAsserts();
+ for (int simpleAssertIdx = 0; simpleAssertIdx <
+ simpleContentAsserts.size(); simpleAssertIdx++) {
+ XSAssert simpleContentAssert = (XSAssert)
+ simpleContentAsserts.get(simpleAssertIdx);
+ assertions.addXSObject(simpleContentAssert);
+ }
+ }
+ }
}
- }
- // there could be assertions, to be evaluated on attributes. add these
- // assertions to the list of assertions to be processed.
- for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
- Augmentations attrAugs = attributes.getAugmentations(attrIndx);
- AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
- (Constants.ATTRIBUTE_PSVI);
- XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition)attrPSVI.
- getTypeDefinition();
- if (attrType != null) {
- XSObjectList facets = attrType.getMultiValueFacets();
- for (int i = 0; i < facets.getLength(); i++) {
- XSMultiValueFacet facet = (XSMultiValueFacet)
- facets.item(i);
- if (facet.getFacetKind() == XSSimpleTypeDefinition.
- FACET_ASSERT) {
- Vector attrAsserts = facet.getAsserts();
- for (int j = 0; j < attrAsserts.size(); j++) {
- XSAssertImpl attrAssert = (XSAssertImpl)
- attrAsserts.elementAt(j);
- attrAssert.setAttrName(attributes.getLocalName
- (attrIndx));
- attrAssert.setAttrValue(attributes.getValue
- (attrIndx));
- assertions.addXSObject(attrAssert);
- }
- break;
- }
- }
+ // there could be assertions, to be evaluated on attributes. add these
+ // assertions to the list of assertions to be processed.
+ for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
+ Augmentations attrAugs = attributes.getAugmentations(attrIndx);
+ AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
+ (Constants.ATTRIBUTE_PSVI);
+ XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition)attrPSVI.
+ getTypeDefinition();
+ if (attrType != null) {
+ XSObjectList facets = attrType.getMultiValueFacets();
+ for (int i = 0; i < facets.getLength(); i++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet)
+ facets.item(i);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.
+ FACET_ASSERT) {
+ Vector attrAsserts = facet.getAsserts();
+ for (int j = 0; j < attrAsserts.size(); j++) {
+ XSAssertImpl attrAssert = (XSAssertImpl)
+ attrAsserts.elementAt(j);
+ attrAssert.setAttrName(attributes.getLocalName
+ (attrIndx));
+ attrAssert.setAttrValue(attributes.getValue
+ (attrIndx));
+ assertions.addXSObject(attrAssert);
+ }
+ break;
+ }
+ }
+ }
}
- }
- if (assertions.size() > 0) {
- assertionList = assertions;
- }
- }
- else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
- // if element's governing type is a "simple type"
- XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition)
- typeDef;
+ if (assertions.size() > 0) {
+ assertionList = assertions;
+ }
+ }
+ else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+ // if element's governing type is a "simple type"
+ XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition)
+ typeDef;
- XSObjectListImpl facets = (XSObjectListImpl) simpleTypeDef.
- getMultiValueFacets();
+ XSObjectListImpl facets = (XSObjectListImpl) simpleTypeDef.
+ getMultiValueFacets();
- if (facets.getLength() == 0 && simpleTypeDef.getItemType() !=
+ if (facets.getLength() == 0 && simpleTypeDef.getItemType() !=
null) {
- // facets for list -> simpleType
- facets = (XSObjectListImpl) simpleTypeDef.getItemType().
- getMultiValueFacets();
- }
- else {
- // facets for union -> simpleType*
- XSObjectList memberTypes = simpleTypeDef.getMemberTypes();
- for (int memberTypeIdx = 0; memberTypeIdx <
- memberTypes.getLength(); memberTypeIdx++) {
- XSObjectList memberTypeFacets = ((XSSimpleTypeDefinition)
- memberTypes.item(memberTypeIdx)).
- getMultiValueFacets();
- for (int memberTypeFacetIdx = 0; memberTypeFacetIdx <
- memberTypeFacets.getLength(); memberTypeFacetIdx++) {
- facets.addXSObject(memberTypeFacets.item
- (memberTypeFacetIdx));
+ // facets for list -> simpleType
+ facets = (XSObjectListImpl) simpleTypeDef.getItemType().
+ getMultiValueFacets();
+ }
+ else if (simpleTypeDef.getVariety() == XSSimpleType.
+ VARIETY_UNION) {
+ // assertions on a simpleType with variety union, are
+ // handled in a special way.
+ // NOTE: assertions on simpleType -> union are not
+ // accumulated here.
+ // create a dummy assertions list (so that a non-null
+ // assertions context is pushed on to a run-time assertions
+ // stack).
+ XSAssertImpl assertImpl = getFirstAssertFromUnionMemberTypes(
+ simpleTypeDef.getMemberTypes());
+ if (assertImpl != null) {
+ // this is done to pass a correct schema NamespaceContext
+ // for union assertions evaluation. since NamespaceContext
+ // is available in an assertions object, therefore we
+ // utilize the 1st assertions on a union for this need.
+
+ // REVISIT: if we can store the schema namespace context
+ // in a global store, then we can avoid storing it in
+ // every assertions object.
+ assertionList = new Vector();
+ assertionList.add(assertImpl);
}
- }
- }
-
- // iterate 'multi value' facets and get assertions from them
- for (int facetIdx = 0; facetIdx < facets.getLength();
- facetIdx++) {
- XSMultiValueFacet facet = (XSMultiValueFacet) facets.
- item(facetIdx);
- if (facet.getFacetKind() == XSSimpleTypeDefinition.
- FACET_ASSERT) {
- if (assertionList == null) {
- assertionList = new Vector();
- }
- assertionList.addAll(facet.getAsserts());
}
- }
- }
+
+ // iterate 'multi value' facets and get assertions from them
+ for (int facetIdx = 0; facetIdx < facets.getLength();
+ facetIdx++) {
+ XSMultiValueFacet facet = (XSMultiValueFacet) facets.
+ item(facetIdx);
+ if (facet.getFacetKind() == XSSimpleTypeDefinition.
+ FACET_ASSERT) {
+ if (assertionList == null) {
+ assertionList = new Vector();
+ }
+ assertionList.addAll(facet.getAsserts());
+ }
+ }
+ }
- return assertionList;
+ return assertionList;
} // getAssertsForEvaluation
/*
+ * Get the 1st assertion from the member types of union. Needed to get
+ * an schema '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++) {
+ 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++) {
+ 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;
+ }
+ }
+ }
+ }
+
+ return assertImpl;
+
+ } // getFirstAssertFromUnionMemberTypes
+
+
+ /*
* Method to initialize the assertions processor.
*/
private void initializeAssertProcessor(Map assertParams) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org