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/01/30 09:00:08 UTC

svn commit: r1065214 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: AbstractPsychoPathImpl.java XMLAssertPsychopathImpl.java alternative/Test.java

Author: mukulg
Date: Sun Jan 30 08:00:07 2011
New Revision: 1065214

URL: http://svn.apache.org/viewvc?rev=1065214&view=rev
Log:
making a slight improvement to schema 1.1 assertions processing code. this change fixes non compliances of these two tests from XML Schema 1.1 test suite - assert-simple003.v1.xml & assert-simple004.v1.xml. doing minor refactorings as well (like variable renaming etc).

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/alternative/Test.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=1065214&r1=1065213&r2=1065214&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 Jan 30 08:00:07 2011
@@ -59,7 +59,7 @@ import org.w3c.dom.Element;
  */
 public class AbstractPsychoPathImpl {
     
-    private DynamicContext fDynamicContext = null;
+    private DynamicContext fXpath2DynamicContext = null;
     private Document domDoc = null;
     
     
@@ -68,7 +68,7 @@ public class AbstractPsychoPathImpl {
      */
     protected DynamicContext initDynamicContext(XSModel schema, Document document, Map psychoPathParams) {
         
-        fDynamicContext = new DefaultDynamicContext(schema, document);        
+        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");
@@ -76,14 +76,14 @@ public class AbstractPsychoPathImpl {
         while (currPrefixes.hasMoreElements()) {
             String prefix = (String)currPrefixes.nextElement();
             String uri = xpath2NamespaceContext.getURI(prefix);
-            fDynamicContext.add_namespace(prefix, uri);
+            fXpath2DynamicContext.add_namespace(prefix, uri);
         }
         
-        fDynamicContext.add_function_library(new FnFunctionLibrary());
-        fDynamicContext.add_function_library(new XSCtrLibrary());        
+        fXpath2DynamicContext.add_function_library(new FnFunctionLibrary());
+        fXpath2DynamicContext.add_function_library(new XSCtrLibrary());        
         domDoc = document;
         
-        return fDynamicContext;
+        return fXpath2DynamicContext;
         
     } // initDynamicContext
     
@@ -91,26 +91,21 @@ public class AbstractPsychoPathImpl {
     /*
      * Evaluate XPath expression with PsychoPath engine.
      */
-    protected boolean evaluateXPathExpr(XPath xp, String xPathDefaultNamespace, Element contextNode)
-                                        throws StaticError, DynamicError, Exception {
+    protected boolean evaluateXPathExpr(XPath xp, Element contextNode) throws StaticError, DynamicError, Exception {
         
-        StaticChecker sc = new StaticNameResolver(fDynamicContext);
+        StaticChecker sc = new StaticNameResolver(fXpath2DynamicContext);
         sc.check(xp);
        
         Evaluator eval = null;
         if (contextNode != null) {
-           eval = new DefaultEvaluator(fDynamicContext, domDoc);           
+           eval = new DefaultEvaluator(fXpath2DynamicContext, domDoc);           
            // change focus to the top most element
            ResultSequence nodeEvalRS = ResultSequenceFactory.create_new();
-           nodeEvalRS.add(new ElementType(contextNode, fDynamicContext.node_position(contextNode)));
-           if (xPathDefaultNamespace != null) {
-             fDynamicContext.add_namespace(null, xPathDefaultNamespace);  
-           }
-           
-           fDynamicContext.set_focus(new Focus(nodeEvalRS));
+           nodeEvalRS.add(new ElementType(contextNode, fXpath2DynamicContext.node_position(contextNode)));           
+           fXpath2DynamicContext.set_focus(new Focus(nodeEvalRS));
         }
-        else {
-           eval = new DefaultEvaluator(fDynamicContext, null);   
+        else {           
+           eval = new DefaultEvaluator(fXpath2DynamicContext, null);
         }
         
         ResultSequence rs = eval.evaluate(xp);

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=1065214&r1=1065213&r2=1065214&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 Jan 30 08:00:07 2011
@@ -83,7 +83,7 @@ import org.w3c.dom.NodeList;
 public class XMLAssertPsychopathImpl extends XMLAssertAdapter {
 
     // class variable declarations
-    private DynamicContext fDynamicContext;
+    private DynamicContext fXpath2DynamicContext;
     private XSModel fSchema = null;
     private AbstractPsychoPathImpl fAbstrPsychopathImpl = null;
 
@@ -128,7 +128,7 @@ public class XMLAssertPsychopathImpl ext
     private void initXPathProcessor() throws Exception {        
         fValidator = (XMLSchemaValidator) getProperty("http://apache.org/xml/properties/assert/validator");        
         fAbstrPsychopathImpl = new AbstractPsychoPathImpl();
-        fDynamicContext = fAbstrPsychopathImpl.initDynamicContext(fSchema, fAssertDocument, fAssertParams);        
+        fXpath2DynamicContext = fAbstrPsychopathImpl.initDynamicContext(fSchema, fAssertDocument, fAssertParams);        
     } // initXPathProcessor
     
 
@@ -310,15 +310,19 @@ public class XMLAssertPsychopathImpl ext
             setTypedValueFor$value(value, null, null);
         } else {
             // complex type with complex content. set xpath context variable $value to an empty sequence.
-            fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+            fXpath2DynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                                              "value"), getXPath2ResultSequence(new ArrayList()));
         }
         
         XSObjectList assertList = (XSObjectList) assertions;
         XSObjectList attrMemberTypes = null;
         final int assertListSize = assertList.size();
-        for (int i = 0; i < assertListSize; i++) {
-            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);               
+        for (int assertIdx = 0; assertIdx < assertListSize; assertIdx++) {
+            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
+            String xPathDefaultNamespace = assertImpl.getXPathDefaultNamespace(); 
+            if (xPathDefaultNamespace != null) {
+                fXpath2DynamicContext.add_namespace(null, xPathDefaultNamespace);  
+            }
             boolean xpathContextExists = false;
             if (assertImpl.getType() == XSConstants.ASSERTION) {
                 // not an assertion facet
@@ -410,6 +414,10 @@ public class XMLAssertPsychopathImpl ext
         
         for (int assertIdx = 0; assertIdx < assertListLength; assertIdx++) {
             XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
+            String xPathDefaultNamespace = assertImpl.getXPathDefaultNamespace(); 
+            if (xPathDefaultNamespace != null) {
+                fXpath2DynamicContext.add_namespace(null, xPathDefaultNamespace);  
+            }
             if (itemType != null) {
                // evaluating assertions for "simpleType -> list". tokenize the list value by the longest sequence of white-spaces.
                StringTokenizer values = new StringTokenizer(value, " \n\t\r");
@@ -587,8 +595,7 @@ public class XMLAssertPsychopathImpl ext
     /*
      * Method to evaluate an assertion object.
      */
-    private AssertionError evaluateAssertion(QName element, XSAssertImpl assertImpl, String value,
-                                             boolean xPathContextExists, boolean isList) {
+    private AssertionError evaluateAssertion(QName element, XSAssertImpl assertImpl, String value, boolean xPathContextExists, boolean isList) {
         
         AssertionError assertionError = null;
         
@@ -598,13 +605,11 @@ public class XMLAssertPsychopathImpl ext
             boolean result;            
             if ((value == null) ||
                 (xPathContextExists == true)) {
-                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, assertImpl.getXPathDefaultNamespace(),
-                                                                     fCurrentAssertDomNode);  
+                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, fCurrentAssertDomNode);  
             } 
             else {
                 // XPath context is "undefined"
-                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, assertImpl.getXPathDefaultNamespace(),
-                                                                     null); 
+                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, null); 
             }
             
             if (!result) {
@@ -658,11 +663,9 @@ public class XMLAssertPsychopathImpl ext
               if (typeDef instanceof XSComplexTypeDefinition && ((XSComplexTypeDefinition) typeDef).getSimpleType() != null) {
                   setValueOf$ValueForCTWithSimpleContent(value, (XSComplexTypeDefinition) typeDef);
               }
-              else if (typeDef instanceof XSComplexTypeDefinition && 
-                      ((XSComplexTypeDefinition) typeDef).getSimpleType() == null) {
-                  // assign an empty XPath2 sequence to xpath context variable
-                  // $value.
-                  fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+              else if (typeDef instanceof XSComplexTypeDefinition && ((XSComplexTypeDefinition) typeDef).getSimpleType() == null) {
+                  // assign an empty XPath2 sequence to xpath context variable $value
+                  fXpath2DynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                                                    "value"), getXPath2ResultSequence(new ArrayList())); 
               }
               else {
@@ -680,7 +683,7 @@ public class XMLAssertPsychopathImpl ext
      */
     private void setValueOf$ValueForSTVarietyAtomic(String value, short xsdTypecode) {
         AnyType psychoPathType = SchemaTypeValueFactory.newSchemaTypeValue(xsdTypecode, value);
-        fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+        fXpath2DynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                                          "value"), (AnyAtomicType) psychoPathType);
     } // setValueOf$ValueForSTVarietyAtomic
 
@@ -718,13 +721,13 @@ public class XMLAssertPsychopathImpl ext
             }
 
             // assign an XPath2 sequence to xpath context variable $value
-            fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+            fXpath2DynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
                                            "value"), getXPath2ResultSequence(xdmItemList));
         }
         else if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
             // simple content type has variety xs:union
             XSSimpleTypeDefinition simpleContentTypeForUnion = getActualListItemTypeForVarietyUnion(complexTypeSimplContentType.getMemberTypes(), value);
-            fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"), 
+            fXpath2DynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"), 
                                          SchemaTypeValueFactory.newSchemaTypeValue(simpleContentTypeForUnion.getBuiltInKind(), value));
         }
         else {

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=1065214&r1=1065213&r2=1065214&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 Jan 30 08:00:07 2011
@@ -27,6 +27,7 @@ import org.apache.xerces.impl.xs.Abstrac
 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.DynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
 import org.eclipse.wst.xml.xpath2.processor.StaticError;
 import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
@@ -39,6 +40,7 @@ import org.w3c.dom.Element;
  * @xerces.internal
  * 
  * @author Hiranya Jayathilaka, University of Moratuwa
+ * @author Mukul Gandhi IBM
  * @version $Id$
  */
 public class Test extends AbstractPsychoPathImpl {
@@ -119,8 +121,8 @@ public class Test extends AbstractPsycho
        
        try {
          // construct a DOM document (used by psychopath engine as XPath XDM instance). 
-         // A PSVI DOM is constructed, to comply to PsychoPath design. This doesn't seem to 
-         // affect CTA psychopath evaluations. CTA spec, doesn't require a typed XDM tree.
+         // A PSVI DOM is constructed to comply to PsychoPath design. This doesn't seem to 
+         // affect CTA psychopath evaluations. CTA spec doesn't require a typed XDM tree.
          // REVISIT ...
          Document document = new PSVIDocumentImpl();
          
@@ -138,9 +140,11 @@ public class Test extends AbstractPsycho
          // construct parameter values for psychopath processor
          Map psychoPathParams = new HashMap();
          psychoPathParams.put("XPATH2_NS_CONTEXT", fXPath2NamespaceContext);
-         initDynamicContext(null, document, psychoPathParams);
-         
-         result = evaluateXPathExpr(fXPathPsychoPath, fTypeAlternative.fXPathDefaultNamespace, elem);
+         DynamicContext xpath2DynamicContext = initDynamicContext(null, document, psychoPathParams);
+         if (fTypeAlternative.fXPathDefaultNamespace != null) {
+             xpath2DynamicContext.add_namespace(null, fTypeAlternative.fXPathDefaultNamespace);  
+         }
+         result = evaluateXPathExpr(fXPathPsychoPath, elem);
        } 
        catch (StaticError ex) {
            result = false; 



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