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 2011/10/31 12:00:49 UTC

svn commit: r1195408 - 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/util/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ axiom-dom/src/ma...

Author: veithen
Date: Mon Oct 31 11:00:48 2011
New Revision: 1195408

URL: http://svn.apache.org/viewvc?rev=1195408&view=rev
Log:
Promoted the ElementHelper#getTextAsStream and ElementHelper#writeTextTo methods to OMElement to make them easier to find and to allow for further optimizations in non standard Axiom implementations.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithNonTextChildren.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithSingleTextNode.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithoutCaching.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextTo.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextToWithNonTextNodes.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetTextAsStreamWithNonDestructiveOMDataSource.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestWriteTextToWithNonDestructiveOMDataSource.java   (with props)
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/ElementHelperTest.java
Modified:
    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/OMXMLBuilderFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.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/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.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-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java

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=1195408&r1=1195407&r2=1195408&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 Mon Oct 31 11:00:48 2011
@@ -25,9 +25,12 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 
+import java.io.IOException;
 import java.io.OutputStream;
+import java.io.Reader;
 import java.io.Writer;
 import java.util.Iterator;
 
@@ -402,7 +405,56 @@ public interface OMElement extends OMNod
      *         If there are no child text nodes, an empty string is returned.
      */
     String getText();
+    
+    /**
+     * Returns a stream representing the concatenation of the text nodes that are children of a
+     * this element. The stream returned by this method produces exactly the same character
+     * sequence as the the stream created by the following expression:
+     * <pre>new StringReader(element.getText())</pre>
+     * <p>
+     * The difference is that the stream implementation returned by this method is optimized for
+     * performance and is guaranteed to have constant memory usage, provided that:
+     * <ol>
+     * <li>The method is not required to cache the content of the {@link OMElement}, i.e.
+     * <code>cache</code> is <code>false</code> or the element is an {@link OMSourcedElement} that
+     * is backed by a non destructive {@link OMDataSource}.
+     * <li>The underlying parser (or the implementation of the underlying {@link XMLStreamReader} in
+     * the case of an {@link OMSourcedElement}) is non coalescing. Note that this is not the default
+     * in Axiom and it may be necessary to configure the parser with
+     * {@link StAXParserConfiguration#NON_COALESCING}.
+     * </ol>
+     * 
+     * @param cache
+     *            whether to enable caching when accessing the element
+     * @return a stream representing the concatenation of the text nodes
+     * 
+     * @see #getText()
+     */
+    Reader getTextAsStream(boolean cache);
 
