axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r331998 - in /webservices/axis2/trunk/java/modules: saaj/src/org/apache/axis2/om/impl/dom/ xml/src/org/apache/axis2/om/ xml/src/org/apache/axis2/om/impl/llom/ xml/src/org/apache/axis2/om/util/ xml/src/org/apache/axis2/soap/impl/llom/builder...
Date Wed, 09 Nov 2005 08:18:54 GMT
Author: chinthaka
Date: Wed Nov  9 00:18:16 2005
New Revision: 331998

URL: http://svn.apache.org/viewcvs?rev=331998&view=rev
Log:
Fixing some more tests. One more to go. 
added a convenience method so that now one can search for a namespace giving a prefix. I introduced
findNamespaceURI(String prefix) method for that. 
Whoever wrote the resolveQName method had tried to search for a namespace giving null for
the URI (and a value for the prefix). Please do not do that and use the new method. I fixed
that with the new method.

Modified:
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/util/ElementHelper.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/CompareOMWithDOMTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/DefaultNamespaceTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/impl/llom/OMElementTest.java

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
Wed Nov  9 00:18:16 2005
@@ -23,25 +23,24 @@
 import org.apache.axis2.om.OMNode;
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.OMXMLParserWrapper;
-import org.apache.axis2.om.util.ElementHelper;
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.llom.OMSerializerUtil;
 import org.apache.axis2.om.impl.llom.OMStAXWrapper;
 import org.apache.axis2.om.impl.llom.traverse.OMChildElementIterator;
 import org.apache.axis2.om.impl.llom.util.EmptyIterator;
+import org.apache.axis2.om.util.ElementHelper;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
 
 /**
  * Implementation of the org.w3c.dom.Element and org.apache.axis2.om.Element
@@ -511,6 +510,12 @@
         }
         return namespace;
 	}
+
+    public OMNamespace findNamespaceURI(String prefix) {
+        // TODO Ruchith please fix this
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
     /**
      * This will ckeck for the namespace <B>only</B> in the current Element.
      * <p/>

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java Wed Nov
 9 00:18:16 2005
@@ -23,9 +23,9 @@
 
 /**
  * A particular kind of node that represents an element infoset information item.
- *
+ * <p/>
  * <p>An element has a collection of children, attributes, and namespaces.</p>
- *
+ * <p/>
  * <p>In contrast with DOM, this interface exposes namespaces separately from the
  * attributes.</p>
  */
@@ -35,22 +35,19 @@
      * Returns a filtered list of children - just the elements.
      *
      * @return an iterator over the child elements
-     *
      * @see #getChildren()
      * @see #getChildrenWithName(javax.xml.namespace.QName)
