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/10/08 09:51:09 UTC

svn commit: r1180333 - in /xerces/java/branches/xml-schema-1.1-dev: src/org/apache/xerces/impl/xs/ src/org/apache/xerces/impl/xs/alternative/ src/org/apache/xerces/impl/xs/assertion/ src/org/apache/xerces/impl/xs/util/ tools/

Author: mukulg
Date: Sat Oct  8 07:51:08 2011
New Revision: 1180333

URL: http://svn.apache.org/viewvc?rev=1180333&view=rev
Log:
starting with need to improve schema 1.1 implementation, as per requirements of XSD 1.1 CTA test "cta0006.n01" (contributed by Saxonica), have made following improvements in this commit,
- adding in-scope namespaces to XDM tree for type alternatives (for full XPath mode evaluation)
- improved implementation of XPath2 "resolve-QName" function and xs:QName type implementation. a new PsychoPath XPath 2.0 jar is provided with these improvements.

have also done minor refactoring.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.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/XSDTypeAlternativeValidator.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/assertion/XSAssertionXPath2ValueImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
    xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.2.0.jar

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java?rev=1180333&r1=1180332&r2=1180333&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java Sat Oct  8 07:51:08 2011
@@ -41,6 +41,7 @@ public final class SchemaSymbols {
     public static final String XSI_NONAMESPACESCHEMALOCATION = "noNamespaceSchemaLocation".intern();
     public static final String XSI_TYPE                      = "type".intern();
     public static final String XSI_NIL                       = "nil".intern();
+    public static final String EMPTY_STRING                  = "".intern(); 
 
     // schema namespace
     public static final String URI_SCHEMAFORSCHEMA           = "http://www.w3.org/2001/XMLSchema".intern();

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=1180333&r1=1180332&r2=1180333&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 Sat Oct  8 07:51:08 2011
@@ -422,6 +422,8 @@ public class XMLSchemaValidator
     private IDContext fIDContext = null;
     
     private String fDatatypeXMLVersion = null;
+    
+    private NamespaceContext fNamespaceContext = null;
 
     /**
      * A wrapper of the standard error reporter. We'll store all schema errors
@@ -774,6 +776,8 @@ public class XMLSchemaValidator
         if (fDocumentHandler != null) {
             fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs);
         }
+        
+        fNamespaceContext = namespaceContext;
 
     } // startDocument(XMLLocator,String)
 
@@ -2246,7 +2250,7 @@ public class XMLSchemaValidator
 
         //process type alternatives
         if (fTypeAlternativesChecking && fCurrentElemDecl != null) {
-           fTypeAlternative = fTypeAlternativeValidator.getTypeAlternative(fCurrentElemDecl, element, attributes, fInheritableAttrList);           
+           fTypeAlternative = fTypeAlternativeValidator.getTypeAlternative(fCurrentElemDecl, element, attributes, fInheritableAttrList, fNamespaceContext);           
            if (fTypeAlternative != null) {
                fCurrentType = fTypeAlternative.getTypeDefinition();
            }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDTypeAlternativeValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDTypeAlternativeValidator.java?rev=1180333&r1=1180332&r2=1180333&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDTypeAlternativeValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDTypeAlternativeValidator.java Sat Oct  8 07:51:08 2011
@@ -23,6 +23,7 @@ import org.apache.xerces.impl.xs.alterna
 import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
 import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.XMLAttributesImpl;
+import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
 import org.apache.xerces.xs.AttributePSVI;
@@ -52,7 +53,7 @@ public class XSDTypeAlternativeValidator
     /*
      * Determine the schema type applicable (represented as XSTypeAlternative component) for an element declaration, using type alternative information.
      */
-    public XSTypeAlternative getTypeAlternative(XSElementDecl currentElemDecl, QName element, XMLAttributes attributes, Vector inheritableAttrList) {
+    public XSTypeAlternative getTypeAlternative(XSElementDecl currentElemDecl, QName element, XMLAttributes attributes, Vector inheritableAttrList, NamespaceContext instanceNamespaceContext) {
         
         XSTypeAlternative selectedTypeAlternative = null; 
         
@@ -62,7 +63,7 @@ public class XSDTypeAlternativeValidator
             XMLAttributes ctaAttributes = getAttributesForCTA(attributes, inheritableAttrList);
             for (int typeAltIdx = 0; typeAltIdx < typeAlternatives.length; typeAltIdx++) {
                 Test ctaTest = typeAlternatives[typeAltIdx].getTest();
-                if (ctaTest != null && ctaTest.evaluateTest(element, ctaAttributes)) {
+                if (ctaTest != null && ctaTest.evaluateTest(element, ctaAttributes, instanceNamespaceContext)) {
                     selectedTypeAlternative = typeAlternatives[typeAltIdx]; 
                     break;
                 }

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=1180333&r1=1180332&r2=1180333&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 Sat Oct  8 07:51:08 2011
@@ -17,14 +17,19 @@
 
 package org.apache.xerces.impl.xs.alternative;
 
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
+
 import org.apache.xerces.dom.PSVIAttrNSImpl;
 import org.apache.xerces.dom.PSVIDocumentImpl;
 import org.apache.xerces.impl.xpath.XPath20;
 import org.apache.xerces.impl.xs.AbstractPsychoPathXPath2Impl;
+import org.apache.xerces.impl.xs.SchemaSymbols;
 import org.apache.xerces.util.NamespaceSupport;
+import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
 import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
@@ -102,11 +107,11 @@ public class Test extends AbstractPsycho
     }
     
     /** Evaluate the test expression with respect to the specified element and its attributes */
-    public boolean evaluateTest(QName element, XMLAttributes attributes) {        
+    public boolean evaluateTest(QName element, XMLAttributes attributes, NamespaceContext instanceNamespaceContext) {        
         if (fXPath != null) {
             return fXPath.evaluateTest(element, attributes);
         } else if (fXPathPsychoPath != null) {
-            return evaluateTestWithPsychoPathXPathEngine(element, attributes);  
+            return evaluateTestWithPsychoPathXPathEngine(element, attributes, instanceNamespaceContext);  
         }
         else {
             return false;
@@ -120,7 +125,7 @@ public class Test extends AbstractPsycho
     /*
      * Evaluate the XPath "test" expression on an XDM instance, for CTA evaluation. Uses PsychoPath XPath 2.0 engine for the evaluation. 
      */
-    private boolean evaluateTestWithPsychoPathXPathEngine(QName element, XMLAttributes attributes) {
+    private boolean evaluateTestWithPsychoPathXPathEngine(QName element, XMLAttributes attributes, NamespaceContext instanceNamespaceContext) {
         
         boolean evaluationResult = false;
 
@@ -134,6 +139,18 @@ public class Test extends AbstractPsycho
                 attrNode.setNodeValue(attributes.getValue(attrIndx));
                 elem.setAttributeNode(attrNode);
             }
+
+            // add in-scope namespaces on the document tree
+            Enumeration currPrefixes = instanceNamespaceContext.getAllPrefixes();
+            while (currPrefixes.hasMoreElements()) {
+                String prefix = (String)currPrefixes.nextElement();
+                String nsUri = instanceNamespaceContext.getURI(prefix);
+                if (!(XMLConstants.XML_NS_PREFIX.equals(prefix) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix))) {
+                   String attrName = (prefix!=null && !SchemaSymbols.EMPTY_STRING.equals(prefix)) ? XMLConstants.XMLNS_ATTRIBUTE+":"+prefix : XMLConstants.XMLNS_ATTRIBUTE;  
+                   elem.setAttribute(attrName, nsUri);  
+                }
+            } 
+            
             document.appendChild(elem);
 
             // construct parameter values for psychopath xpath processor

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java?rev=1180333&r1=1180332&r2=1180333&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java Sat Oct  8 07:51:08 2011
@@ -35,7 +35,7 @@ import org.apache.xerces.xs.XSObjectList
 import org.apache.xerces.xs.XSSimpleTypeDefinition;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
-import org.eclipse.wst.xml.xpath2.processor.PsychoPathTypeHelper;
+import org.eclipse.wst.xml.xpath2.processor.PsychoPathXPathTypeHelper;
 import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType;
 import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
 import org.eclipse.wst.xml.xpath2.processor.internal.types.SchemaTypeValueFactory;
@@ -263,11 +263,11 @@ public class XSAssertionXPath2ValueImpl 
             // the below 'if else' clauses are written to process few special cases handling few of schema types within PsychoPath XPath engine
             final String elementTypeName = elementType.getName();
             if ("dayTimeDuration".equals(elementTypeName)) {
-                typeCode = PsychoPathTypeHelper.DAYTIMEDURATION_DT;
+                typeCode = PsychoPathXPathTypeHelper.DAYTIMEDURATION_DT;
                 isxsd11Type = true;
             }
             else if ("yearMonthDuration".equals(elementTypeName)) {
-                typeCode = PsychoPathTypeHelper.YEARMONTHDURATION_DT;
+                typeCode = PsychoPathXPathTypeHelper.YEARMONTHDURATION_DT;
                 isxsd11Type = true;
             }
 

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=1180333&r1=1180332&r2=1180333&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 Sat Oct  8 07:51:08 2011
@@ -51,9 +51,7 @@ import org.eclipse.wst.xml.xpath2.proces
  * @author Mukul Gandhi, IBM
  * @version $Id$
  */
-public class XSTypeHelper {
-    
-    private static final String EMPTY_STRING = "".intern();    
+public class XSTypeHelper { 
     
     /*
      * Checks if the two schema type components are identical.
@@ -141,43 +139,57 @@ public class XSTypeHelper {
     
     
     /*
-     * Validate a QName value (it should be in correct lexical form, and it's prefix must be declared), and report
-     * errors as found.
+     * Validate a QName value (check correct lexical form, and if the prefix is declared), and report errors if there.
      */
     public static void validateQNameValue(String qNameStr, NamespaceContext namespaceContext, XMLErrorReporter errorReporter) {
         
-        String prefix, localpart;
-        int colonptr = qNameStr.indexOf(':');
-        if (colonptr > 0) {
-            prefix = qNameStr.substring(0, colonptr);
-            localpart = qNameStr.substring(colonptr + 1);
-        } else {
-            prefix = EMPTY_STRING;
-            localpart = qNameStr;
-        }
+        String[] parsedQname = parseQnameString(qNameStr);
+        String prefix = parsedQname[0]; 
+        String localpart = parsedQname[1];
         
         // both prefix (if any) and localpart must be valid NCName
         if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix)) {
-            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "cvc-datatype-valid.1.2.1",
-                                      new Object[] {qNameStr, "QName"}, XMLErrorReporter.SEVERITY_ERROR);
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "cvc-datatype-valid.1.2.1", new Object[] {qNameStr, "QName"}, XMLErrorReporter.SEVERITY_ERROR);
         }
 
         if(!XMLChar.isValidNCName(localpart)) {
-            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "cvc-datatype-valid.1.2.1",
-                                      new Object[] {qNameStr, "QName"}, XMLErrorReporter.SEVERITY_ERROR);
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "cvc-datatype-valid.1.2.1", new Object[] {qNameStr, "QName"}, XMLErrorReporter.SEVERITY_ERROR);
         }
 
         // resove prefix to a uri, report an error if failed
         String uri = namespaceContext.getURI(prefix.intern());
         if (prefix.length() > 0 && uri == null) {
-            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "UndeclaredPrefix",
-                                      new Object[] {qNameStr, prefix}, XMLErrorReporter.SEVERITY_ERROR);
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "UndeclaredPrefix", new Object[] {qNameStr, prefix}, XMLErrorReporter.SEVERITY_ERROR);
         }
         
     } // validateQNameValue
     
     
     /*
+     * Parse QName string value into prefix and local-name pairs.
+     */
+    private static String[] parseQnameString(String qNameStr) {
+        
+        String[] parsedQName = new String[2];
+        
+        String prefix, localpart;
+        int colonptr = qNameStr.indexOf(':');
+        if (colonptr > 0) {
+            prefix = qNameStr.substring(0, colonptr);
+            localpart = qNameStr.substring(colonptr + 1);
+        } else {
+            prefix = SchemaSymbols.EMPTY_STRING;
+            localpart = qNameStr;
+        }
+        parsedQName[0] = prefix;
+        parsedQName[1] = localpart;
+        
+        return parsedQName; 
+        
+    } // parseQnameString 
+    
+    
+    /*
      * Get assertions list of a simpleType definition.
      */
     public static Vector getAssertsFromSimpleType(XSSimpleTypeDefinition simplType) {

Modified: xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.2.0.jar
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/tools/org.eclipse.wst.xml.xpath2.processor_1.2.0.jar?rev=1180333&r1=1180332&r2=1180333&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org