+    /**
+     * Write the content of the text nodes that are children of a given element to a {@link Writer}.
+     * If <code>cache</code> is true, this method has the same effect as the following instruction:
+     * <pre>out.write(element.getText())</pre>
+     * <p>
+     * The difference is that this method is guaranteed to have constant memory usage and is
+     * optimized for performance.
+     * 
+     * @param element
+     *            the element to read the text nodes from
+     * @param out
+     *            the stream to write the content to
+     * @param cache
+     *            whether to enable caching when accessing the element
+     * @throws OMException
+     *             if an error occurs when reading from the element
+     * @throws IOException
+     *             if an error occurs when writing to the stream
+     * 
+     * @see #getText()
+     */
+    void writeTextTo(Writer out, boolean cache) throws IOException;
+    
     /** OMText can contain its information as a QName as well. This will return the text as a QName */
     QName getTextAsQName();
     

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Mon Oct 31 11:00:48 2011
@@ -149,6 +149,24 @@ public class OMXMLBuilderFactory {
     
     /**
      * Create an object model builder that reads an XML document from the provided input stream
+     * using a specified object model factory and with the default parser configuration defined by
+     * {@link StAXParserConfiguration#DEFAULT}.
+     * 
+     * @param omFactory
+     *            the object model factory to use
+     * @param in
+     *            the input stream representing the XML document
+     * @param encoding
+     *            the charset encoding of the XML document or <code>null</code> if the parser should
+     *            determine the charset encoding
+     * @return the builder
+     */
+    public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, InputStream in, String encoding) {
+        return createOMBuilder(omFactory, StAXParserConfiguration.DEFAULT, in, encoding);
+    }
+    
+    /**
+     * Create an object model builder that reads an XML document from the provided input stream
      * using a specified object model factory and with a given parser configuration.
      * 
      * @param omFactory
@@ -160,7 +178,28 @@ public class OMXMLBuilderFactory {
      * @return the builder
      */
     public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, StAXParserConfiguration configuration, InputStream in) {
-        return omFactory.getMetaFactory().createOMBuilder(omFactory, configuration, new InputSource(in));
+        return createOMBuilder(omFactory, configuration, in, null);
+    }
+    
+    /**
+     * Create an object model builder that reads an XML document from the provided input stream
+     * using a specified object model factory and with a given parser configuration.
+     * 
+     * @param omFactory
+     *            the object model factory to use
+     * @param configuration
+     *            the parser configuration to use
+     * @param in
+     *            the input stream representing the XML document
+     * @param encoding
+     *            the charset encoding of the XML document or <code>null</code> if the parser should
+     *            determine the charset encoding
+     * @return the builder
+     */
+    public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, StAXParserConfiguration configuration, InputStream in, String encoding) {
+        InputSource is = new InputSource(in);
+        is.setEncoding(encoding);
+        return omFactory.getMetaFactory().createOMBuilder(omFactory, configuration, is);
     }
     
     /**

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?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- 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 Mon Oct 31 11:00:48 2011
@@ -20,18 +20,14 @@
 package org.apache.axiom.om.util;
 
 import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.ds.ByteArrayDataSource;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPHeaderBlock;
-import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 import org.apache.axiom.util.stax.xop.XOPUtils;
 
 import javax.xml.namespace.QName;
@@ -41,7 +37,6 @@ import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.Reader;
-import java.io.StringReader;
 import java.io.Writer;
 import java.util.Iterator;
 
@@ -208,89 +203,17 @@ public class ElementHelper {
     }
     
     /**
-     * Returns a stream representing the concatenation of the text nodes that are children of a
-     * given element. The stream returned by this method produces exactly the same character
-     * sequence as the the stream created by the following expression:
-     * <pre>new StringReader(element.getText())</pre>
-     * <p>
-     * The difference is that the stream implementation returned by this method is optimized for
-     * performance and is guaranteed to have constant memory usage, provided that:
-     * <ol>
-     * <li>The method is not required to cache the content of the {@link OMElement}, i.e.
-     * <code>cache</code> is <code>false</code> or the element is an {@link OMSourcedElement} that
-     * is backed by a non destructive {@link OMDataSource}.
-     * <li>The underlying parser (or the implementation of the underlying {@link XMLStreamReader} in
-     * the case of an {@link OMSourcedElement}) is non coalescing. Note that this is not the default
-     * in Axiom and it may be necessary to configure the parser with
-     * {@link StAXParserConfiguration#NON_COALESCING}.
-     * </ol>
-     * 
-     * @param element
-     *            the element to read the text nodes from
-     * @param cache
-     *            whether to enable caching when accessing the element
-     * @return a stream representing the concatenation of the text nodes
-     * 
-     * @see OMElement#getText()
+     * @deprecated Use {@link OMElement#getTextAsStream(boolean)} instead.
      */
     public static Reader getTextAsStream(OMElement element, boolean cache) {
-        // If the element is not an OMSourcedElement and has not more than one child, then the most
-        // efficient way to get the Reader is to build a StringReader
-        if (!(element instanceof OMSourcedElement) && (!cache || element.isComplete())) {
-            OMNode child = element.getFirstOMChild();
-            if (child == null) {
-                return new StringReader("");
-            } else if (child.getNextOMSibling() == null) {
-                return new StringReader(child instanceof OMText ? ((OMText)child).getText() : "");
-            }
-        }
-        // In all other cases, extract the data from the XMLStreamReader
-        try {
-            XMLStreamReader reader = element.getXMLStreamReader(cache);
-            if (reader.getEventType() == XMLStreamReader.START_DOCUMENT) {
-                reader.next();
-            }
-            return XMLStreamReaderUtils.getElementTextAsStream(reader, true);
-        } catch (XMLStreamException ex) {
-            throw new OMException(ex);
-        }
+        return element.getTextAsStream(cache);
     }
     
     /**
-     * Write the content of the text nodes that are children of a given element to a
-     * {@link Writer}.
-     * If <code>cache</code> is true, this method has the same effect as the following instruction:
-     * <pre>out.write(element.getText())</pre>
-     * The difference is that this method is guaranteed to have constant memory usage and is
-     * optimized for performance.
-     * 
-     * @param element the element to read the text nodes from
-     * @param out the stream to write the content to
-     * @param cache whether to enable caching when accessing the element
-     * @throws XMLStreamException if an error occurs when reading from the element
-     * @throws IOException if an error occurs when writing to the stream
-     * 
-     * @see OMElement#getText()
+     * @deprecated Use {@link OMElement#writeTextTo(Writer, boolean)} instead.
      */
     public static void writeTextTo(OMElement element, Writer out, boolean cache)
             throws XMLStreamException, IOException {
-        
-        XMLStreamReader reader = element.getXMLStreamReader(cache);
-        int depth = 0;
-        while (reader.hasNext()) {
-            switch (reader.next()) {
-                case XMLStreamReader.CHARACTERS:
-                case XMLStreamReader.CDATA:
-                    if (depth == 1) {
-                        out.write(reader.getText());
-                    }
-                    break;
-                case XMLStreamReader.START_ELEMENT:
-                    depth++;
-                    break;
-                case XMLStreamReader.END_ELEMENT:
-                    depth--;
-            }
-        }
+        element.writeTextTo(out, cache);
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java Mon Oct 31 11:00:48 2011
@@ -18,15 +18,26 @@
  */
 package org.apache.axiom.om.impl.common;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
 import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMText;
 import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
+import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 
 /**
  * Utility class with default implementations for some of the methods defined by the
@@ -47,4 +58,51 @@ public class OMElementImplUtil {
             return new LiveNamespaceContext(element);
         }
     }
+
+    public static Reader getTextAsStream(OMElement element, boolean cache) {
+        // If the element is not an OMSourcedElement and has not more than one child, then the most
+        // efficient way to get the Reader is to build a StringReader
+        if (!(element instanceof OMSourcedElement) && (!cache || element.isComplete())) {
+            OMNode child = element.getFirstOMChild();
+            if (child == null) {
+                return new StringReader("");
+            } else if (child.getNextOMSibling() == null) {
+                return new StringReader(child instanceof OMText ? ((OMText)child).getText() : "");
+            }
+        }
+        // In all other cases, extract the data from the XMLStreamReader
+        try {
+            XMLStreamReader reader = element.getXMLStreamReader(cache);
+            if (reader.getEventType() == XMLStreamReader.START_DOCUMENT) {
+                reader.next();
+            }
+            return XMLStreamReaderUtils.getElementTextAsStream(reader, true);
+        } catch (XMLStreamException ex) {
+            throw new OMException(ex);
+        }
+    }
+    
+    public static void writeTextTo(OMElement element, Writer out, boolean cache) throws IOException {
+        try {
+            XMLStreamReader reader = element.getXMLStreamReader(cache);
+            int depth = 0;
+            while (reader.hasNext()) {
+                switch (reader.next()) {
+                    case XMLStreamReader.CHARACTERS:
+                    case XMLStreamReader.CDATA:
+                        if (depth == 1) {
+                            out.write(reader.getText());
+                        }
+                        break;
+                    case XMLStreamReader.START_ELEMENT:
+                        depth++;
+                        break;
+                    case XMLStreamReader.END_ELEMENT:
+                        depth--;
+                }
+            }
+        } catch (XMLStreamException ex) {
+            throw new OMException(ex);
+        }
+    }
 }

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=1195408&r1=1195407&r2=1195408&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 Mon Oct 31 11:00:48 2011
@@ -55,6 +55,9 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -1006,6 +1009,10 @@ public class ElementImpl extends ParentN
         return childText;
     }
 
+    public Reader getTextAsStream(boolean cache) {
+        return OMElementImplUtil.getTextAsStream(this, cache);
+    }
+
     public QName getTextAsQName() {
         String childText = getTrimmedText();
         if (childText != null) {
@@ -1014,6 +1021,10 @@ public class ElementImpl extends ParentN
         return null;
     }
 
+    public void writeTextTo(Writer out, boolean cache) throws IOException {
+        OMElementImplUtil.writeTextTo(this, out, cache);
+    }
+
     public String getTrimmedText() {
         String childText = null;
         OMNode child = this.getFirstOMChild();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Mon Oct 31 11:00:48 2011
@@ -39,7 +39,7 @@ import org.apache.axiom.ts.om.node.TestI
 
 public class OMImplementationTest extends TestCase {
     public static TestSuite suite() {
-        OMTestSuiteBuilder builder = new OMTestSuiteBuilder(new OMDOMMetaFactory());
+        OMTestSuiteBuilder builder = new OMTestSuiteBuilder(new OMDOMMetaFactory(), false);
         // OMElement#setText(QName) is unsupported
         builder.exclude(TestSetTextQName.class);
         builder.exclude(TestSetTextQNameWithEmptyPrefix.class);

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=1195408&r1=1195407&r2=1195408&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 Mon Oct 31 11:00:48 2011
@@ -59,7 +59,10 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.sax.SAXSource;
 
+import java.io.IOException;
+import java.io.Reader;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -854,6 +857,10 @@ public class OMElementImpl extends OMNod
         }
     }
 
+    public Reader getTextAsStream(boolean cache) {
+        return OMElementImplUtil.getTextAsStream(this, cache);
+    }
+
     public QName getTextAsQName() {
         String childText = getTrimmedText();
         if (childText != null) {
@@ -862,6 +869,10 @@ public class OMElementImpl extends OMNod
         return null;
     }
 
+    public void writeTextTo(Writer out, boolean cache) throws IOException {
+        OMElementImplUtil.writeTextTo(this, out, cache);
+    }
+
     /**
      * Returns the concatination string of TRIMMED values of all OMText  child nodes of this
      * element. This is included purely to improve usability.

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=1195408&r1=1195407&r2=1195408&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 Mon Oct 31 11:00:48 2011
@@ -47,6 +47,7 @@ import javax.xml.transform.sax.SAXSource
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.Reader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Iterator;
@@ -552,6 +553,10 @@ public class OMSourcedElementImpl extend
         return super.getText();
     }
 
+    public Reader getTextAsStream(boolean cache) {
+        return super.getTextAsStream(cache);
+    }
+
     /* (non-Javadoc)
      * @see org.apache.axiom.om.OMElement#getTextAsQName()
      */
@@ -560,6 +565,10 @@ public class OMSourcedElementImpl extend
         return super.getTextAsQName();
     }
 
