ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1700886 - in /webservices/axiom/trunk: 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/impl/dom/ implem...
Date Wed, 02 Sep 2015 20:07:48 GMT
Author: veithen
Date: Wed Sep  2 20:07:47 2015
New Revision: 1700886

URL: http://svn.apache.org/r1700886
Log:
Fix an issue in the implementation of the build() method.

Added:
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
  (with props)
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomContainerSupport.aj
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareElement.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
Wed Sep  2 20:07:47 2015
@@ -126,6 +126,7 @@ public aspect CoreParentNodeSupport {
     public final void CoreParentNode.coreAppendChild(CoreChildNode child, boolean fromBuilder)
{
         CoreParentNode parent = child.coreGetParent();
         if (!fromBuilder) {
+            // TODO: this is wrong; we only need to build the node locally, but build() builds
incomplete children as well
             build();
         }
         Content content = getContent(true);

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomContainerSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomContainerSupport.aj?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomContainerSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomContainerSupport.aj
Wed Sep  2 20:07:47 2015
@@ -145,23 +145,32 @@ public aspect AxiomContainerSupport {
         }
     }
     
-    public void AxiomContainer.defaultBuild() {
+    public final void AxiomContainer.build() {
         OMXMLParserWrapper builder = getBuilder();
-        if (getState() == AxiomContainer.DISCARDED) {
-            if (builder != null) {
-                ((StAXBuilder)builder).debugDiscarded(this);
+        // builder is null. Meaning this is a programatical created element but it has children
which are not completed
+        // Build them all.
+        if (builder == null && getState() == INCOMPLETE) {
+            for (Iterator childrenIterator = this.getChildren(); childrenIterator.hasNext();)
{
+                OMNode omNode = (OMNode) childrenIterator.next();
+                omNode.build();
             }
-            throw new NodeUnavailableException();
-        }
-        if (builder != null && builder.isCompleted()) {
-            log.debug("Builder is already complete.");
-        }
-        while (!isComplete()) {
-
-            builder.next();    
-            if (builder.isCompleted() && !isComplete()) {
-                log.debug("Builder is complete.  Setting OMObject to complete.");
-                setComplete(true);
+        } else {
+            if (getState() == AxiomContainer.DISCARDED) {
+                if (builder != null) {
+                    ((StAXBuilder)builder).debugDiscarded(this);
+                }
+                throw new NodeUnavailableException();
+            }
+            if (builder != null && builder.isCompleted()) {
+                log.debug("Builder is already complete.");
+            }
+            while (!isComplete()) {
+    
+                builder.next();    
+                if (builder.isCompleted() && !isComplete()) {
+                    log.debug("Builder is complete.  Setting OMObject to complete.");
+                    setComplete(true);
+                }
             }
         }
     }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Wed Sep  2 20:07:47 2015
@@ -232,10 +232,6 @@ public class DocumentImpl extends Parent
         throw new UnsupportedOperationException("TODO");
     }
 
-    public final void build() {
-        defaultBuild();
-    }
-
     public final void checkChild(OMNode child) {
         if (child instanceof OMElement) {
             if (getOMDocumentElement() != null) {

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareElement.java?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareElement.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSAwareElement.java
Wed Sep  2 20:07:47 2015
@@ -84,10 +84,6 @@ public class NSAwareElement extends Elem
         super.normalize(config);
     }
 
-    public final void build() {
-        defaultBuild();
-    }
-
     public final void checkChild(OMNode child) {
     }
 }

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
Wed Sep  2 20:07:47 2015
@@ -48,8 +48,4 @@ public class OMDocumentImpl extends OMSe
 
     protected void checkDocumentElement(OMElement element) {
     }
-
-    public void build() {
-        defaultBuild();
-    }
 }

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=1700886&r1=1700885&r2=1700886&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
Wed Sep  2 20:07:47 2015
@@ -41,25 +41,6 @@ public class OMElementImpl extends OMNod
     public void checkChild(OMNode child) {
     }
 
-    public final void build() throws OMException {
-        /**
-         * builder is null. Meaning this is a programatical created element but it has children
which are not completed
-         * Build them all.
-         */
-        if (getBuilder() == null && getState() == INCOMPLETE) {
-            for (Iterator childrenIterator = this.getChildren(); childrenIterator.hasNext();)
{
-                OMNode omNode = (OMNode) childrenIterator.next();
-                omNode.build();
-            }
-        } else {
-            defaultBuild();
-        }
-
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////////
-
     public final void setNamespace(OMNamespace namespace) {
         setNamespace(namespace, true);
     }

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1700886&r1=1700885&r2=1700886&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Wed Sep  2 20:07:47 2015
@@ -35,6 +35,7 @@ import org.apache.axiom.ts.dimension.Exp
 import org.apache.axiom.ts.dimension.NoNamespaceStrategy;
 import org.apache.axiom.ts.dimension.serialization.SerializationStrategy;
 import org.apache.axiom.ts.om.container.OMContainerExtractor;
+import org.apache.axiom.ts.om.container.OMContainerFactory;
 import org.apache.axiom.ts.om.factory.CreateOMElementParentSupplier;
 import org.apache.axiom.ts.om.factory.CreateOMElementVariant;
 import org.apache.axiom.ts.om.sourcedelement.OMSourcedElementVariant;
@@ -148,6 +149,9 @@ public class OMTestSuiteBuilder extends
                 }
             }
         }
+        for (OMContainerFactory cf : getInstances(OMContainerFactory.class)) {
+            addTest(new org.apache.axiom.ts.om.container.TestAddChildWithIncompleteSibling(metaFactory,
cf));
+        }
         addTest(new org.apache.axiom.ts.om.document.TestAddChildIncomplete(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestAddChildWithExistingDocumentElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestBuild(metaFactory));

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java?rev=1700886&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
(added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
Wed Sep  2 20:07:47 2015
@@ -0,0 +1,55 @@
+/*
+ * 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.container;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.testing.multiton.Multiton;
+import org.apache.axiom.testutils.suite.Dimension;
+import org.apache.axiom.testutils.suite.MatrixTestCase;
+
+public abstract class OMContainerFactory extends Multiton implements Dimension {
+    public static final OMContainerFactory DOCUMENT = new OMContainerFactory() {
+        @Override
+        public void addTestParameters(MatrixTestCase testCase) {
+            testCase.addTestParameter("container", "document");
+        }
+        
+        @Override
+        public OMContainer create(OMFactory factory) {
+            return factory.createOMDocument();
+        }
+    };
+    
+    public static final OMContainerFactory ELEMENT = new OMContainerFactory() {
+        @Override
+        public void addTestParameters(MatrixTestCase testCase) {
+            testCase.addTestParameter("container", "element");
+        }
+        
+        @Override
+        public OMContainer create(OMFactory factory) {
+            return factory.createOMElement("test", null);
+        }
+    };
+    
+    private OMContainerFactory() {}
+    
+    public abstract OMContainer create(OMFactory factory);
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java?rev=1700886&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java
(added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java
Wed Sep  2 20:07:47 2015
@@ -0,0 +1,58 @@
+/*
+ * 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.container;
+
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMContainer#addChild(OMNode)} works properly on a container that has
been
+ * created programmatically, but that has a child that is itself incomplete.
+ * <p>
+ * This is a regression test for an issue in older Axiom versions (where the
+ * {@link OMContainer#build()}) method would fail on {@link OMDocument} instances.
+ */
+public class TestAddChildWithIncompleteSibling extends AxiomTestCase {
+    private final OMContainerFactory containerFactory;
+    
+    public TestAddChildWithIncompleteSibling(OMMetaFactory metaFactory, OMContainerFactory
containerFactory) {
+        super(metaFactory);
+        this.containerFactory = containerFactory;
+        containerFactory.addTestParameters(this);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMContainer container = containerFactory.create(factory);
+        container.addChild(OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<a>test</a>")).getDocumentElement(true));
+        ASSERT.that(container.isComplete()).isFalse();
+        container.addChild(factory.createOMText("test"));
+        ASSERT.that(container).hasNumberOfChildren(2);
+    }
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestAddChildWithIncompleteSibling.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message