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/08/25 21:12:58 UTC

svn commit: r1697759 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/ implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/ implementations/axiom-impl/src/main/java/org/apa...

Author: veithen
Date: Tue Aug 25 19:12:58 2015
New Revision: 1697759

URL: http://svn.apache.org/r1697759
Log:
Unify the createOMElement methods that take a QName argument.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactorySupport.aj
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactorySupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactorySupport.aj?rev=1697759&r1=1697758&r2=1697759&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactorySupport.aj (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactorySupport.aj Tue Aug 25 19:12:58 2015
@@ -41,6 +41,7 @@ import org.apache.axiom.om.impl.common.A
 import org.apache.axiom.om.impl.common.AxiomText;
 import org.apache.axiom.om.impl.common.Policies;
 import org.apache.axiom.om.impl.common.TextContent;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
 
 public aspect AxiomNodeFactorySupport {
     public final OMDocument AxiomNodeFactory.createOMDocument() {
@@ -207,4 +208,39 @@ public aspect AxiomNodeFactorySupport {
             OMXMLParserWrapper builder) {
         return createAxiomElement(AxiomElement.class, parent, localName, null, builder, false);
     }
+    
+    public final OMElement AxiomNodeFactory.createOMElement(QName qname, OMContainer parent) {
+        AxiomElement element = createNSAwareElement(AxiomElement.class);
+        if (parent != null) {
+            parent.addChild(element);
+        }
+        element.internalSetLocalName(qname.getLocalPart());
+        String prefix = qname.getPrefix();
+        String namespaceURI = qname.getNamespaceURI();
+        if (namespaceURI.length() > 0) {
+            // The goal here is twofold:
+            //  * check if the namespace needs to be declared;
+            //  * locate an existing OMNamespace object, so that we can avoid creating a new one.
+            OMNamespace ns = element.findNamespace(namespaceURI, prefix);
+            if (ns == null) {
+                if ("".equals(prefix)) {
+                    prefix = OMSerializerUtil.getNextNSPrefix();
+                }
+                ns = element.declareNamespace(namespaceURI, prefix);
+            }
+            element.internalSetNamespace(ns);
+        } else if (prefix.length() > 0) {
+            throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
+        } else {
+            if (element.getDefaultNamespace() != null) {
+                element.declareDefaultNamespace("");
+            }
+            element.internalSetNamespace(null);
+        }
+        return element;
+    }
+
+    public final OMElement AxiomNodeFactory.createOMElement(QName qname) {
+        return createOMElement(qname, null);
+    }
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1697759&r1=1697758&r2=1697759&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Tue Aug 25 19:12:58 2015
@@ -38,7 +38,6 @@ import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMEntityReference;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMHierarchyException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNamespace;
@@ -159,42 +158,6 @@ public class OMDOMFactory implements Axi
     }
 
     /**
-     * Creates a new OMDOM Element node and adds it to the given parent.
-     *
-     * @see #createOMElement(String, OMNamespace, OMContainer)
-     * @see org.apache.axiom.om.OMFactory#createOMElement( javax.xml.namespace.QName,
-     *      org.apache.axiom.om.OMContainer)
-     */
-    public OMElement createOMElement(QName qname, OMContainer parent)
-            throws OMException {
-        OMNamespaceImpl ns;
-        if (qname.getNamespaceURI().length() == 0) {
-            if (qname.getPrefix().length() > 0) {
-                throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
-            }
-            ns = null;
-        } else if (qname.getPrefix().length() != 0) {
-            ns = new OMNamespaceImpl(qname.getNamespaceURI(), qname.getPrefix());
-        } else {
-            ns = new OMNamespaceImpl(qname.getNamespaceURI(), null);
-        }
-        return createOMElement(qname.getLocalPart(), ns, parent);
-    }
-
-    /**
-     * Create an OMElement with the given QName
-     * <p/>
-     * If the QName contains a prefix, we will ensure that an OMNamespace is created mapping the
-     * given namespace to the given prefix.  If no prefix is passed, we'll create a generated one.
-     *
-     * @param qname
-     * @return the new OMElement.
-     */
-    public OMElement createOMElement(QName qname) throws OMException {
-        return createOMElement(qname, null);
-    }
-
-    /**
      * Creates a new OMNamespace.
      *
      * @see org.apache.axiom.om.OMFactory#createOMNamespace(String, String)

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1697759&r1=1697758&r2=1697759&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Tue Aug 25 19:12:58 2015
@@ -31,12 +31,9 @@ import org.apache.axiom.om.OMNode;
 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.util.OMSerializerUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.namespace.QName;
-
 import java.util.Iterator;
 
 /** Class OMElementImpl */
@@ -57,59 +54,10 @@ public class OMElementImpl extends OMNod
         initName(localName, ns, generateNSDecl);
     }
 
-    /**
-     * It is assumed that the QName passed contains, at least, the localName for this element.
-     *
-     * @param qname - this should be valid qname according to javax.xml.namespace.QName
-     * @throws OMException
-     */
-    public OMElementImpl(QName qname, OMContainer parent, OMFactory factory)
-            throws OMException {
-        super(factory);
-        if (parent != null) {
-            parent.addChild(this);
-        }
-        internalSetLocalName(qname.getLocalPart());
-        internalSetNamespace(handleNamespace(qname));
-    }
-    
     public OMElementImpl(OMFactory factory) {
         super(factory);
     }
 
-    /** Method handleNamespace. */
-    final OMNamespace handleNamespace(QName qname) {
-        forceExpand();
-
-        // first try to find a namespace from the scope
-        String namespaceURI = qname.getNamespaceURI();
-        if (namespaceURI.length() > 0) {
-            String prefix = qname.getPrefix();
-            OMNamespace ns = findNamespace(namespaceURI, prefix);
-
-            /**
-             * What is left now is
-             *  1. nsURI = null & parent != null, but ns = null
-             *  2. nsURI != null, (parent doesn't have an ns with given URI), but ns = null
-             */
-            if (ns == null) {
-                if ("".equals(prefix)) {
-                    prefix = OMSerializerUtil.getNextNSPrefix();
-                }
-                return declareNamespace(namespaceURI, prefix);
-            } else {
-                return ns;
-            }
-        } else if (qname.getPrefix().length() > 0) {
-            throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
-        } else {
-            if (getDefaultNamespace() != null) {
-                declareDefaultNamespace("");
-            }
-            return null;
-        }
-    }
-
     public void checkChild(OMNode child) {
     }
 

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1697759&r1=1697758&r2=1697759&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Tue Aug 25 19:12:58 2015
@@ -38,7 +38,6 @@ import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMEntityReference;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
@@ -143,37 +142,6 @@ public class OMLinkedListImplFactory imp
         }
     }
 
-    /**
-     * Create an OMElement with the given QName under the given parent.
-     *
-     * If the QName contains a prefix, we will ensure that an OMNamespace is created
-     * mapping the given namespace to the given prefix.  If no prefix is passed, we'll
-     * use whatever's already mapped in the parent, or create a generated one.
-     *
-     * @param qname the QName of the element to create
-     * @param parent the OMContainer in which to place the new element
-     * @return Returns the new OMElement
-     * @throws OMException if there's a namespace mapping problem
-     */
-    public OMElement createOMElement(QName qname, OMContainer parent)
-            throws OMException {
-        return new OMElementImpl(qname, parent, this);
-    }
-
-    /**
-     * Create an OMElement with the given QName
-     * <p/>
-     * If the QName contains a prefix, we will ensure that an OMNamespace is created mapping the
-     * given namespace to the given prefix.  If no prefix is passed, we'll use whatever's already
-     * mapped in the parent, or create a generated one.
-     *
-     * @param qname
-     * @return the new OMElement.
-     */
-    public OMElement createOMElement(QName qname) throws OMException {
-        return new OMElementImpl(qname, null, this);
-    }
-
     public OMSourcedElement createOMElement(OMDataSource source) {
         return new OMSourcedElementImpl(this, source);
     }