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 2009/11/14 08:03:30 UTC

svn commit: r836132 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: ./ alternative/ assertion/ traversers/

Author: mukulg
Date: Sat Nov 14 07:03:29 2009
New Revision: 836132

URL: http://svn.apache.org/viewvc?rev=836132&view=rev
Log:
fix for XSD namespace prefix usage, while using XSD namespace components (like, xs:string) in Schema 1.1 assert and CTA psychopath, XPath 2 expressions.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
    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/alternative/Test.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java?rev=836132&r1=836131&r2=836132&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java Sat Nov 14 07:03:29 2009
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.Map;
+
 import org.apache.xerces.xs.XSModel;
 import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
@@ -50,10 +52,11 @@
     private Document domDoc = null;
     
     protected DynamicContext initDynamicContext(XSModel schema,
-                                                Document document) {
-        fDynamicContext = new DefaultDynamicContext(schema, document);                
-        fDynamicContext.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
-        fDynamicContext.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
+                                                Document document,
+                                                Map assertParams) {
+        fDynamicContext = new DefaultDynamicContext(schema, document);
+        String xsdPrefix = (String)assertParams.get("XSD_PREFIX"); 
+        fDynamicContext.add_namespace(xsdPrefix, "http://www.w3.org/2001/XMLSchema");
         fDynamicContext.add_function_library(new FnFunctionLibrary());
         fDynamicContext.add_function_library(new XSCtrLibrary());        
         domDoc = document;

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=836132&r1=836131&r2=836132&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 Sat Nov 14 07:03:29 2009
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.Map;
 import java.util.Stack;
 import java.util.Vector;
 
@@ -79,17 +80,20 @@
     // XMLSchemaValidator reference. set from the XMLSchemaValidator object
     // itself.
     XMLSchemaValidator validator = null;
+    
+    Map assertParams = null;
 
     /*
      * The class constructor
      */
-    public XMLAssertPsychopathImpl() {
+    public XMLAssertPsychopathImpl(Map assertParams) {
         // initializing the class variables
         // we use the PSVI enabled DOM implementation, so as to have typed
         // XDM nodes.
         this.assertDocument = new PSVIDocumentImpl();
         this.assertRootStack = new Stack();
         this.assertListStack = new Stack();
+        this.assertParams = assertParams;  
     }
 
     /*
@@ -98,7 +102,7 @@
     private void initXPathProcessor() throws Exception {
         validator = (XMLSchemaValidator) getProperty("http://apache.org/xml/properties/assert/validator");        
         abstrPsychopathImpl = new AbstractPsychoPathImpl();
-        fDynamicContext = abstrPsychopathImpl.initDynamicContext(fSchema, assertDocument);
+        fDynamicContext = abstrPsychopathImpl.initDynamicContext(fSchema, assertDocument, assertParams);
         
         // assign value to variable, "value" in XPath context
         fDynamicContext.add_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(

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=836132&r1=836131&r2=836132&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 Nov 14 07:03:29 2009
@@ -18,6 +18,7 @@
 package org.apache.xerces.impl.xs;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
@@ -39,6 +40,7 @@
 import org.apache.xerces.impl.validation.ValidationState;
 import org.apache.xerces.impl.xs.alternative.Test;
 import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
 import org.apache.xerces.impl.xs.identity.Field;
 import org.apache.xerces.impl.xs.identity.FieldActivator;
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
@@ -808,14 +810,17 @@
     
     /*
      * Helper method to initialize the assertion processor
+     * 
+     * @param assertParams Parameters that are passed, to the assertions processor
      */
-    private void initializeAssertProcessor() {
+    private void initializeAssertProcessor(Map assertParams) {
         String assertProcessorProp = System
                 .getProperty("org.apache.xerces.assertProcessor");
+        
         if (assertProcessorProp == null || assertProcessorProp.equals("")) {
             // if assertion processor is not specified via a system
             // property, default to the Psychopath processor
-            fAssertionProcessor = new XMLAssertPsychopathImpl();
+            fAssertionProcessor = new XMLAssertPsychopathImpl(assertParams);
         } else {
             try {
                 Class assertClass = ClassLoader.getSystemClassLoader()
@@ -829,6 +834,7 @@
                 throw new XNIException(ex.getMessage(), ex);
             }
         }
+        
         fAssertionProcessor.setProperty("http://apache.org/xml/properties/assert/validator", this);
     }
     
@@ -2449,10 +2455,15 @@
           }
               
           if (assertions.size() > 0) {
-            assertObject = assertions;
+            assertObject = assertions;             
             // instantiate the assertions processor
             if (fAssertionProcessor == null) {
-              initializeAssertProcessor();
+              // construct parameter values for the assertion processor
+              String xsdPrefix = ((XSAssertImpl)assertions.get(0)).getXsdNamespacePrefix();
+              Map assertProcessorParams = new HashMap();
+              assertProcessorParams.put("XSD_PREFIX", xsdPrefix);
+              // initialize the assert processor
+              initializeAssertProcessor(assertProcessorParams);
             }
           }
         } else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
@@ -2465,7 +2476,12 @@
                 assertObject = facet.getAsserts();
                 // instantiate the assertions processor
                 if (fAssertionProcessor == null) {
-                   initializeAssertProcessor();
+                   // construct parameter values for the assertion processor                   
+                   String xsdPrefix = ((XSAssertImpl)facet.getAsserts().get(0)).getXsdNamespacePrefix();
+                   Map assertProcessorParams = new HashMap();
+                   assertProcessorParams.put("XSD_PREFIX", xsdPrefix);
+                   // initialize the assert processor
+                   initializeAssertProcessor(assertProcessorParams);
                 }
                 break;
               }