+    public void writeTextTo(Writer out, boolean cache) throws IOException {
+        super.writeTextTo(out, cache);
+    }
+
     /* (non-Javadoc)
      * @see org.apache.axiom.om.OMElement#getLocalName()
      */

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java Mon Oct 31 11:00:48 2011
@@ -32,7 +32,7 @@ import org.apache.axiom.ts.om.node.TestI
 
 public class OMImplementationTest extends TestCase {
     public static TestSuite suite() {
-        OMTestSuiteBuilder builder = new OMTestSuiteBuilder(new OMLinkedListMetaFactory());
+        OMTestSuiteBuilder builder = new OMTestSuiteBuilder(new OMLinkedListMetaFactory(), true);
         // TODO: Axiom should throw an exception if an attempt is made to create a cyclic parent-child relationship
         builder.exclude(TestInsertSiblingAfterOnChild.class);
         builder.exclude(TestInsertSiblingBeforeOnChild.class);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1195408&r1=1195407&r2=1195408&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Mon Oct 31 11:00:48 2011
@@ -42,9 +42,11 @@ public class OMTestSuiteBuilder extends 
         new SerializeToOutputStream(false) };
     
     private final OMMetaFactory metaFactory;
+    private final boolean supportsOMSourcedElement;
     
-    public OMTestSuiteBuilder(OMMetaFactory metaFactory) {
+    public OMTestSuiteBuilder(OMMetaFactory metaFactory, boolean supportsOMSourcedElement) {
         this.metaFactory = metaFactory;
+        this.supportsOMSourcedElement = supportsOMSourcedElement;
     }
     
     protected void addTests() {
@@ -158,6 +160,9 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestGetQNameWithoutNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetText(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetTextAsQNameNoNamespace(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetTextAsStreamWithNonTextChildren(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetTextAsStreamWithoutCaching(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetTextAsStreamWithSingleTextNode(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetTextWithCDATASectionChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetTextWithMixedOMTextChildren(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement(metaFactory));
@@ -209,6 +214,8 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithEmptyPrefix(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithoutNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestUndeclarePrefix(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestWriteTextTo(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestWriteTextToWithNonTextNodes(metaFactory));
         addTest(new org.apache.axiom.ts.om.factory.TestCreateOMAttributeWithInvalidNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.factory.TestCreateOMCommentWithoutParent(metaFactory));
         addTest(new org.apache.axiom.ts.om.factory.TestCreateOMDocument(metaFactory));
@@ -253,6 +260,10 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnOrphan(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnSelf(metaFactory));
+        if (supportsOMSourcedElement) {
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
+        }
         addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestBase64Streaming(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestDigest(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithNonTextChildren.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithNonTextChildren.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithNonTextChildren.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithNonTextChildren.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.element;
+
+import java.io.Reader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.commons.io.IOUtils;
+
+public class TestGetTextAsStreamWithNonTextChildren extends AxiomTestCase {
+    public TestGetTextAsStreamWithNonTextChildren(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a>A<b>B</b>C</a>");
+        Reader in = element.getTextAsStream(true);
+        assertEquals(element.getText(), IOUtils.toString(in));
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithSingleTextNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithSingleTextNode.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithSingleTextNode.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithSingleTextNode.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.element;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.commons.io.IOUtils;
+
+public class TestGetTextAsStreamWithSingleTextNode extends AxiomTestCase {
+    public TestGetTextAsStreamWithSingleTextNode(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("a"));
+        factory.createOMText(element, "test");
+        Reader in = element.getTextAsStream(true);
+        assertTrue(in instanceof StringReader);
+        assertEquals(element.getText(), IOUtils.toString(in));
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithoutCaching.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithoutCaching.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithoutCaching.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextAsStreamWithoutCaching.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.element;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.SequenceInputStream;
+import java.util.Vector;
+
+import javax.activation.DataSource;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.testutils.activation.RandomDataSource;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestGetTextAsStreamWithoutCaching extends AxiomTestCase {
+    public TestGetTextAsStreamWithoutCaching(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        DataSource ds = new RandomDataSource(654321, 64, 128, 20000000);
+        Vector/*<InputStream>*/ v = new Vector/*<InputStream>*/();
+        v.add(new ByteArrayInputStream("<a>".getBytes("ascii")));
+        v.add(ds.getInputStream());
+        v.add(new ByteArrayInputStream("</a>".getBytes("ascii")));
+        OMElement element = OMXMLBuilderFactory.createOMBuilder(factory,
+                StAXParserConfiguration.NON_COALESCING,
+                new SequenceInputStream(v.elements()), "ascii").getDocumentElement();
+        Reader in = element.getTextAsStream(false);
+        IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), "ascii"), in);
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextTo.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextTo.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextTo.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextTo.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.element;
+
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestWriteTextTo extends AxiomTestCase {
+    public TestWriteTextTo(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("a"));
+        factory.createOMText(element, "test");
+        StringWriter out = new StringWriter();
+        element.writeTextTo(out, true);
+        assertEquals(element.getText(), out.toString());
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextToWithNonTextNodes.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextToWithNonTextNodes.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextToWithNonTextNodes.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestWriteTextToWithNonTextNodes.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.element;
+
+import java.io.StringWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestWriteTextToWithNonTextNodes extends AxiomTestCase {
+    public TestWriteTextToWithNonTextNodes(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a>A<b>B</b>C</a>");
+        StringWriter out = new StringWriter();
+        element.writeTextTo(out, true);
+        assertEquals(element.getText(), out.toString());
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetTextAsStreamWithNonDestructiveOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetTextAsStreamWithNonDestructiveOMDataSource.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetTextAsStreamWithNonDestructiveOMDataSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetTextAsStreamWithNonDestructiveOMDataSource.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,54 @@
+/*
+ * 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.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.nio.charset.Charset;
+
+import javax.activation.DataSource;
+import javax.xml.namespace.QName;
+
+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.testutils.activation.RandomDataSource;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestGetTextAsStreamWithNonDestructiveOMDataSource extends AxiomTestCase {
+    public TestGetTextAsStreamWithNonDestructiveOMDataSource(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
+        QName qname = new QName("a");
+        Charset cs = Charset.forName("ascii");
+        OMSourcedElement element = factory.createOMElement(
+                new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
+        Reader in = element.getTextAsStream(true);
+        assertFalse(in instanceof StringReader);
+        IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
+        assertFalse(element.isExpanded());
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestWriteTextToWithNonDestructiveOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestWriteTextToWithNonDestructiveOMDataSource.java?rev=1195408&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestWriteTextToWithNonDestructiveOMDataSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestWriteTextToWithNonDestructiveOMDataSource.java Mon Oct 31 11:00:48 2011
@@ -0,0 +1,54 @@
+/*
+ * 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.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import javax.activation.DataSource;
+import javax.xml.namespace.QName;
+
+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.testutils.activation.RandomDataSource;
+import org.apache.axiom.testutils.io.CharacterStreamComparator;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestWriteTextToWithNonDestructiveOMDataSource extends AxiomTestCase {
+    public TestWriteTextToWithNonDestructiveOMDataSource(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
+        QName qname = new QName("a");
+        OMSourcedElement element = factory.createOMElement(
+                new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
+        Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
+        Writer out = new CharacterStreamComparator(in);
+        element.writeTextTo(out, true); // cache doesn't matter here
+        out.close();
+        assertFalse(element.isExpanded());
+    }
+}

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