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/29 17:14:11 UTC

svn commit: r1700047 - in /webservices/axiom/trunk: aspects/core-aspects/src/main/java/org/apache/axiom/core/ aspects/dom-aspects/src/main/java/org/apache/axiom/dom/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/ implementati...

Author: veithen
Date: Sat Aug 29 15:14:11 2015
New Revision: 1700047

URL: http://svn.apache.org/r1700047
Log:
AXIOM-472: Move the createOMAttribute code to om-aspects.

Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NSAwareAttributeMatcher.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeFactory.java
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMDocumentSupport.aj
    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/NSAwareAttribute.java
    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/OMAttributeImpl.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
    webservices/axiom/trunk/systests/old-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NSAwareAttributeMatcher.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NSAwareAttributeMatcher.java?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NSAwareAttributeMatcher.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NSAwareAttributeMatcher.java Sat Aug 29 15:14:11 2015
@@ -84,8 +84,12 @@ public final class NSAwareAttributeMatch
         return ((CoreNSAwareAttribute)attr).coreGetLocalName();
     }
 
+    // TODO: get rid of the CoreDocument argument here
     public CoreAttribute createAttribute(NodeFactory nodeFactory, CoreDocument document, String namespaceURI, String name, String prefix, String value) {
-        return nodeFactory.createAttribute(document, namespaceURI, name, prefix, value, null);
+        CoreNSAwareAttribute attr = nodeFactory.createNSAwareAttribute();
+        attr.coreSetName(namespaceURI, name, prefix);
+        attr.coreSetCharacterData(value, null);
+        return attr;
     }
 
     public void update(CoreAttribute attr, String prefix, String value) {

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeFactory.java?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeFactory.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/NodeFactory.java Sat Aug 29 15:14:11 2015
@@ -25,7 +25,7 @@ public interface NodeFactory {
     CoreCDATASection createCDATASection();
     <T extends CoreNSAwareElement> T createNSAwareElement(Class<T> type);
     CoreNSUnawareAttribute createAttribute(CoreDocument document, String name, String value, String type);
-    CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI, String localName, String prefix, String value, String type);
+    CoreNSAwareAttribute createNSAwareAttribute();
     CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document, String prefix, String namespaceURI);
     CoreProcessingInstruction createProcessingInstruction();
     CoreEntityReference createEntityReference();

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMDocumentSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMDocumentSupport.aj?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMDocumentSupport.aj (original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMDocumentSupport.aj Sat Aug 29 15:14:11 2015
@@ -170,7 +170,11 @@ public aspect DOMDocumentSupport {
         } else {
             namespaceURI = NSUtil.normalizeNamespaceURI(namespaceURI);
             NSUtil.validateAttributeName(namespaceURI, localName, prefix);
-            return (DOMAttribute)coreGetNodeFactory().createAttribute(this, namespaceURI, localName, prefix, null, null);
+            DOMNSAwareAttribute attr = (DOMNSAwareAttribute)coreGetNodeFactory().createNSAwareAttribute();
+            attr.coreSetOwnerDocument(this);
+            attr.coreSetName(namespaceURI, localName, prefix);
+            // TODO: set type?
+            return attr;
         }
     }
 

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=1700047&r1=1700046&r2=1700047&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 Sat Aug 29 15:14:11 2015
@@ -21,7 +21,9 @@ package org.apache.axiom.om.impl.common.
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMComment;
+import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMDocument;
@@ -33,6 +35,7 @@ import org.apache.axiom.om.OMProcessingI
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.common.AxiomAttribute;
 import org.apache.axiom.om.impl.common.AxiomCDATASection;
 import org.apache.axiom.om.impl.common.AxiomCharacterDataNode;
 import org.apache.axiom.om.impl.common.AxiomComment;
@@ -43,6 +46,7 @@ import org.apache.axiom.om.impl.common.A
 import org.apache.axiom.om.impl.common.AxiomEntityReference;
 import org.apache.axiom.om.impl.common.AxiomProcessingInstruction;
 import org.apache.axiom.om.impl.common.AxiomText;
+import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.Policies;
 import org.apache.axiom.om.impl.common.TextContent;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
