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 2015/06/17 22:03:25 UTC

svn commit: r1686105 - in /webservices/axiom/branches/attrs-aspects: aspects/core-aspects/src/main/java/org/apache/axiom/core/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/ implementations/axiom-dom/src/main/java/org/apache/axiom/om...

Author: veithen
Date: Wed Jun 17 20:03:25 2015
New Revision: 1686105

URL: http://svn.apache.org/r1686105
Log:
Unify remaining namespace declaration related code and ensure that test cases pass.

Modified:
    webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreElementSupport.aj
    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
    webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java

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=1686105&r1=1686104&r2=1686105&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 Wed Jun 17 20:03:25 2015
@@ -133,7 +133,7 @@ public aspect CoreElementSupport {
         CoreAttribute attr = accept(coreAttr, policy);
         String namespaceURI = matcher.getNamespaceURI(attr);
         String name = matcher.getName(attr); 
-        CoreAttribute existingAttr = firstAttribute;
+        CoreAttribute existingAttr = coreGetFirstAttribute();
         CoreAttribute previousAttr = null;
         while (existingAttr != null && !matcher.matches(existingAttr, namespaceURI, name)) {
             previousAttr = existingAttr;

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=1686105&r1=1686104&r2=1686105&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 Wed Jun 17 20:03:25 2015
@@ -51,6 +51,8 @@ import org.apache.axiom.om.impl.common.f
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Utility class with default implementations for some of the methods defined by the
@@ -59,6 +61,8 @@ import org.apache.axiom.util.stax.XMLStr
 public aspect AxiomElementSupport {
     declare parents: (InformationItem+ && OMElement+) implements AxiomElement;
     
+    private static final Log log = LogFactory.getLog(AxiomElementSupport.class);
+    
     public final int AxiomElement.getType() {
         return OMNode.ELEMENT_NODE;
     }
@@ -302,6 +306,49 @@ public aspect AxiomElementSupport {
             AxiomExceptionUtil.translate(ex);
         }
     }
+    
+    public final OMAttribute AxiomElement.addAttribute(OMAttribute attr){
+        // If the attribute already has an owner element then clone the attribute (except if it is owned
+        // by the this element)
+        OMElement owner = attr.getOwner();
+        if (owner != null) {
+            if (owner == this) {
+                return attr;
+            }
+            attr = getOMFactory().createOMAttribute(attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue());
+        }
+
+        OMNamespace namespace = attr.getNamespace();
+        if (namespace != null) {
+            String uri = namespace.getNamespaceURI();
+            if (uri.length() > 0) {
+                String prefix = namespace.getPrefix();
+                OMNamespace ns2 = findNamespaceURI(prefix);
+                if (ns2 == null || !uri.equals(ns2.getNamespaceURI())) {
+                    declareNamespace(uri, prefix);
+                }
+            }
+        }
+
+        internalAppendAttribute(attr);
+        return attr;
+    }
+
+    public final OMAttribute AxiomElement.addAttribute(String localName, String value, OMNamespace ns) {
+        OMNamespace namespace = null;
+        if (ns != null) {
+            String namespaceURI = ns.getNamespaceURI();
+            String prefix = ns.getPrefix();
+            if (namespaceURI.length() > 0 || prefix != null) {
+                namespace = findNamespace(namespaceURI, prefix);
+                if (namespace == null || prefix == null && namespace.getPrefix().length() == 0) {
+                    namespace = new OMNamespaceImpl(namespaceURI, prefix != null ? prefix : OMSerializerUtil.getNextNSPrefix());
+                }
+            }
+        }
+        return addAttribute(getOMFactory().createOMAttribute(localName, namespace, value));
+    }
+
     private static final IdentityMapper<AxiomAttribute> attributeIdentityMapper = new IdentityMapper<AxiomAttribute>();
     
     @SuppressWarnings("rawtypes")
@@ -363,6 +410,15 @@ public aspect AxiomElementSupport {
         return namespace;
     }
 
+    public final OMNamespace AxiomElement.declareNamespace(String uri, String prefix) {
+        if ("".equals(prefix)) {
+            log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix");
+            prefix = OMSerializerUtil.getNextNSPrefix();
+        }
+        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
+        return declareNamespace(ns);
+    }
+
     public final OMNamespace AxiomElement.declareDefaultNamespace(String uri) {
         OMNamespace elementNamespace = getNamespace();
         if (elementNamespace == null && uri.length() > 0

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=1686105&r1=1686104&r2=1686105&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 Wed Jun 17 20:03:25 2015
@@ -22,14 +22,12 @@ 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.CoreModelException;
 import org.apache.axiom.core.NodeMigrationException;
 import org.apache.axiom.core.NodeMigrationPolicy;
 import org.apache.axiom.dom.DOMAttribute;
 import org.apache.axiom.dom.DOMConfigurationImpl;
 import org.apache.axiom.dom.DOMElement;
 import org.apache.axiom.dom.DOMExceptionUtil;
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMElement;
@@ -38,16 +36,11 @@ import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.common.AxiomAttribute;
 import org.apache.axiom.om.impl.common.AxiomContainer;
 import org.apache.axiom.om.impl.common.AxiomElement;
-import org.apache.axiom.om.impl.common.OMNamespaceImpl;
-import org.apache.axiom.om.impl.common.Policies;
 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.OMSerializerUtil;
-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.NamedNodeMap;
@@ -61,8 +54,6 @@ import java.util.Iterator;
 public class ElementImpl extends ParentNode implements DOMElement, AxiomElement, NamedNode,
         OMConstants {
 
-    private static final Log log = LogFactory.getLog(ElementImpl.class);
-    
     private int lineNumber;
 
     public ElementImpl(ParentNode parentNode, String localName, OMNamespace ns, OMXMLParserWrapper builder,
@@ -128,80 +119,6 @@ public class ElementImpl extends ParentN
     // /OmElement methods
     // /
 
-    /** @see org.apache.axiom.om.OMElement#addAttribute (org.apache.axiom.om.OMAttribute) */
-    public OMAttribute addAttribute(OMAttribute attr) {
-        // If the attribute already has an owner element then clone the attribute (except if it is owned
-        // by the this element)
-        OMElement owner = attr.getOwner();
-        if (owner != null) {
-            if (owner == this) {
-                return attr;
-            }
-            attr = new NSAwareAttribute(null, attr.getLocalName(), attr.getNamespace(),
-                    attr.getAttributeValue(), attr.getOMFactory());
-        }
-        
-        OMNamespace namespace = attr.getNamespace();
-        if (namespace != null) {
-            String uri = namespace.getNamespaceURI();
-            if (uri.length() > 0) {
-                String prefix = namespace.getPrefix();
-                OMNamespace ns2 = findNamespaceURI(prefix);
-                if (ns2 == null || !uri.equals(ns2.getNamespaceURI())) {
-                    declareNamespace(uri, prefix);
-                }
-            }
-        }
-
-        try {
-            coreSetAttribute(Policies.ATTRIBUTE_MATCHER, (AxiomAttribute)attr, NodeMigrationPolicy.MOVE_ALWAYS, true, null, ReturnValue.NONE);
-        } catch (NodeMigrationException ex) {
-            DOMExceptionUtil.translate(ex);
-        }
-        return attr;
-    }
-
-    public final OMAttribute addAttribute(String localName, String value, OMNamespace ns) {
-        try {
-            String namespaceURI;
-            String prefix;
-            if (ns == null) {
-                namespaceURI = "";
-                prefix = "";
-            } else {
-                namespaceURI = ns.getNamespaceURI();
-                prefix = ns.getPrefix();
-                if (namespaceURI.length() == 0) {
-                    if (prefix == null) {
-                        prefix = "";
-                    } else if (prefix.length() > 0) {
-                        throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
-                    }
-                } else {
-                    if (prefix == null || prefix.length() > 0) {
-                        prefix = checkNamespaceIsDeclared(prefix, namespaceURI, false, true);
-                    } else {
-                        throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
-                    }
-                }
-            }
-            AxiomAttribute attr = (AxiomAttribute)coreGetNodeFactory().createAttribute(null, namespaceURI, localName, prefix, value, "CDATA");
-            return (AxiomAttribute)coreSetAttribute(Policies.ATTRIBUTE_MATCHER, attr, NodeMigrationPolicy.MOVE_ALWAYS, true, null, ReturnValue.ADDED_ATTRIBUTE);
-        } catch (CoreModelException ex) {
-            throw DOMExceptionUtil.translate(ex);
-        }
-    }
-
-    public OMNamespace declareNamespace(String uri, String prefix) {
-        if ("".equals(prefix)) {
-            log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix");
-            prefix = OMSerializerUtil.getNextNSPrefix();
-        }
-        
-        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
-        return declareNamespace(ns);
-    }
-
     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=1686105&r1=1686104&r2=1686105&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 Wed Jun 17 20:03:25 2015
@@ -32,7 +32,6 @@ import org.apache.axiom.om.OMOutputForma
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.common.AxiomContainer;
 import org.apache.axiom.om.impl.common.AxiomElement;
-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.OMSerializerUtil;
@@ -45,7 +44,6 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 import java.io.StringWriter;
-import java.util.HashMap;
 import java.util.Iterator;
 
 /** Class OMElementImpl */
@@ -128,75 +126,6 @@ public class OMElementImpl extends OMNod
     public void checkChild(OMNode child) {
     }
 
-    public OMNamespace declareNamespace(String uri, String prefix) {
-        if ("".equals(prefix)) {
-            log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix");
-            prefix = OMSerializerUtil.getNextNSPrefix();
-        }
-        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
-        return declareNamespace(ns);
-    }
-
-    /**
-     * Inserts an attribute to this element. Implementor can decide as to insert this in the front
-     * or at the end of set of attributes.
-     *
-     * <p>The owner of the attribute is set to be the particular <code>OMElement</code>.
-     * If the attribute already has an owner then the attribute is cloned (i.e. its name,
-     * value and namespace are copied to a new attribute) and the new attribute is added
-     * to the element. It's owner is then set to be the particular <code>OMElement</code>.
-     * 
-     * @return The attribute that was added to the element. Note: The added attribute
-     * may not be the same instance that was given to add. This can happen if the given
-     * attribute already has an owner. In such case the returned attribute and the given
-     * attribute are <i>equal</i> but not the same instance.
-     *
-     * @see OMAttributeImpl#equals(Object)
-     */
-    public OMAttribute addAttribute(OMAttribute attr){
-        // If the attribute already has an owner element then clone the attribute (except if it is owned
-        // by the this element)
-        OMElement owner = attr.getOwner();
-        if (owner != null) {
-            if (owner == this) {
-                return attr;
-            }
-            attr = new OMAttributeImpl(
-                    attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue(), attr.getOMFactory());
-        }
-
-        OMNamespace namespace = attr.getNamespace();
-        if (namespace != null) {
-            String uri = namespace.getNamespaceURI();
-            if (uri.length() > 0) {
-                String prefix = namespace.getPrefix();
-                OMNamespace ns2 = findNamespaceURI(prefix);
-                if (ns2 == null || !uri.equals(ns2.getNamespaceURI())) {
-                    declareNamespace(uri, prefix);
-                }
-            }
-        }
-
-        internalAppendAttribute(attr);
-        return attr;
-    }
-
-    public OMAttribute addAttribute(String localName, String value,
-                                    OMNamespace ns) {
-        OMNamespace namespace = null;
-        if (ns != null) {
-            String namespaceURI = ns.getNamespaceURI();
-            String prefix = ns.getPrefix();
-            if (namespaceURI.length() > 0 || prefix != null) {
-                namespace = findNamespace(namespaceURI, prefix);
-                if (namespace == null || prefix == null && namespace.getPrefix().length() == 0) {
-                    namespace = new OMNamespaceImpl(namespaceURI, prefix != null ? prefix : OMSerializerUtil.getNextNSPrefix());
-                }
-            }
-        }
-        return addAttribute(new OMAttributeImpl(localName, namespace, value, getOMFactory()));
-    }
-
     public void build() throws OMException {
         /**
          * builder is null. Meaning this is a programatical created element but it has children which are not completed

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1686105&r1=1686104&r2=1686105&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Wed Jun 17 20:03:25 2015
@@ -20,7 +20,6 @@
 package org.apache.axiom.om.impl.llom;
 
 import org.apache.axiom.core.CoreChildNode;
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDataSource;
@@ -335,21 +334,6 @@ public class OMSourcedElementImpl extend
         return isExpanded;
     }
 
-    public OMNamespace declareNamespace(String uri, String prefix) {
-        forceExpand();
-        return super.declareNamespace(uri, prefix);
-    }
-
-    public OMAttribute addAttribute(OMAttribute attr) {
-        forceExpand();
-        return super.addAttribute(attr);
-    }
-
-    public OMAttribute addAttribute(String attributeName, String value, OMNamespace namespace) {
-        forceExpand();
-        return super.addAttribute(attributeName, value, namespace);
-    }
-
     public XMLStreamReader getXMLStreamReader(boolean cache) {
         return getXMLStreamReader(cache, new OMXMLStreamReaderConfiguration());
     }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1686105&r1=1686104&r2=1686105&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Wed Jun 17 20:03:25 2015
@@ -43,6 +43,7 @@ import org.apache.axiom.om.OMSourcedElem
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.common.AxiomAttribute;
 import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory;