ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1339085 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/
Date Wed, 16 May 2012 09:35:27 GMT
Author: veithen
Date: Wed May 16 09:35:26 2012
New Revision: 1339085

URL: http://svn.apache.org/viewvc?rev=1339085&view=rev
Log:
Fixed a couple of issues in the cloneOMElement code.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1339085&r1=1339084&r2=1339085&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Wed May 16 09:35:26 2012
@@ -1027,7 +1027,7 @@ public class OMElementImpl extends OMNod
         if (options.isPreserveModel()) {
             targetElement = createClone(options, targetParent);
         } else {
-            targetElement = factory.createOMElement(localName, ns, targetParent);
+            targetElement = factory.createOMElement(getLocalName(), getNamespace(), targetParent);
         }
         for (Iterator it = getAllDeclaredNamespaces(); it.hasNext(); ) {
             OMNamespace ns = (OMNamespace)it.next();
@@ -1044,7 +1044,7 @@ public class OMElementImpl extends OMNod
     }
 
     protected OMElement createClone(OMCloneOptions options, OMContainer targetParent) {
-        return factory.createOMElement(localName, ns, targetParent);
+        return factory.createOMElement(getLocalName(), getNamespace(), targetParent);
     }
     
     public void setLineNumber(int lineNumber) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1339085&r1=1339084&r2=1339085&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Wed May 16 09:35:26 2012
@@ -672,7 +672,8 @@ public class OMSourcedElementImpl extend
         // If already expanded or this is not an OMDataSourceExt, then
         // create a copy of the OM Tree
         OMDataSource ds = getDataSource();
-        if (ds == null || 
+        if (!options.isCopyOMDataSources() ||
+            ds == null || 
             isExpanded() || 
             !(ds instanceof OMDataSourceExt)) {
             return super.clone(options, targetParent);
@@ -697,7 +698,9 @@ public class OMSourcedElementImpl extend
                                     getLocalName(), 
                                     getNamespace());
         }
-        targetParent.addChild(targetOMSE);
+        if (targetParent != null) {
+            targetParent.addChild(targetOMSE);
+        }
         return targetOMSE;
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1339085&r1=1339084&r2=1339085&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Wed May 16 09:35:26 2012
@@ -346,6 +346,8 @@ public class OMTestSuiteBuilder extends 
             }
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestByteArrayDS(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestCharArrayDS(metaFactory));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestCloneOMElementNonDestructive(metaFactory,
true));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestCloneOMElementNonDestructive(metaFactory,
false));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestComplete(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestExpand(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java?rev=1339085&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java
Wed May 16 09:35:26 2012
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.ts.om.sourcedelement;
+
+import java.nio.charset.Charset;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.attachments.ByteArrayDataSource;
+import org.apache.axiom.om.OMCloneOptions;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestCloneOMElementNonDestructive extends AxiomTestCase {
+    private final boolean copyOMDataSources;
+    
+    public TestCloneOMElementNonDestructive(OMMetaFactory metaFactory, boolean copyOMDataSources)
{
+        super(metaFactory);
+        this.copyOMDataSources = copyOMDataSources;
+        addTestProperty("copyOMDataSources", String.valueOf(copyOMDataSources));
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"),
+                new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
+        OMSourcedElement element = factory.createOMElement(ds);
+        OMCloneOptions options = new OMCloneOptions();
+        options.setCopyOMDataSources(copyOMDataSources);
+        OMElement clone = element.cloneOMElement(options);
+        if (copyOMDataSources) {
+            assertTrue(clone instanceof OMSourcedElement);
+            assertFalse(element.isExpanded());
+        } else {
+            assertFalse(clone instanceof OMSourcedElement);
+            assertTrue(clone.isComplete());
+        }
+        assertEquals("test", clone.getText());
+        assertEquals("wrapper", clone.getLocalName());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestCloneOMElementNonDestructive.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message