You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by pr...@apache.org on 2006/10/31 18:47:14 UTC

svn commit: r469580 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/util/ axiom-tests/src/test/java/org/apache/axiom/om/util/

Author: pradine
Date: Tue Oct 31 09:47:12 2006
New Revision: 469580

URL: http://svn.apache.org/viewvc?view=rev&rev=469580
Log:
New implementation, and new unit test.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMAttributeHelperTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java?view=diff&rev=469580&r1=469579&r2=469580
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/AttributeHelper.java Tue Oct 31 09:47:12 2006
@@ -18,7 +18,6 @@
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 
 /**
  * Helper class for attributes.
@@ -31,16 +30,13 @@
     * 
     * @see ElementHelper#importOMElement(OMElement, OMFactory) to convert instances of OMElement
     */
-    public static OMAttribute importOMAttribute(OMAttribute omAttribute, OMFactory omFactory) {
+    public static void importOMAttribute(OMAttribute omAttribute, OMElement omElement) {
         // first check whether the given OMAttribute has the same OMFactory
-        if (omAttribute.getOMFactory().getClass().isInstance(omFactory)) {
-            return omAttribute;
-        }else {
-            OMElement omElement = omAttribute.getOMFactory().createOMElement("localName", "namespace", "prefix");
+        if (omAttribute.getOMFactory().getClass().isInstance(omElement.getOMFactory())) {
             omElement.addAttribute(omAttribute);
-            OMElement documentElement = new StAXOMBuilder(omFactory, omElement.getXMLStreamReader()).getDocumentElement();
-            documentElement.build();
-            return (OMAttribute) documentElement.getAllAttributes().next();
+        }
+        else {
+            omElement.addAttribute(omAttribute.getLocalName(), omAttribute.getAttributeValue(), omAttribute.getNamespace());
         }
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java?view=diff&rev=469580&r1=469579&r2=469580
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java Tue Oct 31 09:47:12 2006
@@ -144,7 +144,7 @@
      * tree, we need to convert the new OMElement to match to the factory of existing object tree.
      * This method will convert omElement to the given omFactory.
      *
-     * @see AttributeHelper#importOMAttribute(OMAttribute, OMFactory) to convert instances of OMAttribute
+     * @see AttributeHelper#importOMAttribute(OMAttribute, OMElement) to convert instances of OMAttribute
      */
     public static OMElement importOMElement(OMElement omElement, OMFactory omFactory) {
         // first check whether the given OMElement has the same omFactory

Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMAttributeHelperTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMAttributeHelperTest.java?view=auto&rev=469580
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMAttributeHelperTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMAttributeHelperTest.java Tue Oct 31 09:47:12 2006
@@ -0,0 +1,50 @@
+package org.apache.axiom.om.util;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
+
+import junit.framework.TestCase;
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class OMAttributeHelperTest extends TestCase {
+
+    public void testImportOMAttribute() {
+        //Convert from OM to DOOM.
+        OMFactory omf = OMAbstractFactory.getOMFactory();
+        OMNamespace ns1 = omf.createOMNamespace("http://nsurl","prefix");
+        OMAttribute attr1 = omf.createOMAttribute("attr1",ns1,"attr1value");
+        
+        OMFactory doomf = DOOMAbstractFactory.getOMFactory();
+        OMElement ome1 = doomf.createOMElement("element", ns1.getNamespaceURI(), ns1.getPrefix());
+        AttributeHelper.importOMAttribute(attr1, ome1);
+        assertNotSame(attr1, ome1.getAttribute(attr1.getQName()));
+        assertEquals(attr1.getAttributeValue(), ome1.getAttribute(attr1.getQName()).getAttributeValue());
+        
+        //Convert from DOOM to OM.
+        OMNamespace ns2 = doomf.createOMNamespace("http://nsurl","prefix");
+        OMAttribute attr2 = doomf.createOMAttribute("attr2",ns2,"attr2value");
+        
+        OMElement ome2 = omf.createOMElement("element", ns2.getNamespaceURI(), ns2.getPrefix());
+        AttributeHelper.importOMAttribute(attr2, ome2);
+        assertNotSame(attr2, ome2.getAttribute(attr2.getQName()));
+        assertEquals(attr2.getAttributeValue(), ome2.getAttribute(attr2.getQName()).getAttributeValue());
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org