@@ -2479,7 +2495,8 @@
             assertAugs.putItem("ASSERT", assertObject);
             fAssertionProcessor.startElement(element, attributes, assertAugs);
          }
-    }
+         
+    } // addAssertsForEvaluation
     
 
     /**

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=836132&r1=836131&r2=836132&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 Nov 14 07:03:29 2009
@@ -17,12 +17,16 @@
 
 package org.apache.xerces.impl.xs.alternative;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.xerces.impl.xpath.XPath20;
 import org.apache.xerces.impl.xs.AbstractPsychoPathImpl;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
@@ -47,20 +51,25 @@
     
     /** XPath 2.0 expression. PsychoPath XPath 2.0 expression. */
     protected XPath fXPathPsychoPath = null;
+    
+    /** XSD document prefix. Present on <schema> element. */
+    protected String fXsdPrefix = null;
 
     /** Constructs a "test" for type alternatives */
-    public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative) {
+    public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative, String xsdPrefix) {
         fXPath = xpath;
         fTypeAlternative = typeAlternative;
+        fXsdPrefix = xsdPrefix;
     }
     
     /*
      * Constructs a "test" for type alternatives. An overloaded constructor,
      * for PsychoPath XPath processor.
      */
-    public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative) {
+    public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative, String xsdPrefix) {
        fXPathPsychoPath = xpath;
-       fTypeAlternative = typeAlternative;    
+       fTypeAlternative = typeAlternative;
+       fXsdPrefix = xsdPrefix; 
     }
 
     public XSTypeAlternativeImpl getTypeAlternative() {
@@ -100,8 +109,9 @@
     }
     
     /*
-     * Evaluate the XPath "test" expression on an XDM instance, containing the specified
-     * element and its attributes. Using PsychoPath XPath 2.0 engine for the evaluation. 
+     * Evaluate the XPath "test" expression on an XDM instance, consisting
+     * of the specified element and its attributes. Using PsychoPath XPath 2.0
+     * engine for the evaluation. 
      */
     private boolean evaluateTestWithPsychoPath(QName element, XMLAttributes attributes) {
        boolean result = false;
@@ -121,7 +131,11 @@
        
          document.appendChild(elem);
          
-         initDynamicContext(null, document);       
+        // construct parameter values for psychopath processor
+         Map psychoPathParams = new HashMap();
+         psychoPathParams.put("XSD_PREFIX", fXsdPrefix);
+         initDynamicContext(null, document, psychoPathParams);
+         
          result = evaluatePsychoPathExpr(fXPathPsychoPath,
                                 fTypeAlternative.fXPathDefaultNamespace,
                                 elem);

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=836132&r1=836131&r2=836132&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 Sat Nov 14 07:03:29 2009
@@ -34,7 +34,7 @@
     /** The type definition associated with the assertion component */
     protected XSTypeDefinition fTypeDefinition;
 
-    /** An XPath 2.0 expression that represents the 'test' attribute */
+    /** An XPath 2.0 expression that represents the assert 'test' attribute */
     protected Test fTestExpr = null;
     
     /** Optional annotations */
@@ -42,6 +42,9 @@
 
     /** Default XPath namespace */
     protected String fXPathDefaultNamespace = null;
+    
+    /** XSD namespace prefix, present on <schema> element */
+    protected String xsdNamespacePrefix = null;
 
     /** Constructor */
     public XSAssertImpl(XSTypeDefinition type,
@@ -65,6 +68,11 @@
     public void setXPathDefauleNamespace(String namespace) {
         fXPathDefaultNamespace = namespace;
     }
+    
+    /** Sets the XSD namespace, prefix */
+    public void setXsdNamespacePrefix(String nsPrefix) {
+        xsdNamespacePrefix = nsPrefix;
+    }
    
     public XSObjectList getAnnotations() {
         return fAnnotations;
@@ -114,6 +122,14 @@
         return XSConstants.ASSERTION;
     }
     
+    /**
+     * 
+     * Get the XSD namespace prefix
+     */
+    public String getXsdNamespacePrefix() {
+        return xsdNamespacePrefix;
+    }
+    
     /*
      * Tests if two assert components are equal
      */

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=836132&r1=836131&r2=836132&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java Sat Nov 14 07:03:29 2009
@@ -497,6 +497,7 @@
                                            schemaDoc.fNamespaceSupport), assertImpl);                 
                     assertImpl.setTest(testExpr);
                     assertImpl.setXPathDefauleNamespace(xpathDefaultNamespace);
