Author: mukulg
Date: Sun Nov 15 07:09:58 2009
New Revision: 836333

URL: http://svn.apache.org/viewvc?rev=836333&view=rev
Log:
fixes to the namespace bindings implementation, for psychopath XPath 2 static 
context.

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/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/Constants.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java?rev=836333&r1=836332&r2=836333&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 Nov 15 07:09:58 2009
@@ -473,9 +473,6 @@
     public final static short SCHEMA_VERSION_1_0_EXTENDED = 2;
     public final static short SCHEMA_VERSION_1_1 = 4;
     
-    // XPath 2.0 constants
-    public final static String XPATH20_FN_NAMESPACE = 
"http://www.w3.org/2005/xpath-functions";;
-    
     // private
     
     /** SAX features. */

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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -17,9 +17,10 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.Enumeration;
 import java.util.Map;
 
-import org.apache.xerces.impl.Constants;
+import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.xs.XSModel;
 import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
@@ -42,10 +43,11 @@
 import org.w3c.dom.Element;
 
 /**
- * A base class, providing common services for XPath 2.0 evaluation, with 
PsychoPath.
+ * A base class, providing common services for XPath 2 evaluation,
+ * with PsychoPath XPath 2.0 engine.
  * 
  * @author Mukul Gandhi, IBM
- * @version $Id: AbstractPsychoPathImpl.java 814163 2009-09-12 13:43:19Z 
mukulg $
+ * @version $Id: AbstractPsychoPathImpl.java 836159 2009-11-14 17:47:00Z 
mukulg $
  */
 public class AbstractPsychoPathImpl {
     
@@ -55,14 +57,16 @@
     protected DynamicContext initDynamicContext(XSModel schema,
                                                 Document document,
                                                 Map psychoPathParams) {
-        fDynamicContext = new DefaultDynamicContext(schema, document);
-        String xsdPrefix = (String) psychoPathParams.get("XSD_PREFIX");
-        String xpath2FnPrefix = (String) 
psychoPathParams.get("XPATH2_FN_PREFIX");
-        fDynamicContext.add_namespace(xsdPrefix, 
"http://www.w3.org/2001/XMLSchema";);
-        // set the XPath 2.0 functions namespace binding to the XPath 2.0 
static
-        // context, if present on <schema> element.
-        if (xpath2FnPrefix != null) {
-           fDynamicContext.add_namespace(xpath2FnPrefix, 
Constants.XPATH20_FN_NAMESPACE);    
+        
+        fDynamicContext = new DefaultDynamicContext(schema, document);        
+        // populate the PsychoPath XPath 2.0 static context, with namespace 
bindings
+        // derived from the XSD Schema
+        NamespaceSupport xpath2NamespaceContext = (NamespaceSupport) 
psychoPathParams.get("XPATH2_NS_CONTEXT");
+        Enumeration currPrefixes = xpath2NamespaceContext.getAllPrefixes();
+        while (currPrefixes.hasMoreElements()) {
+            String prefix = (String)currPrefixes.nextElement();
+            String uri = xpath2NamespaceContext.getURI(prefix);
+            fDynamicContext.add_namespace(prefix, uri);
         }
         fDynamicContext.add_function_library(new FnFunctionLibrary());
         fDynamicContext.add_function_library(new XSCtrLibrary());        

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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -102,7 +102,9 @@
     private void initXPathProcessor() throws Exception {
         validator = (XMLSchemaValidator) 
getProperty("http://apache.org/xml/properties/assert/validator";);        
         abstrPsychopathImpl = new AbstractPsychoPathImpl();
-        fDynamicContext = abstrPsychopathImpl.initDynamicContext(fSchema, 
assertDocument, assertParams);
+        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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -2459,16 +2459,10 @@
             // instantiate the assertions processor
             if (fAssertionProcessor == null) {
               // construct parameter values for the assertion processor
-              String xsdPrefix = 
((XSAssertImpl)assertions.get(0)).getXsdNamespacePrefix();
-              String xpath2FnPrefix = 
((XSAssertImpl)assertions.get(0)).getXpath2FnPrefix();
               Map assertProcessorParams = new HashMap();
-              assertProcessorParams.put("XSD_PREFIX", xsdPrefix);
-              // set the XPath 2.0 functions namespace prefix, if present on
-              // <schema> element.
-              if (xpath2FnPrefix != null) {
-                assertProcessorParams.put("XPATH2_FN_PREFIX", xpath2FnPrefix); 
   
-              }
-              // initialize the assert processor
+              assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                                        
((XSAssertImpl)assertions.get(0)).getXPath2NamespaceContext());
+              // initialize the assertions processor
               initializeAssertProcessor(assertProcessorParams);
             }
           }
@@ -2483,16 +2477,10 @@
                 // instantiate the assertions processor
                 if (fAssertionProcessor == null) {
                    // construct parameter values for the assertion processor
-                   String xsdPrefix = 
((XSAssertImpl)facet.getAsserts().get(0)).getXsdNamespacePrefix();
-                   String xpath2FnPrefix = 
((XSAssertImpl)facet.getAsserts().get(0)).getXpath2FnPrefix();
                    Map assertProcessorParams = new HashMap();
-                   assertProcessorParams.put("XSD_PREFIX", xsdPrefix);
-                   // set the XPath 2.0 functions namespace prefix, if present 
on
-                   // <schema> element.
-                   if (xpath2FnPrefix != null) {
-                     assertProcessorParams.put("XPATH2_FN_PREFIX", 
xpath2FnPrefix);    
-                   }
-                   // initialize the assert processor
+                   assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                           
((XSAssertImpl)facet.getAsserts().get(0)).getXPath2NamespaceContext());
+                   // initialize the assertions processor
                    initializeAssertProcessor(assertProcessorParams);
                 }
                 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=836333&r1=836332&r2=836333&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 Nov 15 07:09:58 2009
@@ -26,7 +26,7 @@
 
 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.util.NamespaceSupport;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
@@ -51,25 +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;
+        
+    /** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD 
traversers. */
+    protected NamespaceSupport fXPath2NamespaceContext = null;
 
     /** Constructs a "test" for type alternatives */
-    public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative, String 
xsdPrefix) {
+    public Test(XPath20 xpath, XSTypeAlternativeImpl typeAlternative, 
NamespaceSupport namespaceContext) {
         fXPath = xpath;
         fTypeAlternative = typeAlternative;
-        fXsdPrefix = xsdPrefix;
+        fXPath2NamespaceContext = namespaceContext;
     }
     
     /*
      * Constructs a "test" for type alternatives. An overloaded constructor,
      * for PsychoPath XPath processor.
      */
-    public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative, String 
xsdPrefix) {
+    public Test(XPath xpath, XSTypeAlternativeImpl typeAlternative, 
NamespaceSupport namespaceContext) {
        fXPathPsychoPath = xpath;
        fTypeAlternative = typeAlternative;
-       fXsdPrefix = xsdPrefix; 
+       fXPath2NamespaceContext = namespaceContext;
     }
 
     public XSTypeAlternativeImpl getTypeAlternative() {
@@ -131,9 +131,9 @@
        
          document.appendChild(elem);
          
-        // construct parameter values for psychopath processor
+         // construct parameter values for psychopath processor
          Map psychoPathParams = new HashMap();
-         psychoPathParams.put("XSD_PREFIX", fXsdPrefix);
+         psychoPathParams.put("XPATH2_NS_CONTEXT", fXPath2NamespaceContext);
          initDynamicContext(null, document, psychoPathParams);
          
          result = evaluatePsychoPathExpr(fXPathPsychoPath,

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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs.assertion;
 
+import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.xs.XSAssert;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSNamespaceItem;
@@ -24,7 +25,7 @@
 import org.apache.xerces.xs.XSTypeDefinition;
 
 /**
- * XML Schema 1.1 'assertion' component
+ * XML Schema 1.1 'assertion' component.
  * 
  * @author Mukul Gandhi, IBM
  * @version $Id$
@@ -42,12 +43,9 @@
 
     /** Default XPath namespace */
     protected String fXPathDefaultNamespace = null;
-    
-    /** XSD namespace prefix, present on <schema> element */
-    protected String fXsdNamespacePrefix = null;
-    
-    /** XPath 2.0 functions namespace prefix, present on <schema> element */
-    protected String fXpath2FnPrefix = null;
+      
+    /** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD 
traversers. */
+    protected NamespaceSupport fXPath2NamespaceContext = null;
 
     /** Constructor */
     public XSAssertImpl(XSTypeDefinition type,
@@ -68,18 +66,13 @@
     }
 
     /** Sets the xpath default namespace */
-    public void setXPathDefauleNamespace(String namespace) {
+    public void setXPathDefaultNamespace(String namespace) {
         fXPathDefaultNamespace = namespace;
     }
-    
-    /** Sets the XSD namespace, prefix */
-    public void setXsdNamespacePrefix(String nsPrefix) {
-        fXsdNamespacePrefix = nsPrefix;
-    }
-    
-    /** Sets the XPath 2.0 functions namespace, prefix */
-    public void setXpath2FnPrefix(String nsPrefix) {
-        fXpath2FnPrefix = nsPrefix;
+      
+    /** Sets the XPath 2.0 namespace context */
+    public void setXPath2NamespaceContext(NamespaceSupport namespaceContext) {
+        fXPath2NamespaceContext = namespaceContext;       
     }
    
     public XSObjectList getAnnotations() {
@@ -129,21 +122,12 @@
     public short getType() {
         return XSConstants.ASSERTION;
     }
-    
-    /**
-     * 
-     * Get the XSD namespace prefix
-     */
-    public String getXsdNamespacePrefix() {
-        return fXsdNamespacePrefix;
-    }
-    
+       
     /**
-     * 
-     * Get the XPath 2.0 functions prefix
+     * Get the XPath 2.0 namespace context
      */
-    public String getXpath2FnPrefix() {
-        return fXpath2FnPrefix;
+    public NamespaceSupport getXPath2NamespaceContext() {
+        return fXPath2NamespaceContext;
     }
     
     /*

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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -492,20 +492,18 @@
                         annotations = XSObjectListImpl.EMPTY_LIST;
                     }
                     
+                    // create an assertion object
                     XSAssertImpl assertImpl = new XSAssertImpl(typeDef, 
annotations);
                     Test testExpr = new Test(new XPath20Assert(test, 
fSymbolTable, 
                                            schemaDoc.fNamespaceSupport), 
assertImpl);                 
                     assertImpl.setTest(testExpr);
-                    assertImpl.setXPathDefauleNamespace(xpathDefaultNamespace);
-                    
assertImpl.setXsdNamespacePrefix(schemaDoc.fSchemaElement.getPrefix());
-                    String xpath2FnPrefix = 
schemaDoc.fNamespaceSupport.getPrefix(Constants.XPATH20_FN_NAMESPACE);
-                    if (xpath2FnPrefix != null) {
-                       assertImpl.setXpath2FnPrefix(xpath2FnPrefix);
-                    }
+                    assertImpl.setXPathDefaultNamespace(xpathDefaultNamespace);
+                    
assertImpl.setXPath2NamespaceContext(schemaDoc.fNamespaceSupport);
                     
                     if (assertData == null) {
                        assertData = new Vector();
-                    }
+                    }                    
+                    // add assertion object, to the list of assertions to be 
processed
                     assertData.addElement(assertImpl);
                 } else {
                     // 'test' attribute is mandatory in assert element

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=836333&r1=836332&r2=836333&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
 Sun Nov 15 07:09:58 2009
@@ -1589,18 +1589,16 @@
                 // if no annotations are present add an empty list to the 
assertion
                 annotations = XSObjectListImpl.EMPTY_LIST;
             }
-
+            
+            // create an assertion object
             XSAssertImpl assertImpl = new XSAssertImpl(enclosingCT, 
annotations);
             Test testExpr = new Test(new XPath20Assert(test, fSymbolTable,
                                       schemaDoc.fNamespaceSupport), 
assertImpl);
             assertImpl.setTest(testExpr);
-            assertImpl.setXPathDefauleNamespace(xpathDefaultNamespace);
-            
assertImpl.setXsdNamespacePrefix(schemaDoc.fSchemaElement.getPrefix());
-            String xpath2FnPrefix = 
schemaDoc.fNamespaceSupport.getPrefix(Constants.XPATH20_FN_NAMESPACE);
-            if (xpath2FnPrefix != null) {
-               assertImpl.setXpath2FnPrefix(xpath2FnPrefix);
-            }
-            // add assertion object to an array buffer
+            assertImpl.setXPathDefaultNamespace(xpathDefaultNamespace);
+            assertImpl.setXPath2NamespaceContext(schemaDoc.fNamespaceSupport);
+            
+            // add assertion object, to the list of assertions to be processed
             addAssertion(assertImpl);
 
             Element sibling = DOMUtil.getNextSiblingElement(assertElement);

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=836333&r1=836332&r2=836333&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 Nov 15 07:09:58 2009
@@ -161,19 +161,19 @@
             try {
                testExpr = new Test(new XPath20(test, fSymbolTable, 
schemaDoc.fNamespaceSupport),
                                        typeAlternative,
-                                       schemaDoc.fSchemaElement.getPrefix());
+                                       schemaDoc.fNamespaceSupport);
             } 
             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, 
schemaDoc.fSchemaElement.getPrefix());
+                  testExpr = new Test(xp, typeAlternative, 
schemaDoc.fNamespaceSupport);
                } 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,
-                                       schemaDoc.fSchemaElement.getPrefix());
+                                       schemaDoc.fNamespaceSupport);
                }                
             }            
             typeAlternative.setTest(testExpr);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to