Author: chinthaka
Date: Thu Sep 14 01:58:33 2006
New Revision: 443289

URL: http://svn.apache.org/viewvc?view=rev&rev=443289
Log:
- More improvements to default namespaces handling. There was a little catch in 
my earlier implementation. This was revealed when I was fixing 
http://issues.apache.org/jira/browse/WSCOMMONS-79
-Minor improvement to OMNavigator to get namespaces of attributes

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java?view=diff&rev=443289&r1=443288&r2=443289
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/xpath/DocumentNavigator.java
 Thu Sep 14 01:58:33 2006
@@ -1,24 +1,10 @@
 package org.apache.axiom.om.xpath;
 
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMComment;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMDocument;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMProcessingInstruction;
-import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
-import org.jaxen.BaseXPath;
-import org.jaxen.DefaultNavigator;
-import org.jaxen.FunctionCallException;
-import org.jaxen.JaxenConstants;
-import org.jaxen.UnsupportedAxisException;
-import org.jaxen.XPath;
+import org.jaxen.*;
 import org.jaxen.saxpath.SAXPathException;
 import org.jaxen.util.SingleObjectIterator;
 
@@ -364,7 +350,10 @@
             for (Iterator iter = element.getAllAttributes();
                  iter != null && iter.hasNext();) {
                 OMAttribute attr = (OMAttribute) iter.next();
-                declaredNS.add(attr.getNamespace());
+                OMNamespace namespace = attr.getNamespace();
+                if (namespace != null) {
+                    declaredNS.add(namespace);
+                }
             }
             for (Iterator iter = declaredNS.iterator();
                  iter != null && iter.hasNext();) {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?view=diff&rev=443289&r1=443288&r2=443289
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 Thu Sep 14 01:58:33 2006
@@ -49,7 +49,7 @@
     /**
      * Field ns
      */
-    protected OMNamespace ns = DEFAULT_DEFAULT_NS_OBJECT;
+    protected OMNamespace ns;
 
     /**
      * Field localName
@@ -862,7 +862,19 @@
      * @throws OMException
      */
     public OMNamespace getNamespace() throws OMException {
-        return ns != null ? ns : DEFAULT_DEFAULT_NS_OBJECT;
+//        return ns != null ? ns : DEFAULT_DEFAULT_NS_OBJECT;
+        if (ns == null) {
+            // User wants to keep this element in the default default 
namespace. Let's try to see the default namespace
+            // is overriden by some one up in the tree
+            OMNamespace parentDefaultNS = this.findNamespaceURI("");
+
+            if(parentDefaultNS != null && 
!"".equals(parentDefaultNS.getNamespaceURI())){
+                // if it was overriden, then we must explicitly declare 
default default namespace as the namespace
+                // of this element
+                ns = DEFAULT_DEFAULT_NS_OBJECT;
+            }
+        }
+        return ns;
     }
 
     /**

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java?view=diff&rev=443289&r1=443288&r2=443289
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java
 Thu Sep 14 01:58:33 2006
@@ -65,17 +65,7 @@
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jaxen.BaseXPath;
-import org.jaxen.Context;
-import org.jaxen.ContextSupport;
-import org.jaxen.FunctionCallException;
-import org.jaxen.JaxenException;
-import org.jaxen.Navigator;
-import org.jaxen.SimpleNamespaceContext;
-import org.jaxen.SimpleVariableContext;
-import org.jaxen.UnsupportedAxisException;
-import org.jaxen.XPath;
-import org.jaxen.XPathFunctionContext;
+import org.jaxen.*;
 import org.jaxen.function.StringFunction;
 import org.jaxen.pattern.Pattern;
 import org.jaxen.saxpath.helpers.XPathReaderFactory;
@@ -255,7 +245,7 @@
                 assertEquals("Node type mismatch", Pattern.NAMESPACE_NODE, 
nav.getNodeType(o));
             }
         }
-        assertEquals(34, count);
+        assertEquals(25, count);
     }
 
 
@@ -1715,60 +1705,60 @@
         }
     }
 
-//    public void testid55739() throws JaxenException
-//    {
-//        Navigator nav = getNavigator();
-//        String url = TESTS_ROOT + "xml/testNamespaces.xml";
-//        log("Document [" + url + "]");
-//        Object document = nav.getDocument(url);
-//        XPath contextpath = new BaseXPath("/", nav);
-//        log("Initial Context :: " + contextpath);
-//        List list = contextpath.selectNodes(document);
-//        Iterator iter = list.iterator();
-//        while (iter.hasNext())
-//        {
-//            Object context = iter.next();
-//            /* the root is not an element, so no namespaces
-//            */
-//            assertCountXPath(0, context, "namespace::*");
-//            assertCountXPath(0, context, "/namespace::*");
-//            /* must count the default xml: prefix as well
-//            */
-//            assertCountXPath(3, context, 
"/Template/Application1/namespace::*");
-//            assertCountXPath(3, context, 
"/Template/Application2/namespace::*");
-//            /* every element has separate copies
-//            */
-//            assertCountXPath(25, context, "//namespace::*");
-//        }
-//    }
-
-//    public void testid55797() throws JaxenException
-//    {
-//        Navigator nav = getNavigator();
-//        String url = TESTS_ROOT + "xml/testNamespaces.xml";
-//        log("Document [" + url + "]");
-//        Object document = nav.getDocument(url);
-//        XPath contextpath = new BaseXPath("/Template/Application1", nav);
-//        log("Initial Context :: " + contextpath);
-//        List list = contextpath.selectNodes(document);
-//        Iterator iter = list.iterator();
-//        while (iter.hasNext())
-//        {
-//            Object context = iter.next();
-//            /* must count the default xml: prefix as well
-//            */
-//            assertCountXPath(3, context, "namespace::*");
-//            assertCountXPath(0, context, "/namespace::*");
-//            assertCountXPath(3, context, 
"/Template/Application1/namespace::*");
-//            assertCountXPath(3, context, 
"/Template/Application2/namespace::*");
-//            assertCountXPath(25, context, "//namespace::*");
-//            assertCountXPath(8, context, "//namespace::xplt");
-//            /* the name test literally matches the prefix as given in the
-//              document, and does not use the uri
-//            */
-//            assertCountXPath(0, context, "//namespace::somethingelse");
-//        }
-//    }
+    public void testid55739() throws JaxenException
+    {
+        Navigator nav = getNavigator();
+        String url = TESTS_ROOT + "xml/testNamespaces.xml";
+        log("Document [" + url + "]");
+        Object document = nav.getDocument(url);
+        XPath contextpath = new BaseXPath("/", nav);
+        log("Initial Context :: " + contextpath);
+        List list = contextpath.selectNodes(document);
+        Iterator iter = list.iterator();
+        while (iter.hasNext())
+        {
+            Object context = iter.next();
+            /* the root is not an element, so no namespaces
+            */
+            assertCountXPath(0, context, "namespace::*");
+            assertCountXPath(0, context, "/namespace::*");
+            /* must count the default xml: prefix as well
+            */
+            assertCountXPath(3, context, 
"/Template/Application1/namespace::*");
+            assertCountXPath(3, context, 
"/Template/Application2/namespace::*");
+            /* every element has separate copies
+            */
+            assertCountXPath(25, context, "//namespace::*");
+        }
+    }
+
+    public void testid55797() throws JaxenException
+    {
+        Navigator nav = getNavigator();
+        String url = TESTS_ROOT + "xml/testNamespaces.xml";
+        log("Document [" + url + "]");
+        Object document = nav.getDocument(url);
+        XPath contextpath = new BaseXPath("/Template/Application1", nav);
+        log("Initial Context :: " + contextpath);
+        List list = contextpath.selectNodes(document);
+        Iterator iter = list.iterator();
+        while (iter.hasNext())
+        {
+            Object context = iter.next();
+            /* must count the default xml: prefix as well
+            */
+            assertCountXPath(3, context, "namespace::*");
+            assertCountXPath(0, context, "/namespace::*");
+            assertCountXPath(3, context, 
"/Template/Application1/namespace::*");
+            assertCountXPath(3, context, 
"/Template/Application2/namespace::*");
+            assertCountXPath(25, context, "//namespace::*");
+            assertCountXPath(8, context, "//namespace::xplt");
+            /* the name test literally matches the prefix as given in the
+              document, and does not use the uri
+            */
+            assertCountXPath(0, context, "//namespace::somethingelse");
+        }
+    }
 
     public void testid55873() throws JaxenException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to