Author: mukulg Date: Sun Oct 9 04:34:12 2011 New Revision: 1180543 URL: http://svn.apache.org/viewvc?rev=1180543&view=rev Log: committing a schema 1.1 fix. started with fixing implementation to comply to the XSD 1.1 test case "cta9003err" (contributed by Saxonica). doing additional static checking of XPath expression, in XSDTypeAlternativeTraverser to abort processing and raise error, if for example a schema type used in the XPath expression isn't present in the XPath static context (which is been tested by the test case mentioned above).
have also done minor refactoring in other parts of code base (also in class XSTypeHelper, which is not related to the functional fix for this commit). Modified: 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/msg/XMLSchemaMessages.properties xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.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/alternative/Test.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java 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=1180543&r1=1180542&r2=1180543&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 Sun Oct 9 04:34:12 2011 @@ -497,6 +497,9 @@ public final class Constants { public final static short TYPE_AND_FACET_AVAILABILITY = 2; public final static short TYPE_AND_FACET_UNAVAILABILITY = 3; + // Constants to support PsychoPath XPath engine uses + public final static String XPATH2_NAMESPACE_CONTEXT = "XPATH2_NS_CONTEXT"; + // private /** SAX features. */ 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=1180543&r1=1180542&r2=1180543&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 Sun Oct 9 04:34:12 2011 @@ -348,7 +348,8 @@ c-fields-xpaths = c-fields-xpaths: The field value = ''{0}'' is not valid. c-general-xpath = c-general-xpath: The expression ''{0}'' is not valid with respect to the XPath subset supported by XML Schema. c-general-xpath-ns = c-general-xpath-ns: A namespace prefix in XPath expression ''{0}'' was not bound to a namespace. - c-cta-xpath = c-cta-xpath: The XPath expression ''{0}'' couldn''t compile successfully in ''{1}'' mode, during CTA evaluation. + c-cta-xpath = c-cta-xpath: The XPath expression ''{0}'' couldn''t compile successfully in ''{1}'' mode, during CTA evaluation. + c-cta-xpath-serr = c-cta-xpath-serr: The XPath expression ''{0}'' couldn''t compile successfully in ''{1}'' mode, during CTA evaluation. A static error ''{2}'' occured in the XPath expression. c-selector-xpath = c-selector-xpath: The selector value = ''{0}'' is not valid; selector xpaths cannot contain attributes. EmptyTargetNamespace = EmptyTargetNamespace: In schema document ''{0}'', the value of the ''targetNamespace'' attribute cannot be an empty string. FacetValueFromBase = FacetValueFromBase: In the declaration of type ''{0}'', value ''{1}'' of facet ''{2}'' must be from the value space of the base type, ''{3}''. Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java?rev=1180543&r1=1180542&r2=1180543&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathXPath2Impl.java Sun Oct 9 04:34:12 2011 @@ -20,6 +20,9 @@ package org.apache.xerces.impl.xs; import java.util.Enumeration; import java.util.Map; +import javax.xml.XMLConstants; + +import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.xs.assertion.XSAssertImpl; import org.apache.xerces.impl.xs.traversers.XSDHandler; import org.apache.xerces.impl.xs.util.XSTypeHelper; @@ -60,19 +63,21 @@ public class AbstractPsychoPathXPath2Imp private Document fDomDoc = null; /* - * Initialize the PsychoPath engine XPath 2.0 dynamic context. + * Initialize the PsychoPath engine XPath 2.0 dynamic context. This also initializes the XPath engine's static + * context, since dynamic context is inherited from the static context. */ - protected DynamicContext initXPath2DynamicContext(XSModel schema, Document document, Map psychoPathParams) { + public DynamicContext initXPath2DynamicContext(XSModel schema, Document document, Map psychoPathParams) { fXpath2DynamicContext = new DefaultDynamicContext(schema, document); // populate the 'PsychoPath XPath 2' static context, with namespace bindings derived from the XML Schema document - NamespaceSupport xpath2NamespaceContext = (NamespaceSupport) psychoPathParams.get("XPATH2_NS_CONTEXT"); + NamespaceSupport xpath2NamespaceContext = (NamespaceSupport) psychoPathParams.get(Constants.XPATH2_NAMESPACE_CONTEXT); Enumeration currPrefixes = xpath2NamespaceContext.getAllPrefixes(); while (currPrefixes.hasMoreElements()) { String prefix = (String)currPrefixes.nextElement(); addNamespaceBindingToXPath2DynamicContext(prefix, xpath2NamespaceContext.getURI(prefix)); - } + } + addNamespaceBindingToXPath2DynamicContext(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); fXpath2DynamicContext.add_function_library(new FnFunctionLibrary()); fXpath2DynamicContext.add_function_library(new XSCtrLibrary()); fDomDoc = document; 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=1180543&r1=1180542&r2=1180543&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 Sun Oct 9 04:34:12 2011 @@ -107,7 +107,7 @@ public class XSDAssertionValidator { } Map assertProcessorParams = new HashMap(); - assertProcessorParams.put("XPATH2_NS_CONTEXT", xpathNamespaceContext); + assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, xpathNamespaceContext); // initialize the assertions processor initializeAssertProcessor(assertProcessorParams); } Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java?rev=1180543&r1=1180542&r2=1180543&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java Sun Oct 9 04:34:12 2011 @@ -25,6 +25,7 @@ import javax.xml.XMLConstants; import org.apache.xerces.dom.PSVIAttrNSImpl; import org.apache.xerces.dom.PSVIDocumentImpl; +import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.xpath.XPath20; import org.apache.xerces.impl.xs.AbstractPsychoPathXPath2Impl; import org.apache.xerces.impl.xs.SchemaSymbols; @@ -155,7 +156,7 @@ public class Test extends AbstractPsycho // construct parameter values for psychopath xpath processor Map psychoPathParams = new HashMap(); - psychoPathParams.put("XPATH2_NS_CONTEXT", fXPath2NamespaceContext); + psychoPathParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, fXPath2NamespaceContext); initXPath2DynamicContext(null, document, psychoPathParams); if (fTypeAlternative.fXPathDefaultNamespace != null) { addNamespaceBindingToXPath2DynamicContext(null, fTypeAlternative.fXPathDefaultNamespace); Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java?rev=1180543&r1=1180542&r2=1180543&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java Sun Oct 9 04:34:12 2011 @@ -17,10 +17,14 @@ package org.apache.xerces.impl.xs.traversers; +import java.util.HashMap; +import java.util.Map; + import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.dv.XSSimpleType; import org.apache.xerces.impl.xpath.XPath20; import org.apache.xerces.impl.xpath.XPathException; +import org.apache.xerces.impl.xs.AbstractPsychoPathXPath2Impl; import org.apache.xerces.impl.xs.SchemaGrammar; import org.apache.xerces.impl.xs.SchemaSymbols; import org.apache.xerces.impl.xs.XSAnnotationImpl; @@ -37,6 +41,9 @@ import org.apache.xerces.xni.QName; import org.apache.xerces.xs.XSObjectList; import org.apache.xerces.xs.XSTypeDefinition; import org.eclipse.wst.xml.xpath2.processor.JFlexCupParser; +import org.eclipse.wst.xml.xpath2.processor.StaticChecker; +import org.eclipse.wst.xml.xpath2.processor.StaticError; +import org.eclipse.wst.xml.xpath2.processor.StaticNameResolver; import org.eclipse.wst.xml.xpath2.processor.XPathParser; import org.eclipse.wst.xml.xpath2.processor.XPathParserException; import org.eclipse.wst.xml.xpath2.processor.ast.XPath; @@ -57,6 +64,7 @@ import org.w3c.dom.Element; * @xerces.internal * * @author Hiranya Jayathilaka, University of Moratuwa + * @author Mukul Gandhi IBM * @version $Id$ */ class XSDTypeAlternativeTraverser extends XSDAbstractTraverser { @@ -64,6 +72,7 @@ class XSDTypeAlternativeTraverser extend private static final XSSimpleType fErrorType; private boolean fIsFullXPathModeForCTA; private String[] fctaXPathModes = {"cta-subset", "cta-full"}; + private AbstractPsychoPathXPath2Impl abstractPsychoPathInst = new AbstractPsychoPathXPath2Impl(); static { SchemaGrammar grammar = SchemaGrammar.getS4SGrammar(Constants.SCHEMA_VERSION_1_1); @@ -196,6 +205,10 @@ class XSDTypeAlternativeTraverser extend // if full XPath 2.0 support is enabled for CTA, use PsychoPath XPath 2.0 engine for XPath evaluation XPathParser xpp = new JFlexCupParser(); XPath xp = xpp.parse("boolean(" + testStr + ")"); + Map psychoPathParams = new HashMap(); + psychoPathParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, schemaDoc.fNamespaceSupport); + StaticChecker name_check = new StaticNameResolver(abstractPsychoPathInst.initXPath2DynamicContext(null, null, psychoPathParams)); + name_check.check(xp); testExpr = new Test(xp, testStr, typeAlternative, schemaDoc.fNamespaceSupport); } else { @@ -212,6 +225,10 @@ class XSDTypeAlternativeTraverser extend // if XPath expression couldn't compile, create a "test" without an expression testExpr = new Test((XPath20) null, typeAlternative, new NamespaceSupport(schemaDoc.fNamespaceSupport)); reportSchemaError("c-cta-xpath", new Object[] {testStr, fctaXPathModes[1]}, altElement); + } catch (StaticError serr) { + // if XPath expression couldn't compile, and there's a static error in XPath expression, create a "test" without an expression + testExpr = new Test((XPath20) null, typeAlternative, new NamespaceSupport(schemaDoc.fNamespaceSupport)); + reportSchemaError("c-cta-xpath-serr", new Object[] {testStr, fctaXPathModes[1], serr.code()}, altElement); } typeAlternative.setTest(testExpr); } Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=1180543&r1=1180542&r2=1180543&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java Sun Oct 9 04:34:12 2011 @@ -139,7 +139,7 @@ public class XSTypeHelper { /* - * Validate a QName value (check correct lexical form, and if the prefix is declared), and report errors if there. + * Validate a QName value (check lexical form for correctness, and if the prefix is declared), and report errors if there are any. */ public static void validateQNameValue(String qNameStr, NamespaceContext namespaceContext, XMLErrorReporter errorReporter) { @@ -166,7 +166,7 @@ public class XSTypeHelper { /* - * Parse QName string value into prefix and local-name pairs. + * Parse a QName string value into prefix and local-name pairs. */ private static String[] parseQnameString(String qNameStr) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org