ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1685677 - in /webservices/axiom/branches/attrs-aspects: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/ implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ implementations/axiom-impl/src/main/java/org/ap...
Date Mon, 15 Jun 2015 21:55:15 GMT
Author: veithen
Date: Mon Jun 15 21:55:15 2015
New Revision: 1685677

URL: http://svn.apache.org/r1685677
Log:
Rewrite the namespace declaration support in LLOM.

Modified:
    webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
    webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java

Modified: webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj?rev=1685677&r1=1685676&r2=1685677&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
(original)
+++ webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
Mon Jun 15 21:55:15 2015
@@ -31,11 +31,13 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.core.CoreAttribute;
 import org.apache.axiom.core.CoreParentNode;
 import org.apache.axiom.core.IdentityMapper;
 import org.apache.axiom.core.NodeMigrationException;
 import org.apache.axiom.core.NodeMigrationPolicy;
 import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
@@ -369,4 +371,97 @@ public aspect AxiomElementSupport {
     public final void AxiomElement.undeclarePrefix(String prefix) {
         addNamespaceDeclaration(new OMNamespaceImpl("", prefix));
     }
+
+    public final OMNamespace AxiomElement.findNamespace(String uri, String prefix) {
+
+        // check in the current element
+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
+        if (namespace != null) {
+            return namespace;
+        }
+
+        // go up to check with ancestors
+        OMContainer parent = getParent();
+        if (parent != null) {
+            //For the OMDocumentImpl there won't be any explicit namespace
+            //declarations, so going up the parent chain till the document
+            //element should be enough.
+            if (parent instanceof OMElement) {
+                namespace = ((OMElement) parent).findNamespace(uri, prefix);
+                // If the prefix has been redeclared, then ignore the binding found on the
ancestors
+                if (prefix == null && namespace != null && findDeclaredNamespace(null,
namespace.getPrefix()) != null) {
+                    namespace = null;
+                }
+            }
+        }
+
+        return namespace;
+    }
+
+    private static final OMNamespace XMLNS = new OMNamespaceImpl(OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX);
+
+    /**
+     * Checks for the namespace <B>only</B> in the current Element. This is also
used to retrieve
+     * the prefix of a known namespace URI.
+     */
+    private OMNamespace AxiomElement.findDeclaredNamespace(String uri, String prefix) {
+        // Seems weird, but necessary for compatibility with older versions
+        if (uri != null && prefix != null && prefix.length() == 0) {
+            prefix = null;
+        }
+        
+        CoreAttribute attr = coreGetFirstAttribute();
+        while (attr != null) {
+            if (attr instanceof AxiomNamespaceDeclaration) {
+                OMNamespace namespace = ((AxiomNamespaceDeclaration)attr).getDeclaredNamespace();
+                if ((prefix == null || prefix.equals(namespace.getPrefix()))
+                        && (uri == null || uri.equals(namespace.getNamespaceURI())))
{
+                    return namespace;
+                }
+            }
+            attr = attr.coreGetNextAttribute();
+        }
+
+        //If the prefix is available and uri is available and its the xml namespace
+        if ((prefix == null || prefix.equals(OMConstants.XMLNS_PREFIX))
+                && (uri == null || uri.equals(OMConstants.XMLNS_URI))) {
+            return XMLNS;
+        } else {
+            return null;
+        }
+    }
+
+    public final OMNamespace AxiomElement.findNamespaceURI(String prefix) {
+        if (prefix == null) {
+            throw new IllegalArgumentException();
+        }
+        CoreAttribute attr = coreGetFirstAttribute();
+        while (attr != null) {
+            if (attr instanceof AxiomNamespaceDeclaration) {
+                AxiomNamespaceDeclaration nsDecl = (AxiomNamespaceDeclaration)attr;
+                if (nsDecl.coreGetDeclaredPrefix().equals(prefix)) {
+                    OMNamespace ns = nsDecl.getDeclaredNamespace();
+                    if (ns.getNamespaceURI().length() == 0) {
+                        // We are either in the prefix undeclaring case (XML 1.1 only) or
the namespace
+                        // declaration is xmlns="". In both cases we need to return null.
+                        return null;
+                    } else {
+                        return ns;
+                    }
+                }
+            }
+            attr = attr.coreGetNextAttribute();
+        }
+        OMContainer parent = getParent();
+        if (parent instanceof OMElement) {
+            // try with the parent
+            return ((OMElement)parent).findNamespaceURI(prefix);
+        } else {
+            return null;
+        }
+    }
+
+    public final OMNamespace AxiomElement.getDefaultNamespace() {
+        return findNamespaceURI("");
+    }
 }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1685677&r1=1685676&r2=1685677&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Mon Jun 15 21:55:15 2015
@@ -22,7 +22,6 @@ package org.apache.axiom.om.impl.dom;
 import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
 
 import org.apache.axiom.core.AttributeMatcher;