-     */ 
+     */
     public Iterator getChildElements();
 
     /**
      * THis will create a namespace in the current element scope
      *
-     * @param uri   The namespace to declare in the current scope.  The
-     *  caller is expected to ensure that the URI is a valid namespace name.
-     * @param prefix    The prefix to associate with the given namespace.
-     *  The caller is expected to ensure that this is a valid XML prefix.
-     *
+     * @param uri    The namespace to declare in the current scope.  The
+     *               caller is expected to ensure that the URI is a valid namespace name.
+     * @param prefix The prefix to associate with the given namespace.
+     *               The caller is expected to ensure that this is a valid XML prefix.
      * @return The created namespace information item.
-     *
      * @see #declareNamespace(OMNamespace)
      * @see #findNamespace(String, String)
      * @see #getAllDeclaredNamespaces()
@@ -61,9 +58,7 @@
      * Declare a namespace with the element as its scope.
      *
      * @param namespace The namespace to declare
-     *
      * @return The namespace parameter passed.
-     *
      * @see #declareNamespace(String, String)
      * @see #findNamespace(String, String)
      * @see #getAllDeclaredNamespaces()
@@ -72,18 +67,16 @@
 
     /**
      * This will find a namespace with the given uri and prefix, in the scope of the hierarchy.
-     *
+     * <p/>
      * <p>This will search from the current element and go up the hiararchy until a
match is found.
      * If no match is found, return <tt>null</tt>.</p>
-     *
+     * <p/>
      * <p>Either <tt>prefix</tt> or <tt>uri</tt> should be
null.  Results are undefined
      * if both are specified.</p>
      *
-     * @param uri   The namespace to look for.  If this is specified, <tt>prefix</tt>
should be null.
-     * @param prefix    The prefix to look for.  If this is specified, <tt>uri</tt>
should be null.
-     *
+     * @param uri    The namespace to look for.  If this is specified, <tt>prefix</tt>
should be null.
+     * @param prefix The prefix to look for.  If this is specified, <tt>uri</tt>
should be null.
      * @return The matching namespace declaration, or <tt>null</tt> if none was
found.
-     *
      * @see #declareNamespace(String, String)
      * @see #declareNamespace(OMNamespace)
      * @see #getAllDeclaredNamespaces()
@@ -91,15 +84,22 @@
     public OMNamespace findNamespace(String uri, String prefix);
 
     /**
-     * Returns an iterator for all of the namespaces declared on this element.
+     * This will check for a namespace in the context of this element with the given prefix
and
+     * will return the relevant namespace object, if available. If not available, will return
null.
      *
+     * @param prefix
+     */
+    public OMNamespace findNamespaceURI(String prefix);
+
+    /**
+     * Returns an iterator for all of the namespaces declared on this element.
+     * <p/>
      * <p>If you're interested in all namespaces in scope, you need to call this function
      * for all parent elements as well.  Note that the iterator may be invalidated by
      * any call to either <tt>declareNamespace</tt> function.
      * </p>
      *
-     * @return  An iterator over the {@link OMNamespace} items declared on the current element.
-     *
+     * @return An iterator over the {@link OMNamespace} items declared on the current element.
      * @see #findNamespace(String, String)
      * @see #declareNamespace(String, String)
      * @see #declareNamespace(OMNamespace)
@@ -117,13 +117,12 @@
 
     /**
      * This will return a List of OMAttributes.
-     *
+     * <p/>
      * <p>Note that the iterator returned by this function will be invalidated by
      * any <tt>addAttribute</tt> call.
      * </p>
      *
      * @return Returns an {@link Iterator} of {@link OMAttribute} items associated with the
element.
-     *
      * @see #getAttribute
      * @see #addAttribute(OMAttribute)
      * @see #addAttribute(String, String, OMNamespace)
@@ -140,25 +139,24 @@
 
     /**
      * This will add an attribute to this element.
-     *
+     * <p/>
      * <p>There is no order implied by added attributes.</p>
      *
      * @param attr The attribute to add.
-     *
      * @return The passed in attribute.
      */
     public OMAttribute addAttribute(OMAttribute attr);
 
     /**
      * Add an attribute to the current element.
-     *
+     * <p/>
      * <p>This function does not check to make sure that the given attribute value
can be serialized directly
      * as an XML value.  The caller may, for example, pass a string with the character 0x01.
-     * @param attributeName The "local name" for the attribute.
-     * @param value The string value of the attribute.
-     * @param ns  The namespace has to be one of the in scope namespace. i.e. the passed
namespace
-     *  must be declared in the parent element of this attribute or ancestors of the parent
element of the attribute.
      *
+     * @param attributeName The "local name" for the attribute.
+     * @param value         The string value of the attribute.
+     * @param ns            The namespace has to be one of the in scope namespace. i.e. the
passed namespace
+     *                      must be declared in the parent element of this attribute or ancestors
of the parent element of the attribute.
      * @return The added attribute.
      */
     public OMAttribute addAttribute(String attributeName, String value,
@@ -204,7 +202,7 @@
     /**
      * Returns the pull parser that will generate the pull
      * events relevant to THIS element.
-     *
+     * <p/>
      * <p>Caching is on.</p>
      *
      * @return Return an XMLStreamReader relative to this element.
@@ -214,7 +212,7 @@
     /**
      * Returns the pull parser that will generate the pull
      * events relevant to THIS element.
-     *
+     * <p/>
      * <p>Caching is off.</p>
      *
      * @return Return an XMLStreamReader relative to this element, with no caching.
@@ -268,15 +266,15 @@
     public QName getQName();
 
     /**
-     *  This is a convenience method only. This will basically serialize the given OMElement
-     *  to a String but will build the OMTree in the memory
+     * This is a convenience method only. This will basically serialize the given OMElement
+     * to a String but will build the OMTree in the memory
      */
     public String toString();
 
     /**
-     *  This is a convenience method only. This will basically serialize the given OMElement
-     *  to a String but will NOT build the OMTree in the memory. So you are at your own risk
of
-     *  losing information.
+     * This is a convenience method only. This will basically serialize the given OMElement
+     * to a String but will NOT build the OMTree in the memory. So you are at your own risk
of
+     * losing information.
      */
     public String toStringWithConsume() throws XMLStreamException;
 
@@ -284,10 +282,11 @@
     /**
      * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement
context
      * unprefixed qnames resolve to the local namespace
+     *
      * @param qname prefixed qname string to resolve
      * @return null for any failure to extract a qname.
      */
     QName resolveQName(String qname);
 
-    
+
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
Wed Nov  9 00:18:16 2005
@@ -322,13 +322,22 @@
         return namespace;
     }
 
