Author: mukulg
Date: Sat Apr 9 06:59:21 2022
New Revision: 1899673
URL: http://svn.apache.org/viewvc?rev=1899673&view=rev
Log:
committing fix for jira issue XERCESJ-1743. adding a related test case as well.
Added:
xerces/java/branches/xml-schema-1.1-tests/data/jira_bugs/1743_1.xsd
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
xerces/java/branches/xml-schema-1.1-tests/src/org/apache/xerces/tests/JiraBugsTests.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=1899673&r1=1899672&r2=1899673&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
Sat Apr 9 06:59:21 2022
@@ -19,7 +19,9 @@ package org.apache.xerces.impl.dv.xs;
import java.math.BigInteger;
import java.util.AbstractList;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -33,6 +35,8 @@ import org.apache.xerces.impl.dv.XSFacet
import org.apache.xerces.impl.dv.XSSimpleType;
import org.apache.xerces.impl.xpath.regex.RegularExpression;
import org.apache.xerces.impl.xs.SchemaSymbols;
+import org.apache.xerces.impl.xs.XMLAssertXPath2EngineImpl;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
import org.apache.xerces.impl.xs.util.ObjectListImpl;
import org.apache.xerces.impl.xs.util.ShortListImpl;
import org.apache.xerces.impl.xs.util.StringListImpl;
@@ -40,6 +44,7 @@ import org.apache.xerces.impl.xs.util.XS
import org.apache.xerces.util.XML11Char;
import org.apache.xerces.util.XMLChar;
import org.apache.xerces.xni.NamespaceContext;
+import org.apache.xerces.xni.QName;
import org.apache.xerces.xs.ShortList;
import org.apache.xerces.xs.StringList;
import org.apache.xerces.xs.XSAnnotation;
@@ -931,6 +936,7 @@ public class XSSimpleTypeDecl implements
ValidationContextImpl ctx = new ValidationContextImpl(context);
enumerationAnnotations = facets.enumAnnotations;
fEnumerationSize = 0;
+
for (int i = 0; i < size; i++) {
if (enumNSDecls != null)
ctx.setNSContext((NamespaceContext)enumNSDecls.elementAt(i));
@@ -942,6 +948,43 @@ public class XSSimpleTypeDecl implements
reportError("enumeration-valid-restriction", new
Object[]{enumVals.elementAt(i), this.getBaseType().getName()});
}
}
+
+ if (fAssertion != null && fAssertion.size() > 0) {
+ // added for XML Schema 1.1
+ String enumVal = null;
+ try {
+ Map assertProcessorParams = new HashMap();
+
assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT,
((XSAssertImpl)fAssertion.get(0)).
+
getXPath2NamespaceContext());
+ XMLAssertXPath2EngineImpl fAssertionProcessor = new
XMLAssertXPath2EngineImpl(assertProcessorParams);
+ fAssertionProcessor.initXPathProcessor();
+ QName elemQname = new QName(null, "enumeration",
"enumeration", Constants.NS_XMLSCHEMA);
+ QName attrQname = new QName(null, "value", "value",
null);
+ boolean isTypeDerivedFromList = ((XSSimpleType)
this.getBaseType().getBaseType()).
+
getVariety() == XSSimpleType.VARIETY_LIST;
+ boolean isTypeDerivedFromUnion = ((XSSimpleType)
this.getBaseType().getBaseType()).
+
getVariety() == XSSimpleType.VARIETY_UNION;
+ for (int idx = 0; idx < fAssertion.size(); idx++) {
+ XSAssertImpl assertImpl =
(XSAssertImpl)fAssertion.get(idx);
+ for (int i = 0; i < size; i++) {
+ enumVal = (String)enumVals.elementAt(i);
+ Boolean isAssertSucceeded =
fAssertionProcessor.evaluateOneAssertionFromSimpleType(elemQname, enumVal,
null,
+
(XSSimpleTypeDefinition)this.getBaseType(), isTypeDerivedFromList,
+
isTypeDerivedFromUnion, assertImpl, true, attrQname, true);
+ if (isAssertSucceeded.booleanValue() == false) {
+ throw new InvalidDatatypeFacetException(null,
null);
+ }
+ }
+ }
+ }
+ catch (InvalidDatatypeFacetException ex) {
+ reportError("enumeration-valid-restriction", new
Object[]{enumVal, this.getBaseType().getName()});
+ }
+ catch (Exception ex) {
+ // NO OP
+ }
+ }
+
fFacetsDefined |= FACET_ENUMERATION;
if ((fixedFacet & FACET_ENUMERATION) != 0)
fFixedFacet |= FACET_ENUMERATION;
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java?rev=1899673&r1=1899672&r2=1899673&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
Sat Apr 9 06:59:21 2022
@@ -134,7 +134,7 @@ public class XMLAssertXPath2EngineImpl e
/*
* Initialize the Eclipse XPath processor.
*/
- private void initXPathProcessor() throws Exception {
+ public void initXPathProcessor() throws Exception {
fXmlSchemaValidator = (XMLSchemaValidator)
getProperty("http://apache.org/xml/properties/assert/validator");
fAbstrXpathEngineImpl = new AbstractXPath2EngineImpl();
fXpath2DynamicContext =
fAbstrXpathEngineImpl.initXPath2DynamicContext(fSchemaXSmodel, fAssertDocument,
fAssertParams);
@@ -216,7 +216,7 @@ public class XMLAssertXPath2EngineImpl e
for (int assertIdx = 0; assertIdx < attrAssertList.size();
assertIdx++) {
XSAssertImpl assertImpl =
(XSAssertImpl)attrAssertList.get(assertIdx);
assertImpl.setAttrName(attrQname.localpart);
- evaluateOneAssertionFromSimpleType(element, attrValue,
attrAugs, attrSimpleType, isTypeDerivedFromList, isTypeDerivedFromUnion,
assertImpl, true, attrQname);
+ evaluateOneAssertionFromSimpleType(element, attrValue,
attrAugs, attrSimpleType, isTypeDerivedFromList, isTypeDerivedFromUnion,
assertImpl, true, attrQname, false);
// evaluate assertions on itemType of xs:list
XSSimpleTypeDefinition attrItemType =
attrSimpleType.getItemType();
if (isTypeDerivedFromList && attrItemType != null) {
@@ -393,7 +393,7 @@ public class XMLAssertXPath2EngineImpl e
if (xPathDefaultNamespace != null) {
fXpath2DynamicContext.add_namespace(null,
xPathDefaultNamespace);
}
- evaluateOneAssertionFromSimpleType(element, value, augs,
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl,
false, null);
+ evaluateOneAssertionFromSimpleType(element, value, augs,
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl,
false, null, false);
}
// evaluate assertions on itemType of xs:list
@@ -407,8 +407,10 @@ public class XMLAssertXPath2EngineImpl e
/*
* Evaluate one assertion instance for a simpleType (this assertion could
be from an attribute, simpleType on element or a complexType with simple
content).
*/
- private void evaluateOneAssertionFromSimpleType(QName element, String
value, Augmentations augs, XSSimpleTypeDefinition simpleTypeDefn, boolean
isTypeDerivedFromList, boolean isTypeDerivedFromUnion,
- XSAssertImpl assertImpl,
boolean isAttribute, QName attrQname) throws Exception {
+ public Boolean evaluateOneAssertionFromSimpleType(QName element, String
value, Augmentations augs, XSSimpleTypeDefinition simpleTypeDefn, boolean
isTypeDerivedFromList, boolean isTypeDerivedFromUnion,
+ XSAssertImpl assertImpl,
boolean isAttribute, QName attrQname, boolean isAssertEvaluationFromSchema)
throws Exception {
+
+ Boolean isAssertSucceeded = Boolean.TRUE;
if (simpleTypeDefn.getVariety() ==
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
// evaluating assertions for "simpleType -> restriction" (not
derived by union)
@@ -420,26 +422,43 @@ public class XMLAssertXPath2EngineImpl e
}
AssertionError assertError = evaluateOneAssertion(element,
assertImpl, value, false, false);
if (assertError != null) {
- reportAssertionsError(assertError);
+ if (isAssertEvaluationFromSchema) {
+ isAssertSucceeded = Boolean.FALSE;
+ }
+ else {
+ reportAssertionsError(assertError);
+ }
}
}
else if (simpleTypeDefn.getVariety() ==
XSSimpleTypeDefinition.VARIETY_LIST) {
// evaluating assertions for "simpleType -> list"
- evaluateAssertionOnSTListValue(element, value, assertImpl, false,
simpleTypeDefn.getItemType(), isTypeDerivedFromList);
+ isAssertSucceeded = evaluateAssertionOnSTListValue(element, value,
assertImpl, false, simpleTypeDefn.getItemType(), isTypeDerivedFromList,
isAssertEvaluationFromSchema);
}
else if (!isAttribute &&
((Boolean)augs.getItem(XSAssertConstants.isAssertProcNeededForUnionElem)).booleanValue())
{
// evaluating assertions for "simpleType -> union" for an element
- if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn,
isTypeDerivedFromUnion, assertImpl, value, augs)) {
- fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new
Object[] {element.rawname, value});
+ if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn,
isTypeDerivedFromUnion, assertImpl, value, augs)) {
+ if (isAssertEvaluationFromSchema) {
+ isAssertSucceeded = Boolean.FALSE;
+ }
+ else {
+ fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new
Object[] {element.rawname, value});
+ }
}
}
else if (isAttribute &&
((Boolean)augs.getItem(XSAssertConstants.isAssertProcNeededForUnionAttr)).booleanValue())
{
// evaluating assertions for "simpleType -> union" for an
attribute
- if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn,
isTypeDerivedFromUnion, assertImpl, value, augs)) {
- fXmlSchemaValidator.reportSchemaError("cvc-attribute.3", new
Object[] {element.rawname, attrQname.localpart, value,
((XSSimpleTypeDecl)simpleTypeDefn).getTypeName()});
+ if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn,
isTypeDerivedFromUnion, assertImpl, value, augs)) {
+ if (isAssertEvaluationFromSchema) {
+ isAssertSucceeded = Boolean.FALSE;
+ }
+ else {
+ fXmlSchemaValidator.reportSchemaError("cvc-attribute.3",
new Object[] {element.rawname, attrQname.localpart, value,
((XSSimpleTypeDecl)simpleTypeDefn).getTypeName()});
+ }
}
}
+ return isAssertSucceeded;
+
} // evaluateOneAssertionFromSimpleType
@@ -471,8 +490,10 @@ public class XMLAssertXPath2EngineImpl e
/*
* Evaluate assertion on a simpleType xs:list value.
*/
- private void evaluateAssertionOnSTListValue(QName element, String
listStrValue, XSAssertImpl assertImpl, boolean xpathContextExists,
- XSSimpleTypeDefinition
itemType, boolean isTypeDerivedFromList) throws Exception {
+ private Boolean evaluateAssertionOnSTListValue(QName element, String
listStrValue, XSAssertImpl assertImpl, boolean xpathContextExists,
+ XSSimpleTypeDefinition
itemType, boolean isTypeDerivedFromList, boolean isAssertEvaluationFromSchema)
throws Exception {
+
+ Boolean isAssertSucceeded = Boolean.TRUE;
AssertionError assertError = null;
@@ -480,8 +501,13 @@ public class XMLAssertXPath2EngineImpl e
setXDMTypedValueOf$valueForSTVarietyList(fCurrentAssertDomNode,
listStrValue, itemType, isTypeDerivedFromList, fXpath2DynamicContext);
assertError = evaluateOneAssertion(element, assertImpl,
listStrValue, xpathContextExists, true);
if (assertError != null) {
- assertError.setIsTypeDerivedFromList(isTypeDerivedFromList);
- reportAssertionsError(assertError);
+ if (isAssertEvaluationFromSchema) {
+ isAssertSucceeded = Boolean.FALSE;
+ }
+ else {
+ assertError.setIsTypeDerivedFromList(isTypeDerivedFromList);
+ reportAssertionsError(assertError);
+ }
}
}
else {
@@ -493,11 +519,18 @@ public class XMLAssertXPath2EngineImpl e
setXDMTypedValueOf$valueForSTVarietyList(fCurrentAssertDomNode,
listItemStrValue, itemType, isTypeDerivedFromList, fXpath2DynamicContext);
assertError = evaluateOneAssertion(element, assertImpl,
listItemStrValue, xpathContextExists, true);
if (assertError != null) {
- reportAssertionsError(assertError);
+ if (isAssertEvaluationFromSchema) {
+ isAssertSucceeded = Boolean.FALSE;
+ }
+ else {
+ reportAssertionsError(assertError);
+ }
}
}
}
+ return isAssertSucceeded;
+
} // evaluateAssertionOnSTListValue
@@ -587,7 +620,7 @@ public class XMLAssertXPath2EngineImpl e
boolean isTypeDerivedFromList =
isTypeDerivedFromSTList(simpleTypeDefn);
boolean isTypeDerivedFromUnion =
isTypeDerivedFromSTUnion(simpleTypeDefn);
restorePsviInfoForXPathContext(elemPsvi);
- evaluateOneAssertionFromSimpleType(element, value, augs,
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl,
false, null);
+ evaluateOneAssertionFromSimpleType(element, value, augs,
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl,
false, null, false);
savePsviInfoWithUntypingOfAssertRoot(elemPsvi, true);
// evaluate assertions on itemType of xs:list
XSSimpleTypeDefinition listItemType =
simpleTypeDefn.getItemType();
Added: xerces/java/branches/xml-schema-1.1-tests/data/jira_bugs/1743_1.xsd
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-tests/data/jira_bugs/1743_1.xsd?rev=1899673&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-tests/data/jira_bugs/1743_1.xsd (added)
+++ xerces/java/branches/xml-schema-1.1-tests/data/jira_bugs/1743_1.xsd Sat Apr
9 06:59:21 2022
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:element name="color">
+ <xs:simpleType>
+ <xs:restriction base="Color">
+ <xs:enumeration value="a"/>
+ <xs:enumeration value="b"/>
+ <xs:enumeration value="c"/>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+
+ <xs:simpleType name="Color">
+ <xs:restriction base="xs:string">
+ <xs:assertion test="matches($value, '^(red|green|blue|yellow)$')"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+</xs:schema>
\ No newline at end of file
Modified:
xerces/java/branches/xml-schema-1.1-tests/src/org/apache/xerces/tests/JiraBugsTests.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-tests/src/org/apache/xerces/tests/JiraBugsTests.java?rev=1899673&r1=1899672&r2=1899673&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-tests/src/org/apache/xerces/tests/JiraBugsTests.java
(original)
+++
xerces/java/branches/xml-schema-1.1-tests/src/org/apache/xerces/tests/JiraBugsTests.java
Sat Apr 9 06:59:21 2022
@@ -624,5 +624,16 @@ public class JiraBugsTests extends Xerce
assertTrue(false);
}
}
+
+ public void testJira_1743_1() {
+ String schemapath = fDataDir+"/jira_bugs/1743_1.xsd";
+ try {
+ Schema s = fSchemaFactory.newSchema(new
StreamSource(schemapath));
+ assertTrue(failureList.size() == 1);
+ } catch(Exception ex) {
+ assertEquals(ex.getMessage(),
"enumeration-valid-restriction: Enumeration value"
+ + " 'a' is not in the
value space of the base type, Color.");
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]