-import org.apache.axiom.core.CoreAttribute;
 import org.apache.axiom.core.CoreModelException;
 import org.apache.axiom.core.NodeMigrationException;
 import org.apache.axiom.core.NodeMigrationPolicy;
@@ -34,7 +33,6 @@ import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
@@ -54,7 +52,6 @@ import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.NamedNodeMap;
 
-import javax.xml.XMLConstants;
 import javax.xml.stream.XMLStreamException;
 
 import java.io.ByteArrayOutputStream;
@@ -205,122 +202,6 @@ public class ElementImpl extends ParentN
         return declareNamespace(ns);
     }
 
-    public OMNamespace getDefaultNamespace() {
-        Attr decl = getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
-        if (decl != null) {
-            String uri = decl.getValue();
-            return uri.length() == 0 ? null : new OMNamespaceImpl(uri, "");
-        }
-
-        ParentNode parentNode = (ParentNode)coreGetParent();
-        if (parentNode instanceof ElementImpl) {
-            ElementImpl element = (ElementImpl) parentNode;
-            return element.getDefaultNamespace();
-        }
-        return null;
-    }
-
-    /** @see org.apache.axiom.om.OMElement#findNamespace(String, String) */
-    public OMNamespace findNamespace(String uri, String prefix) {
-
-        // check in the current element
-        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
-        if (namespace != null) {
-            return namespace;
-        }
-
-        // go up to check with ancestors
-        ParentNode parentNode = (ParentNode)coreGetParent();
-        if (parentNode != null) {
-            // For the OMDocumentImpl there won't be any explicit namespace
-            // declarations, so going up the parent chain till the document
-            // element should be enough.
-            if (parentNode instanceof OMElement) {
-                namespace = ((ElementImpl) parentNode).findNamespace(uri,
-                                                                     prefix);
-                // If the prefix has been redeclared, then ignore the binding found on the
ancestors
-                if (prefix == null && namespace != null && findDeclaredNamespace(null,
namespace.getPrefix()) != null) {
-                    namespace = null;
-                }
-            }
-        }
-
-        if (namespace == null && uri != null && prefix != null
-                && prefix.equals(OMConstants.XMLNS_PREFIX)
-                && uri.equals(OMConstants.XMLNS_URI)) {
-            declareNamespace(OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX);
-            namespace = findNamespace(uri, prefix);
-        }
-        return namespace;
-    }
-
-    public OMNamespace findNamespaceURI(String prefix) {
-        CoreAttribute attr = coreGetFirstAttribute();
-        while (attr != null) {
-            if (attr instanceof NamespaceDeclaration) {
-                NamespaceDeclaration nsDecl = (NamespaceDeclaration)attr;
-                if (nsDecl.coreGetDeclaredPrefix().equals(prefix)) {
-                    OMNamespace ns = nsDecl.getDeclaredNamespace();
-                    if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length()
== 0) {
-                        // Prefix undeclaring case (XML 1.1 only)
-                        return null;
-                    } else {
-                        return ns;
-                    }
-                }
-            }
-            attr = attr.coreGetNextAttribute();
-        }
-        ParentNode parentNode = (ParentNode)coreGetParent();
-        if (parentNode instanceof OMElement) {
-            // try with the parent
-            return ((OMElement)parentNode).findNamespaceURI(prefix);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Checks for the namespace <B>only</B> in the current Element. This can
also be used to
-     * retrieve the prefix of a known namespace URI.
-     */
-    private OMNamespace findDeclaredNamespace(String uri, String prefix) {
-        NamedNodeMap attributes = getAttributes();
-        if (uri == null) {
-            Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
-                    prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : prefix);
-            return decl == null ? null : new OMNamespaceImpl(decl.getValue(), prefix);
-        }
-        // If the prefix is available and uri is available and its the xml
-        // namespace
-        if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX)
-                && uri.equals(OMConstants.XMLNS_URI)) {
-            return new OMNamespaceImpl(uri, prefix);
-        }
-
-        if (prefix == null || "".equals(prefix)) {
-            for (int i=0; i<attributes.getLength(); i++) {
-                Attr attr = (Attr)attributes.item(i);
-                if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
-                    String declaredUri = attr.getValue();
-                    if (declaredUri.equals(uri)) {
-                        return new OMNamespaceImpl(uri, attr.getPrefix() == null ? "" : attr.getLocalName());
-                    }
-                }
-            }
-        } else {
-            Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
prefix);
-            if (decl != null) {
-                String declaredUri = decl.getValue();
-                if (declaredUri.equals(uri)) {
-                    return new OMNamespaceImpl(uri, prefix);
-                }
-            }
-        }
-
-        return null;
-    }
-
     public void setNamespace(OMNamespace namespace) {
         setNamespace(namespace, true);
     }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1685677&r1=1685676&r2=1685677&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Mon Jun 15 21:55:15 2015