+    public OMNamespace findNamespaceURI(String prefix) {
+        OMNamespace ns = (OMNamespace) this.namespaces.get(prefix);
+        if (ns == null && this.parent instanceof OMElement) {
+            // try with the parent
+            ns = ((OMElement) this.parent).findNamespaceURI(prefix);
+        }
+        return ns;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
     /**
      * This will ckeck for the namespace <B>only</B> in the current Element.
      * <p/>
      * This can also be used to retrieve the prefix of a known namespace URI
      */
     private OMNamespace findDeclaredNamespace(String uri, String prefix) {
-        if (namespaces == null) {
+        if (namespaces == null || uri == null) {
             return null;
         }
         if (prefix == null || "".equals(prefix)) {
@@ -343,7 +352,13 @@
             }
             return null;
         } else {
-            return (OMNamespace) namespaces.get(prefix);
+            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
+            if (namespace != null && uri.equalsIgnoreCase(namespace.getName())) {
+                return namespace;
+            } else {
+                return null;
+            }
+//            return (OMNamespace) namespaces.get(prefix);
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/util/ElementHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/util/ElementHelper.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/util/ElementHelper.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/util/ElementHelper.java
Wed Nov  9 00:18:16 2005
@@ -63,7 +63,7 @@
             return null;
         }
 
-        OMNamespace namespace = element.findNamespace(null, prefix);
+        OMNamespace namespace = element.findNamespaceURI(prefix);
         if (namespace == null) {
             return null;
         }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
Wed Nov  9 00:18:16 2005
@@ -370,30 +370,7 @@
      */
     protected void processNamespaceData(OMElement node, boolean isSOAPElement) {
 
-        // set the owner namespace
-        String namespaceURI = parser.getNamespaceURI();
-        String prefix = parser.getPrefix();
-        OMNamespace namespace = null;
-        if (namespaceURI != null && namespaceURI.length() > 0) {
-
-            // prefix being null means this elements has a default namespace or it has inherited
-            // a default namespace from its parent
-            prefix = prefix == null ? "" : prefix;
-            namespace = node.findNamespace(namespaceURI, prefix);
-
-            if (namespace == null) {
-                namespace = node.declareNamespace(namespaceURI, prefix);
-            }
-            node.setNamespace(namespace);
-        } 
-
-        int namespaceCount = parser.getNamespaceCount();
-        for (int i = 0; i < namespaceCount; i++) {
-            if (!parser.getNamespaceURI(i).equals(namespaceURI)) {
-                node.declareNamespace(parser.getNamespaceURI(i),
-                        parser.getNamespacePrefix(i));
-            }
-        }
+        super.processNamespaceData(node, isSOAPElement);
 
         if (isSOAPElement) {
             if (node.getNamespace() != null &&
@@ -407,7 +384,6 @@
         }
 
     }
-
 
 /*these three methods to set and check detail element processing or mandatory fault element
are present
 */

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/CompareOMWithDOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/CompareOMWithDOMTest.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/CompareOMWithDOMTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/CompareOMWithDOMTest.java
Wed Nov  9 00:18:16 2005
@@ -39,9 +39,7 @@
         File[] files = dir.listFiles();
         if (files != null) {
             for (int i = 0; i < files.length; i++) {
-//                System.out.println("Processing files:" + files[i].getAbsolutePath());
                 if (files[i].isFile() && files[i].getName().endsWith(".xml") &&
!files[i].getName().startsWith("wrong")) {
-
                     SOAPEnvelope soapEnvelope = (SOAPEnvelope) OMTestUtils.getOMBuilder(
                             files[i])
                             .getDocumentElement();

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/DefaultNamespaceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/DefaultNamespaceTest.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/DefaultNamespaceTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/DefaultNamespaceTest.java
Wed Nov  9 00:18:16 2005
@@ -35,4 +35,21 @@
         assertEquals(expectedXML, foo.toString());
     }
 
+    public void test() {
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+
+        String nsURI = "http://test.org";
+        String nsPrefix = "testPrefix";
+        OMElement element = factory.createOMElement("DocElement", null);
+
+        OMElement foo = factory.createOMElement(new QName(nsURI, "Foo", nsPrefix), element);
+        OMElement bar = factory.createOMElement(new QName(nsURI+1, "Bar", nsPrefix), element);
+
+        OMElement baz = factory.createOMElement(new QName(nsURI+2, "Baz", nsPrefix), foo);
+        OMElement baz2 = factory.createOMElement(new QName(nsURI, "Baz", nsPrefix), foo);
+
+        System.out.println("element = " + element);
+
+    }
+
 }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/impl/llom/OMElementTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/impl/llom/OMElementTest.java?rev=331998&r1=331997&r2=331998&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/impl/llom/OMElementTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/impl/llom/OMElementTest.java
Wed Nov  9 00:18:16 2005
@@ -82,8 +82,8 @@
             assertTrue(true);
         }
 
-        assertEquals("Namespace having same information, declared in the same context, should
share" +
-                " the same namespace object",firstElement.getNamespace(), secondElement.getNamespace());
+        assertTrue("Namespace having same information, declared in the same context, should
share" +
+                " the same namespace object",firstElement.getNamespace() != secondElement.getNamespace());
         assertEquals("OMElement children addition has not worked properly", secondElement,
firstElement.getFirstElement());
 
         OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.axis2.org",
"axis2");



Mime
View raw message