ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1382677 - in /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom: AttrImpl.java DocumentFragmentImpl.java DocumentImpl.java ElementImpl.java LeafNode.java NodeImpl.java
Date Mon, 10 Sep 2012 07:58:19 GMT
Author: veithen
Date: Mon Sep 10 07:58:19 2012
New Revision: 1382677

URL: http://svn.apache.org/viewvc?rev=1382677&view=rev
Log:
AXIOM-423: Refactored the lookupNamespaceURI code to make it more object oriented.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Mon Sep 10 07:58:19 2012
@@ -492,4 +492,9 @@ public class AttrImpl extends RootNode i
     public final Node getNextSibling() {
         return null;
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        Element ownerElement = getOwnerElement();
+        return ownerElement == null ? null : ownerElement.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
Mon Sep 10 07:58:19 2012
@@ -121,4 +121,8 @@ public class DocumentFragmentImpl extend
     public void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        return null;
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Mon Sep 10 07:58:19 2012
@@ -622,4 +622,10 @@ public class DocumentImpl extends RootNo
     public final void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        Element documentElement = getDocumentElement();
+        return documentElement == null ? null
+                : documentElement.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Mon Sep 10 07:58:19 2012
@@ -44,6 +44,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -1198,4 +1199,41 @@ public class ElementImpl extends ParentN
     public final void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        String namespace = this.getNamespaceURI();
+        String prefix = this.getPrefix();
+        // First check for namespaces implicitly defined by the namespace prefix/URI of the
element
+        // TODO: although the namespace != null condition conforms to the specs, it is likely
incorrect; see XERCESJ-1586
+        if (namespace != null
+                && (prefix == null && specifiedPrefix == null
+                        || prefix != null && prefix.equals(specifiedPrefix))) {
+            return namespace;
+        }
+        // looking in attributes
+        if (this.hasAttributes()) {
+            NamedNodeMap map = this.getAttributes();
+            int length = map.getLength();
+            for (int i = 0; i < length; i++) {
+                Node attr = map.item(i);
+                namespace = attr.getNamespaceURI();
+                if (namespace != null && namespace.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
{
+                    // At this point we know that either the prefix of the attribute is null
and
+                    // the local name is "xmlns" or the prefix is "xmlns" and the local name
is the
+                    // namespace prefix declared by the namespace declaration. We check that
constraint
+                    // when the attribute is created.
+                    String attrPrefix = attr.getPrefix();
+                    if ((specifiedPrefix == null && attrPrefix == null)
+                            || (specifiedPrefix != null && attrPrefix != null
+                                    && attr.getLocalName().equals(specifiedPrefix)))
{
+                        String value = attr.getNodeValue();
+                        return value.length() > 0 ? value : null;
+                    }
+                }
+            }
+        }
+        // looking in ancestor
+        ParentNode parent = parentNode();
+        return parent == null || parent instanceof Document ? null : parent.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
Mon Sep 10 07:58:19 2012
@@ -27,6 +27,7 @@ import org.apache.axiom.om.impl.common.I
 import org.apache.axiom.om.impl.common.IParentNode;
 import org.apache.axiom.om.impl.common.OMNodeHelper;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
@@ -133,4 +134,12 @@ public abstract class LeafNode extends N
     public final IParentNode getIParentNode() {
         return parentNode();
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        ParentNode parent = parentNode();
+        // Note: according to the DOM specs, we need to delegate the lookup if the parent
+        // is an element or an entity reference. However, since we don't support entity
+        // references fully, we only check for elements.
+        return parent instanceof Element ? parent.lookupNamespaceURI(specifiedPrefix) : null;
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1382677&r1=1382676&r2=1382677&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
Mon Sep 10 07:58:19 2012
@@ -34,17 +34,14 @@ import org.apache.axiom.om.util.StAXUtil
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.UserDataHandler;
-import org.w3c.dom.Attr;
 
 import java.io.OutputStream;
 import java.io.Writer;
 import java.util.Hashtable;
 
-import javax.xml.XMLConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -247,81 +244,6 @@ public abstract class NodeImpl implement
     }
 
     /**
-     * Returns the namespace for a given prefix <br/>
-     * The prefix can be of an Attribute's or an Element's.
-     */
-    public String lookupNamespaceURI(String specifiedPrefix) {
-        short type = this.getNodeType();
-        switch (type) {
-        case Node.ELEMENT_NODE: {
-
-            String namespace = this.getNamespaceURI();
-            String prefix = this.getPrefix();
-            // First check for namespaces implicitly defined by the namespace prefix/URI
of the element
-            // TODO: although the namespace != null condition conforms to the specs, it is
likely incorrect; see XERCESJ-1586
-            if (namespace != null
-                    && (prefix == null && specifiedPrefix == null
-                            || prefix != null && prefix.equals(specifiedPrefix)))
{
-                return namespace;
-            }
-            // looking in attributes
-            if (this.hasAttributes()) {
-                NamedNodeMap map = this.getAttributes();
-                int length = map.getLength();
-                for (int i = 0; i < length; i++) {
-                    Node attr = map.item(i);
-                    namespace = attr.getNamespaceURI();
-                    if (namespace != null && namespace.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
{
-                        // At this point we know that either the prefix of the attribute
is null and
-                        // the local name is "xmlns" or the prefix is "xmlns" and the local
name is the
-                        // namespace prefix declared by the namespace declaration. We check
that constraint
-                        // when the attribute is created.
-                        String attrPrefix = attr.getPrefix();
-                        if ((specifiedPrefix == null && attrPrefix == null)
-                                || (specifiedPrefix != null && attrPrefix != null
-                                        && attr.getLocalName().equals(specifiedPrefix)))
{
-                            String value = attr.getNodeValue();
-                            return value.length() > 0 ? value : null;
-                        }
-                    }
-                }
-            }
-            // looking in ancestor
-            NodeImpl ancestor = (NodeImpl) getElementAncestor(this);
-            if (ancestor != null) {
-                return ancestor.lookupNamespaceURI(specifiedPrefix);
-            }
-
-            return null;
-
-        }
-        case Node.DOCUMENT_NODE: {
-            Element documentElement = ((Document) this).getDocumentElement();
-            return documentElement == null ? null
-                    : documentElement.lookupNamespaceURI(specifiedPrefix);
-        }
-        case Node.ENTITY_NODE:
-        case Node.NOTATION_NODE:
-        case Node.DOCUMENT_FRAGMENT_NODE:
-        case Node.DOCUMENT_TYPE_NODE:
-            // type is unknown
-            return null;
-        case Node.ATTRIBUTE_NODE: {
-            Element ownerElement = ((Attr) this).getOwnerElement();
-            return ownerElement == null ? null : ownerElement.lookupNamespaceURI(specifiedPrefix);
-        }
-        default: {
-            NodeImpl ancestor = (NodeImpl) getElementAncestor(this);
-            if (ancestor != null) {
-                return ancestor.lookupNamespaceURI(specifiedPrefix);
-            }
-            return null;
-        }
-
-        }
-    }
-
-    /**
      * Tests whether two nodes are equal. <br>This method tests for equality of nodes,
not sameness
      * (i.e., whether the two nodes are references to the same object) which can be tested
with
      * <code>Node.isSameNode()</code>. All nodes that are the same will also
be equal, though the
@@ -927,17 +849,4 @@ public abstract class NodeImpl implement
     }
 
     abstract NodeImpl clone(OMCloneOptions options, ParentNode targetParent, boolean deep,
boolean namespaceRepairing);
-
-    public Node getElementAncestor(Node currentNode) {
-        Node parent = currentNode.getParentNode();
-        while (parent != null) {
-            short type = parent.getNodeType();
-            if (type == Node.ELEMENT_NODE) {
-                return parent;
-            }
-            parent = parent.getParentNode();
-        }
-        return null;
-    }
-
 }



Mime
View raw message