You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/09/10 09:25:29 UTC

svn commit: r1382670 - /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java

Author: veithen
Date: Mon Sep 10 07:25:28 2012
New Revision: 1382670

URL: http://svn.apache.org/viewvc?rev=1382670&view=rev
Log:
AXIOM-423: Some optimizations and code simplifications. The code for lookupNamespaceURI now has 100% line and branch coverage.

Modified:
    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/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=1382670&r1=1382669&r2=1382670&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:25:28 2012
@@ -257,16 +257,12 @@ public abstract class NodeImpl implement
 
             String namespace = this.getNamespaceURI();
             String prefix = this.getPrefix();
-            // looking in the element
+            // 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) {
-                if (prefix == null && specifiedPrefix == null) {
-                    // looking for default namespace
-                    return namespace;
-                } else if (prefix != null && prefix.equals(specifiedPrefix)) {
-                    // non default namespace
-                    return namespace;
-                }
+            if (namespace != null
+                    && (prefix == null && specifiedPrefix == null
+                            || prefix != null && prefix.equals(specifiedPrefix))) {
+                return namespace;
             }
             // looking in attributes
             if (this.hasAttributes()) {
@@ -274,14 +270,17 @@ public abstract class NodeImpl implement
                 int length = map.getLength();
                 for (int i = 0; i < length; i++) {
                     Node attr = map.item(i);
-                    String attrPrefix = attr.getPrefix();
-                    String value = attr.getNodeValue();
                     namespace = attr.getNamespaceURI();
                     if (namespace != null && namespace.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
-                        if (specifiedPrefix == null && attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) {
-                            return value.length() > 0 ? value : null;
-                        } else if (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_ATTRIBUTE)
-                                && attr.getLocalName().equals(specifiedPrefix)) {
+                        // 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;
                         }
                     }