@@ -35,7 +35,6 @@ import org.apache.axiom.om.impl.common.A
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.serializer.push.OutputException;
 import org.apache.axiom.om.impl.common.serializer.push.Serializer;
-import org.apache.axiom.om.impl.util.EmptyIterator;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.commons.logging.Log;
@@ -55,11 +54,7 @@ public class OMElementImpl extends OMNod
 
     private static final Log log = LogFactory.getLog(OMElementImpl.class);
     
-    /** Field namespaces */
-    protected HashMap namespaces = null;
-    
     private int lineNumber;
-    private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator();
 
     public OMElementImpl(OMContainer parent, String localName, OMNamespace ns, OMXMLParserWrapper
builder,
                     OMFactory factory, boolean generateNSDecl) {
@@ -142,123 +137,6 @@ public class OMElementImpl extends OMNod
         return declareNamespace(ns);
     }
 
-    public OMNamespace getDefaultNamespace() {
-        OMNamespace defaultNS;
-        if (namespaces != null && (defaultNS = (OMNamespace) namespaces.get(""))
!= null) {
-            return defaultNS.getNamespaceURI().length() == 0 ? null : defaultNS;
-        }
-        OMContainer parent = getParent();
-        if (parent instanceof OMElementImpl) {
-            return ((OMElementImpl) parent).getDefaultNamespace();
-
-        }
-        return null;
-    }
-
-    /**
-     * Finds a namespace with the given uri and prefix, in the scope of the document. Starts
to find
-     * from the current element and goes up in the hiararchy until one is found. If none
is found,
-     * returns null.
-     */
-    public OMNamespace findNamespace(String uri, String prefix) {
-
-        // check in the current element
-        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
-        if (namespace != null) {
-            return namespace;
-        }
-
-        // go up to check with ancestors
-        OMContainer parent = getParent();
-        if (parent != null) {
-            //For the OMDocumentImpl there won't be any explicit namespace
-            //declarations, so going up the parent chain till the document
-            //element should be enough.
-            if (parent instanceof OMElement) {
-                namespace = ((OMElementImpl) parent).findNamespace(uri, prefix);
-                // If the prefix has been redeclared, then ignore the binding found on the
ancestors
-                if (prefix == null && namespace != null && findDeclaredNamespace(null,
namespace.getPrefix()) != null) {
-                    namespace = null;
-                }
-            }
-        }
-
-        return namespace;
-    }
-
-    public OMNamespace findNamespaceURI(String prefix) {
-        OMNamespace ns = this.namespaces == null ?
-                null :
-                (OMNamespace) this.namespaces.get(prefix);
-
-        if (ns == null) {
-            OMContainer parent = getParent();
-            if (parent instanceof OMElement) {
-                // try with the parent
-                return ((OMElement)parent).findNamespaceURI(prefix);
-            } else {
-                return null;
-            }
-        } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length()
== 0) {
-            // Prefix undeclaring case (XML 1.1 only)
-            return null;
-        } else {
-            return ns;
-        }
-    }
-
-    // Constant
-    static final OMNamespaceImpl xmlns =
-            new OMNamespaceImpl(OMConstants.XMLNS_URI,
-                                OMConstants.XMLNS_PREFIX);
-
-    /**
-     * Checks for the namespace <B>only</B> in the current Element. This is also
used to retrieve
-     * the prefix of a known namespace URI.
-     */
-    private OMNamespace findDeclaredNamespace(String uri, String prefix) {
-        if (uri == null) {
-            return namespaces == null ? null : (OMNamespace)namespaces.get(prefix);
-        }
-
-        //If the prefix is available and uri is available and its the xml namespace
-        if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) &&
-                uri.equals(OMConstants.XMLNS_URI)) {
-            return xmlns;
-        }
-
-        if (namespaces == null) {
-            return null;
-        }
-
-        if (prefix == null || "".equals(prefix)) {
-
-            OMNamespace defaultNamespace = this.getDefaultNamespace();
-            if (defaultNamespace != null && uri.equals(defaultNamespace.getNamespaceURI()))
{
-                return defaultNamespace;
-            }
-            Iterator namespaceListIterator = namespaces.values().iterator();
-
-            String nsUri;
-
-            while (namespaceListIterator.hasNext()) {
-                OMNamespace omNamespace =
-                        (OMNamespace) namespaceListIterator.next();
-                nsUri = omNamespace.getNamespaceURI();
-                if (nsUri != null &&
-                        nsUri.equals(uri)) {
-                    return omNamespace;
-                }
-            }
-        } else {
-            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
-            if (namespace != null && uri.equals(namespace.getNamespaceURI())) {
-                return namespace;
-            }
-        }
-        return null;
-    }
-
     /**
      * Inserts an attribute to this element. Implementor can decide as to insert this in
the front
      * or at the end of set of attributes.



Mime
View raw message