Author: veithen
Date: Sat Jun 20 18:20:00 2015
New Revision: 1686660

URL: http://svn.apache.org/r1686660
Log:
Use the namespace URI/prefix lookup methods in core-aspects.

Modified:
    
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
    
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreNSAwareElementSupport.aj
    
webservices/axiom/branches/attrs-aspects/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj

Modified: 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj?rev=1686660&r1=1686659&r2=1686660&view=diff
==============================================================================
--- 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
 (original)
+++ 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
 Sat Jun 20 18:20:00 2015
@@ -229,6 +229,9 @@ public aspect CoreElementSupport {
             String prefix = parentElement.coreLookupPrefix(namespaceURI, 
strict);
             // The prefix declared on one of the ancestors may be masked by 
another
             // namespace declaration on this element (or one of its 
descendants).
+            if (!strict && getImplicitNamespaceURI(prefix) != null) {
+                return null;
+            }
             for (CoreAttribute attr = coreGetFirstAttribute(); attr != null; 
attr = attr.coreGetNextAttribute()) {
                 if (attr instanceof CoreNamespaceDeclaration) {
                     CoreNamespaceDeclaration decl = 
(CoreNamespaceDeclaration)attr;

Modified: 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreNSAwareElementSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreNSAwareElementSupport.aj?rev=1686660&r1=1686659&r2=1686660&view=diff
==============================================================================
--- 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreNSAwareElementSupport.aj
 (original)
+++ 
webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreNSAwareElementSupport.aj
 Sat Jun 20 18:20:00 2015
@@ -20,12 +20,10 @@ package org.apache.axiom.core;
 
 public aspect CoreNSAwareElementSupport {
     public final String CoreNSAwareElement.getImplicitNamespaceURI(String 
prefix) {
-        // TODO
-        throw new UnsupportedOperationException();
+        return prefix.equals(coreGetPrefix()) ? coreGetNamespaceURI() : null;
     }
 
     public final String CoreNSAwareElement.getImplicitPrefix(String 
namespaceURI) {
-        // TODO
-        throw new UnsupportedOperationException();
+        return namespaceURI.equals(coreGetNamespaceURI()) ? coreGetPrefix() : 
null;
     }
 }

Modified: 
webservices/axiom/branches/attrs-aspects/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj?rev=1686660&r1=1686659&r2=1686660&view=diff
==============================================================================
--- 
webservices/axiom/branches/attrs-aspects/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj
 (original)
+++ 
webservices/axiom/branches/attrs-aspects/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMElementSupport.aj
 Sat Jun 20 18:20:00 2015
@@ -26,7 +26,6 @@ import org.apache.axiom.core.CoreNSAware
 import org.apache.axiom.core.CoreNamespaceDeclaration;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.TypeInfo;
@@ -53,72 +52,23 @@ public aspect DOMElementSupport {
         throw new UnsupportedOperationException();
     }
 
-    public final String DOMElement.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
-        if (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;
-                    }
-                }
-            }
+    public final String DOMElement.lookupNamespaceURI(String prefix) {
+        if (prefix == null) {
+            prefix = "";
+        } else if (prefix.length() == 0) {
+            return null;
         }
-        // looking in ancestor
-        DOMParentNode parent = (DOMParentNode)coreGetParent();
-        return parent instanceof Element ? 
parent.lookupNamespaceURI(specifiedPrefix) : null;
+        String namespaceURI = coreLookupNamespaceURI(prefix, false);
+        return namespaceURI == null || namespaceURI.length() == 0 ? null : 
namespaceURI;
     }
 
     public final String DOMElement.lookupPrefix(String namespaceURI) {
-        return lookupPrefix(namespaceURI, this);
-    }
-    
-    private final String DOMElement.lookupPrefix(String namespaceURI, Element 
originalElement) {
-        if (namespaceURI == null || namespaceURI.length() == 0) {
+        if (namespaceURI == null) {
             return null;
+        } else {
+            String prefix = coreLookupPrefix(namespaceURI, false);
+            return prefix == null || prefix.length() == 0 ? null : prefix;
         }
-        if (namespaceURI.equals(getNamespaceURI())) {
-            String prefix = getPrefix();
-            if 
(namespaceURI.equals(originalElement.lookupNamespaceURI(prefix))) {
-                return prefix;
-            }
-        }
-        if (this.hasAttributes()) {
-            NamedNodeMap map = this.getAttributes();
-            int length = map.getLength();
-            for (int i = 0; i < length; i++) {
-                Node attr = map.item(i);
-                String attrPrefix = attr.getPrefix();
-                if (attrPrefix != null && 
attrPrefix.equals(XMLConstants.XMLNS_ATTRIBUTE)
-                        && attr.getNodeValue().equals(namespaceURI)) {
-                    String prefix = attr.getLocalName();
-                    if 
(namespaceURI.equals(originalElement.lookupNamespaceURI(prefix))) {
-                        return prefix;
-                    }
-                }
-            }
-        }
-        DOMParentNode parent = (DOMParentNode)coreGetParent();
-        return parent instanceof Element ? 
((DOMElement)parent).lookupPrefix(namespaceURI, originalElement) : null;
     }
 
     public final boolean DOMElement.hasAttributes() {


Reply via email to