+                    assertImpl.setXsdNamespacePrefix(schemaDoc.fSchemaElement.getPrefix());
                     if (assertData == null) {
                         assertData = new Vector();
                     }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=836132&r1=836131&r2=836132&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java Sat Nov 14 07:03:29 2009
@@ -1595,6 +1595,7 @@
                                       schemaDoc.fNamespaceSupport), assertImpl);
             assertImpl.setTest(testExpr);
             assertImpl.setXPathDefauleNamespace(xpathDefaultNamespace);
+            assertImpl.setXsdNamespacePrefix(schemaDoc.fSchemaElement.getPrefix());
 
             // add assertion object to an array buffer
             addAssertion(assertImpl);

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=836132&r1=836131&r2=836132&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 Sat Nov 14 07:03:29 2009
@@ -159,18 +159,21 @@
             Test testExpr = null;
             //set the test attribute value
             try {
-               testExpr = new Test(new XPath20(test, fSymbolTable, schemaDoc.fNamespaceSupport), typeAlternative);
+               testExpr = new Test(new XPath20(test, fSymbolTable, schemaDoc.fNamespaceSupport),
+                                       typeAlternative,
+                                       schemaDoc.fSchemaElement.getPrefix());
             } 
             catch (XPathException e) {
                // fall back to full XPath 2.0 support, with PsychoPath engine
                try {
                   XPathParser xpp = new JFlexCupParser();
                   XPath xp = xpp.parse("boolean(" + test + ")");
-                  testExpr = new Test(xp, typeAlternative);
+                  testExpr = new Test(xp, typeAlternative, schemaDoc.fSchemaElement.getPrefix());
                } catch(XPathParserException ex) {
                   reportSchemaError("c-cta-xpath", new Object[] { test }, altElement);
                   //if the XPath is invalid, create a Test without an expression
-                  testExpr = new Test((XPath20) null, typeAlternative);
+                  testExpr = new Test((XPath20) null, typeAlternative,
+                                       schemaDoc.fSchemaElement.getPrefix());
                }                
             }            
             typeAlternative.setTest(testExpr);



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