ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1054414 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/impl/ axiom-api/src/main/java/org/apache/axiom/om/impl/util/ axiom-dom/src/main/java/or...
Date Sun, 02 Jan 2011 14:29:33 GMT
Author: veithen
Date: Sun Jan  2 14:29:32 2011
New Revision: 1054414

URL: http://svn.apache.org/viewvc?rev=1054414&view=rev
Log:
Fixed AXIOM-24 by reusing code/concepts from the OMElement implementations.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsume.java
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    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-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
Sun Jan  2 14:29:32 2011
@@ -33,6 +33,12 @@ import java.util.Iterator;
  * <p>Exposes the ability to add, find, and iterate over the children of a document
or element.</p>
  */
 public interface OMContainer extends OMSerializable {
+    /**
+     * Returns the builder object.
+     *
+     * @return Returns the builder object used to construct the underlying XML infoset on
the fly.
+     */
+    OMXMLParserWrapper getBuilder();
 
     /**
      * Adds the given node as the last child. One must preserve the order of children, in
this

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
Sun Jan  2 14:29:32 2011
@@ -267,13 +267,6 @@ public interface OMElement extends OMNod
     void setBuilder(OMXMLParserWrapper wrapper);
 
     /**
-     * Returns the builder object.
-     *
-     * @return Returns the builder object used to construct the underlying XML infoset on
the fly.
-     */
-    OMXMLParserWrapper getBuilder();
-
-    /**
      * Sets the first child.
      *
      * @param node

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
Sun Jan  2 14:29:32 2011
@@ -19,12 +19,13 @@
 
 package org.apache.axiom.om.impl;
 
-import java.util.Iterator;
-
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
 
 /**
  * Utility class with default implementations for some of the methods defined by the
@@ -55,11 +56,14 @@ public class OMDocumentImplUtil {
             }
         }
 
-        Iterator children = document.getChildren();
-
-        while (children.hasNext()) {
-            OMNodeEx omNode = (OMNodeEx) children.next();
-            omNode.internalSerialize(writer, cache);
+        if (cache || document.isComplete() || document.getBuilder() == null) {
+            OMSerializerUtil.serializeChildren(document, writer, cache);
+        } else {
+            StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
+            XMLStreamReader reader = document.getXMLStreamReaderWithoutCaching();
+            while (reader.getEventType() != XMLStreamReader.END_DOCUMENT) {
+                streamingOMSerializer.serialize(reader, writer);
+            }
         }
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
Sun Jan  2 14:29:32 2011
@@ -20,10 +20,12 @@
 package org.apache.axiom.om.impl.util;
 
 import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
 import org.apache.axiom.om.util.CommonUtils;
 import org.apache.commons.logging.Log;
@@ -556,6 +558,29 @@ public class OMSerializerUtil {
         }
     }
 
+    public static void serializeChildren(OMContainer container, XMLStreamWriter writer,
+            boolean cache) throws XMLStreamException {
+        if (cache) {
+            Iterator children = container.getChildren();
+            while (children.hasNext()) {
+                ((OMNodeEx) children.next()).internalSerialize(writer, true);
+            }
+        } else {
+            OMNodeEx child = (OMNodeEx)container.getFirstOMChild();
+            while (child != null) {
+                if ((!(child instanceof OMElement)) || child.isComplete() ||
+                        ((OMElement)child).getBuilder() == null) {
+                    child.internalSerialize(writer, false);
+                } else {
+                    OMElement element = (OMElement) child;
+                    element.getBuilder().setCache(false);
+                    serializeByPullStream(element, writer, cache);
+                }
+                child = (OMNodeEx)child.getNextOMSiblingIfAvailable();
+            }
+        }
+    }
+
     /**
      * Get the next prefix name
      * @return next prefix name

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Sun Jan  2 14:29:32 2011
@@ -28,7 +28,6 @@ import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
 import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
 import org.apache.axiom.om.impl.traverse.OMDescendantsIterator;
@@ -892,15 +891,6 @@ public class ElementImpl extends ParentN
         return (attr == null) ? null : attr.getAttributeValue();
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.axiom.om.OMElement#getBuilder()
-     */
-    public OMXMLParserWrapper getBuilder() {
-        return this.builder;
-    }
-
     /**
      * Returns the first Element node.
      *
@@ -1076,44 +1066,12 @@ public class ElementImpl extends ParentN
     public void internalSerialize(XMLStreamWriter writer,
                                      boolean cache) throws XMLStreamException {
 
-        if (cache) {
-            // in this case we don't care whether the elements are built or not
-            // we just call the serializeAndConsume methods
+        if (cache || this.done || (this.builder == null)) {
             OMSerializerUtil.serializeStartpart(this, writer);
-            // serilize children
-            Iterator children = this.getChildren();
-            while (children.hasNext()) {
-                ((OMNodeEx) children.next()).internalSerialize(writer, true);
-            }
+            OMSerializerUtil.serializeChildren(this, writer, cache);
             OMSerializerUtil.serializeEndpart(writer);
-
         } else {
-            // Now the caching is supposed to be off. However caching been
-            // switched off
-            // has nothing to do if the element is already built!
-            if (this.done) {
-                OMSerializerUtil.serializeStartpart(this, writer);
-                ChildNode child = this.firstChild;
-                while (child != null
-                        && ((!(child instanceof OMElement)) || child
-                        .isComplete())) {
-                    child.internalSerialize(writer, false);
-                    child = child.nextSibling;
-                }
-                if (child != null) {
-                    OMElement element = (OMElement) child;
-                    element.getBuilder().setCache(false);
-                    OMSerializerUtil.serializeByPullStream(element, writer,
-                                                           cache);
-                }
-                OMSerializerUtil.serializeEndpart(writer);
-            } else {
-                // take the XMLStream reader and feed it to the stream
-                // serilizer.
-                // todo is this right ?????
-                OMSerializerUtil.serializeByPullStream(this, writer, cache);
-            }
-
+            OMSerializerUtil.serializeByPullStream(this, writer, cache);
         }
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
Sun Jan  2 14:29:32 2011
@@ -27,6 +27,7 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMProcessingInstruction;
 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.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
@@ -65,6 +66,10 @@ public abstract class ParentNode extends
     // /OMContainer methods
     // /
 
+    public OMXMLParserWrapper getBuilder() {
+        return this.builder;
+    }
+
     public void addChild(OMNode omNode) {
         if (omNode.getOMFactory() instanceof OMDOMFactory) {
             Node domNode = (Node) omNode;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
Sun Jan  2 14:29:32 2011
@@ -95,6 +95,10 @@ public class OMDocumentImpl extends OMSe
         this.builder = parserWrapper;
     }
 
+    public OMXMLParserWrapper getBuilder() {
+        return builder;
+    }
+
     /**
      * Method getDocumentElement.
      *

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=1054414&r1=1054413&r2=1054414&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
Sun Jan  2 14:29:32 2011
@@ -870,40 +870,12 @@ public class OMElementImpl extends OMNod
     public void internalSerialize(XMLStreamWriter writer, boolean cache)
             throws XMLStreamException {
 
-        if (cache) {
-            //in this case we don't care whether the elements are built or not
-            //we just call the serializeAndConsume methods
+        if (cache || this.done || (this.builder == null)) {
             OMSerializerUtil.serializeStartpart(this, writer);
-            //serialize children
-            Iterator children = this.getChildren();
-            while (children.hasNext()) {
-                ((OMNodeEx) children.next()).internalSerialize(writer, true);
-            }
+            OMSerializerUtil.serializeChildren(this, writer, cache);
             OMSerializerUtil.serializeEndpart(writer);
-
         } else {
-            //Now the caching is supposed to be off. However caching been switched off
-            //has nothing to do if the element is already built!
-            if (this.done || (this.builder == null)) {
-                OMSerializerUtil.serializeStartpart(this, writer);
-                OMNodeImpl child = (OMNodeImpl) firstChild;
-                while (child != null) {
-                    if ((!(child instanceof OMElement)) || child.isComplete() ||
-                            child.builder == null) {
-                        child.internalSerialize(writer, false);
-                    } else {
-                        OMElement element = (OMElement) child;
-                        element.getBuilder().setCache(false);
-                        OMSerializerUtil.serializeByPullStream(element, writer, cache);
-                    }
-                    child = child.nextSibling;
-                }
-                OMSerializerUtil.serializeEndpart(writer);
-            } else {
-                OMSerializerUtil.serializeByPullStream(this, writer, cache);
-            }
-
-
+            OMSerializerUtil.serializeByPullStream(this, writer, cache);
         }
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
Sun Jan  2 14:29:32 2011
@@ -32,7 +32,7 @@ public abstract class AxiomTestCase exte
     }
     
     protected void assertConsumed(OMContainer container) {
-        assertFalse(container.isComplete());
+        assertFalse("Expected the node to be incomplete", container.isComplete());
         boolean isConsumed;
         try {
             container.serialize(new NullOutputStream());

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java?rev=1054414&r1=1054413&r2=1054414&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
Sun Jan  2 14:29:32 2011
@@ -45,6 +45,7 @@ public class AxiomTestSuiteBuilder {
         addTest(new org.apache.axiom.ts.om.attribute.TestGetQName(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
+        addTest(new org.apache.axiom.ts.om.document.TestSerializeAndConsume(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
         for (int i=0; i<conformanceFiles.length; i++) {
             addTest(new org.apache.axiom.ts.om.document.TestGetXMLStreamReader(metaFactory,
conformanceFiles[i], true));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsume.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsume.java?rev=1054414&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsume.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestSerializeAndConsume.java
Sun Jan  2 14:29:32 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.document;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.commons.io.output.NullOutputStream;
+
+/**
+ * Tests the behavior of {@link OMDocument#serializeAndConsume(java.io.OutputStream))}. This
is a
+ * regression test for <a href="https://issues.apache.org/jira/browse/AXIOM-24">AXIOM-24</a>.
+ */
+public class TestSerializeAndConsume extends AxiomTestCase {
+    public TestSerializeAndConsume(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory,
+                new StringReader("<elem>text</elem>")).getDocument();
+        document.serializeAndConsume(new NullOutputStream());
+        assertConsumed(document);
+    }
+}

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



Mime
View raw message