@@ -270,4 +274,32 @@ public aspect AxiomNodeFactorySupport {
     public final OMElement AxiomNodeFactory.createOMElement(QName qname) {
         return createOMElement(qname, null);
     }
+    
+    public final OMAttribute AxiomNodeFactory.createOMAttribute(String localName, OMNamespace ns, String value) {
+        if (ns != null && ns.getPrefix() == null) {
+            String namespaceURI = ns.getNamespaceURI();
+            if (namespaceURI.length() == 0) {
+                ns = null;
+            } else {
+                ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
+            }
+        }
+        if (ns != null) {
+            if (ns.getNamespaceURI().length() == 0) {
+                if (ns.getPrefix().length() > 0) {
+                    throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
+                } else {
+                    ns = null;
+                }
+            } else if (ns.getPrefix().length() == 0) {
+                throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
+            }
+        }
+        AxiomAttribute attr = (AxiomAttribute)createNSAwareAttribute();
+        attr.internalSetLocalName(localName);
+        attr.coreSetCharacterData(value, Policies.DETACH_POLICY);
+        attr.internalSetNamespace(ns);
+        attr.coreSetType(OMConstants.XMLATTRTYPE_CDATA);
+        return attr;
+    }
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareAttribute.java Sat Aug 29 15:14:11 2015
@@ -21,12 +21,10 @@ package org.apache.axiom.om.impl.dom;
 import org.apache.axiom.core.ClonePolicy;
 import org.apache.axiom.dom.DOMNSAwareAttribute;
 import org.apache.axiom.om.OMCloneOptions;
-import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.OMAttributeEx;
 import org.apache.axiom.om.impl.common.AxiomAttribute;
-import org.apache.axiom.om.impl.common.AxiomText;
 
 public final class NSAwareAttribute extends AttrImpl implements OMAttributeEx, AxiomAttribute, DOMNSAwareAttribute {
     // TODO: copy isId?
@@ -37,15 +35,8 @@ public final class NSAwareAttribute exte
         coreSetType(type);
     }
     
-    public NSAwareAttribute(DocumentImpl ownerDocument, String localName,
-                    OMNamespace ns, String value, OMFactory factory) {
-        super(ownerDocument, factory);
-        internalSetLocalName(localName);
-        if (value != null && value.length() != 0) {
-            coreAppendChild((AxiomText)factory.createOMText(value), false);
-        }
-        coreSetType(OMConstants.XMLATTRTYPE_CDATA);
-        internalSetNamespace(ns);
+    public NSAwareAttribute(OMFactory factory) {
+        super(null, factory);
     }
 
     public String toString() {

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=1700047&r1=1700046&r2=1700047&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 Sat Aug 29 15:14:11 2015
@@ -33,7 +33,6 @@ import org.apache.axiom.core.CoreNSUnawa
 import org.apache.axiom.core.CoreNamespaceDeclaration;
 import org.apache.axiom.core.CoreProcessingInstruction;
 import org.apache.axiom.dom.DOMNodeFactory;
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDataSource;
@@ -63,7 +62,6 @@ import org.apache.axiom.om.impl.dom.NSUn
 import org.apache.axiom.om.impl.dom.NamespaceDeclaration;
 import org.apache.axiom.om.impl.dom.ProcessingInstructionImpl;
 import org.apache.axiom.om.impl.dom.TextImpl;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11Body;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11Fault;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11FaultCode;
@@ -173,30 +171,6 @@ public class OMDOMFactory implements Axi
         }
     }
     
-    public OMAttribute createOMAttribute(String localName, OMNamespace ns,
-                                         String value) {
-        if (ns != null && ns.getPrefix() == null) {
-            String namespaceURI = ns.getNamespaceURI();
-            if (namespaceURI.length() == 0) {
-                ns = null;
-            } else {
-                ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
-            }
-        }
-        if (ns != null) {
-            if (ns.getNamespaceURI().length() == 0) {
-                if (ns.getPrefix().length() > 0) {
-                    throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
-                } else {
-                    ns = null;
-                }
-            } else if (ns.getPrefix().length() == 0) {
-                throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
-            }
-        }
-        return new NSAwareAttribute(null, localName, ns, value, this);
-    }
-
     /**
      * This method is intended only to be used by Axiom intenals when merging Objects from different
      * Axiom implementations to the DOOM implementation.
@@ -329,9 +303,8 @@ public class OMDOMFactory implements Axi
         return attr;
     }
 
-    public final CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI,
-            String localName, String prefix, String value, String type) {
-        return new NSAwareAttribute((DocumentImpl)document, localName, namespaceURI.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, prefix), value, this);
+    public final CoreNSAwareAttribute createNSAwareAttribute() {
+        return new NSAwareAttribute(this);
     }
 
     public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document,

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java Sat Aug 29 15:14:11 2015
@@ -20,47 +20,17 @@
 package org.apache.axiom.om.impl.llom;
 
 import org.apache.axiom.om.OMCloneOptions;
-import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMInformationItem;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.common.AxiomAttribute;
-import org.apache.axiom.om.impl.common.Policies;
 
 /** Class OMAttributeImpl */
 public class OMAttributeImpl extends Attribute implements AxiomAttribute {
-    /**
-     * Constructor OMAttributeImpl.
-     *
-     * @param localName
-     * @param ns
-     * @param value
-     */
-    public OMAttributeImpl(String localName, OMNamespace ns, String value, OMFactory factory) 
-    {
+    public OMAttributeImpl(OMFactory factory) {
         super(factory);
-        if (localName == null || localName.trim().length() == 0)
-            throw new IllegalArgumentException("Local name may not be null or empty");
-        
-        if (ns != null) {
-            if (ns.getNamespaceURI().length() == 0) {
-                if (ns.getPrefix().length() > 0) {
-                    throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
-                } else {
-                    ns = null;
-                }
-            } else if (ns.getPrefix().length() == 0) {
-                throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
-            }
-        }
-
-        internalSetLocalName(localName);
-        coreSetCharacterData(value, Policies.DETACH_POLICY);
-        internalSetNamespace(ns);
-        coreSetType(OMConstants.XMLATTRTYPE_CDATA);
     }
 
     public OMInformationItem clone(OMCloneOptions options) {
-        return new OMAttributeImpl(getLocalName(), getNamespace(), getAttributeValue(), getOMFactory());
+        return getOMFactory().createOMAttribute(getLocalName(), getNamespace(), getAttributeValue());
     }
 }

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=1700047&r1=1700046&r2=1700047&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 Sat Aug 29 15:14:11 2015
@@ -33,9 +33,7 @@ import org.apache.axiom.core.CoreNSUnawa
 import org.apache.axiom.core.CoreNamespaceDeclaration;
 import org.apache.axiom.core.CoreProcessingInstruction;
 import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMComment;
-import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMElement;
@@ -61,7 +59,6 @@ import org.apache.axiom.om.impl.llom.OME
 import org.apache.axiom.om.impl.llom.OMEntityReferenceImpl;
 import org.apache.axiom.om.impl.llom.OMProcessingInstructionImpl;
 import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11Body;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11Fault;
 import org.apache.axiom.soap.impl.common.AxiomSOAP11FaultCode;
@@ -180,28 +177,6 @@ public class OMLinkedListImplFactory imp
     }
 
     /**
-     * Creates attribute.
-     *
-     * @param localName
-     * @param ns
-     * @param value
-     * @return Returns OMAttribute.
-     */
-    public OMAttribute createOMAttribute(String localName,
-                                         OMNamespace ns,
-                                         String value) {
-        if (ns != null && ns.getPrefix() == null) {
-            String namespaceURI = ns.getNamespaceURI();
-            if (namespaceURI.length() == 0) {
-                ns = null;
-            } else {
-                ns = new OMNamespaceImpl(namespaceURI, OMSerializerUtil.getNextNSPrefix());
-            }
-        }
-        return new OMAttributeImpl(localName, ns, value, this);
-    }
-
-    /**
      * This method is intended only to be used by Axiom intenals when merging Objects from different
      * Axiom implementations to the LLOM implementation.
      *
@@ -331,12 +306,8 @@ public class OMLinkedListImplFactory imp
         throw new UnsupportedOperationException();
     }
 
-    public CoreNSAwareAttribute createAttribute(CoreDocument document, String namespaceURI,
-            String localName, String prefix, String value, String type) {
-        return new OMAttributeImpl(
-                localName,
-                namespaceURI.length() == 0 && prefix.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, prefix),
-                value, this);
+    public CoreNSAwareAttribute createNSAwareAttribute() {
+        return new OMAttributeImpl(this);
     }
 
     public final CoreNamespaceDeclaration createNamespaceDeclaration(CoreDocument document,

Modified: webservices/axiom/trunk/systests/old-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/old-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java?rev=1700047&r1=1700046&r2=1700047&view=diff
==============================================================================
--- webservices/axiom/trunk/systests/old-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java (original)
+++ webservices/axiom/trunk/systests/old-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java Sat Aug 29 15:14:11 2015
@@ -32,36 +32,6 @@ import java.io.StringReader;
 
 public class OMAttributeTest extends TestCase {
 
-    public void testNullLocalName() throws Exception {
-        OMFactory factory = OMAbstractFactory.getOMFactory();
-        try {
-            factory.createOMAttribute(null, null, null);
-        } catch (IllegalArgumentException e) {
-            return;
-        }
-        fail("Null localname was accepted!");
-    }
-
-    public void testEmptyLocalName() throws Exception {
-        OMFactory factory = OMAbstractFactory.getOMFactory();
-        try {
-            factory.createOMAttribute("", null, null);
-        } catch (IllegalArgumentException e) {
-            return;
-        }
-        fail("Empty localname was accepted!");
-    }
-
-    public void testWhitespaceLocalName() throws Exception {
-        OMFactory factory = OMAbstractFactory.getOMFactory();
-        try {
-            factory.createOMAttribute("    ", null, null);
-        } catch (IllegalArgumentException e) {
-            return;
-        }
-        fail("Whitespace localname was accepted!");
-    }
-
     public void testAddAttribute() throws Exception {
         String xmlString =
                 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header name = \"jhon\"/><soapenv:Body><my:uploadFileUsingMTOM xmlns:my=\"http://localhost/my\"><my:folderName>/home/saliya/Desktop</my:folderName></my:uploadFileUsingMTOM></soapenv:Body><Body>TTTT</Body> </soapenv:Envelope>";