Author: veithen
Date: Sat May 23 20:29:40 2015
New Revision: 1681379

URL: http://svn.apache.org/r1681379
Log:
AXIOM-404: Add a detach() method to OMXMLParserWrapper that allows to detach 
the builder from its underlying source, so that the state of the source object 
can be safely changed. For each type of source object the implementation uses 
the optimal strategy.

Added:
    
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
   (with props)
    
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
   (with props)
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
      - copied, changed from r1676748, 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
   (with props)
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/DummyXMLReader.java
   (with props)
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithDOM.java
   (with props)
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithSAXSource.java
   (with props)
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithStream.java
   (with props)
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java
   (with props)
Removed:
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
Modified:
    
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
    
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
    
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
    
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
    
webservices/axiom/trunk/modules/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
    
webservices/axiom/trunk/testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/MIMESample.java
    
webservices/axiom/trunk/testing/xml-testsuite/src/main/java/org/apache/axiom/ts/xml/StreamType.java

Modified: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
 (original)
+++ 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
 Sat May 23 20:29:40 2015
@@ -21,6 +21,7 @@ package org.apache.axiom.om.impl.common.
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 import java.net.URL;
 
 import javax.xml.stream.XMLStreamException;
@@ -34,6 +35,7 @@ import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.builder.XOPAwareStAXOMBuilder;
 import org.apache.axiom.om.util.StAXParserConfiguration;
@@ -56,10 +58,12 @@ import org.xml.sax.InputSource;
 public abstract class AbstractOMMetaFactory implements OMMetaFactoryEx {
     private final static class SourceInfo {
         private final XMLStreamReader reader;
+        private final Detachable detachable;
         private final Closeable closeable;
         
-        SourceInfo(XMLStreamReader reader, Closeable closeable) {
+        SourceInfo(XMLStreamReader reader, Detachable detachable, Closeable 
closeable) {
             this.reader = reader;
+            this.detachable = detachable;
             this.closeable = closeable;
         }
 
@@ -67,38 +71,67 @@ public abstract class AbstractOMMetaFact
             return reader;
         }
 
+        Detachable getDetachable() {
+            return detachable;
+        }
+
         Closeable getCloseable() {
             return closeable;
         }
     }
     
-    private static SourceInfo createXMLStreamReader(StAXParserConfiguration 
configuration, InputSource is) {
+    private static SourceInfo createXMLStreamReader(StAXParserConfiguration 
configuration,
+            InputSource is, boolean makeDetachable) {
         XMLStreamReader reader;
+        Detachable detachable;
         Closeable closeable;
         try {
             if (is.getByteStream() != null) {
                 String systemId = is.getSystemId();
                 String encoding = is.getEncoding();
+                InputStream in = is.getByteStream();
+                if (makeDetachable) {
+                    DetachableInputStream detachableInputStream = new 
DetachableInputStream(in, false);
+                    in = detachableInputStream;
+                    detachable = detachableInputStream;
+                } else {
+                    detachable = null;
+                }
                 if (systemId != null) {
                     if (encoding == null) {
-                        reader = 
StAXUtils.createXMLStreamReader(configuration, systemId, is.getByteStream());
+                        reader = 
StAXUtils.createXMLStreamReader(configuration, systemId, in);
                     } else {
                         throw new UnsupportedOperationException();
                     }
                 } else {
                     if (encoding == null) {
-                        reader = 
StAXUtils.createXMLStreamReader(configuration, is.getByteStream());
+                        reader = 
StAXUtils.createXMLStreamReader(configuration, in);
                     } else {
-                        reader = 
StAXUtils.createXMLStreamReader(configuration, is.getByteStream(), encoding);
+                        reader = 
StAXUtils.createXMLStreamReader(configuration, in, encoding);
                     }
                 }
                 closeable = null;
             } else if (is.getCharacterStream() != null) {
-                reader = StAXUtils.createXMLStreamReader(configuration, 
is.getCharacterStream());
+                Reader in = is.getCharacterStream();
+                if (makeDetachable) {
+                    DetachableReader detachableReader = new 
DetachableReader(in);
+                    in = detachableReader;
+                    detachable = detachableReader;
+                } else {
+                    detachable = null;
+                }
+                reader = StAXUtils.createXMLStreamReader(configuration, in);
                 closeable = null;
             } else {
                 String systemId = is.getSystemId();
                 InputStream in = new 
URL(systemId).openConnection().getInputStream();
+                if (makeDetachable) {
+                    DetachableInputStream detachableInputStream = new 
DetachableInputStream(in, true);
+                    in = detachableInputStream;
+                    detachable = detachableInputStream;
+                } else {
+                    detachable = null;
+                }
                 reader = StAXUtils.createXMLStreamReader(configuration, 
systemId, in);
                 closeable = in;
             }
@@ -107,7 +140,7 @@ public abstract class AbstractOMMetaFact
         } catch (IOException ex) {
             throw new OMException(ex);
         }
-        return new SourceInfo(reader, closeable);
+        return new SourceInfo(reader, detachable, closeable);
     }
     
     private static XMLStreamReader getXMLStreamReader(XMLStreamReader 
originalReader) {
@@ -128,9 +161,9 @@ public abstract class AbstractOMMetaFact
     }
 
     public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputSource is) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, is);
+        SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
         StAXOMBuilder builder = new StAXOMBuilder(omFactory, 
sourceInfo.getReader(),
-                sourceInfo.getCloseable());
+                sourceInfo.getDetachable(), sourceInfo.getCloseable());
         builder.setAutoClose(true);
         return builder;
     }
@@ -173,30 +206,38 @@ public abstract class AbstractOMMetaFact
 
     public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration 
configuration,
             OMFactory omFactory, InputSource rootPart, MimePartProvider 
mimePartProvider) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart);
-        XOPAwareStAXOMBuilder builder = new XOPAwareStAXOMBuilder(omFactory, 
sourceInfo.getReader(),
-                mimePartProvider, sourceInfo.getCloseable());
+        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, 
false);
+        XOPAwareStAXOMBuilder builder = new XOPAwareStAXOMBuilder(
+                omFactory,
+                sourceInfo.getReader(),
+                mimePartProvider,
+                mimePartProvider instanceof Detachable ? 
(Detachable)mimePartProvider : null,
+                sourceInfo.getCloseable());
         builder.setAutoClose(true);
         return builder;
     }
 
     public SOAPModelBuilder createStAXSOAPModelBuilder(XMLStreamReader parser) 
{
-        return new StAXSOAPModelBuilder(this, getXMLStreamReader(parser));
+        return new StAXSOAPModelBuilder(this, getXMLStreamReader(parser), 
null, null);
     }
 
     public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration 
configuration, InputSource is) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, is);
+        SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
         StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(this, 
sourceInfo.getReader(),
-                sourceInfo.getCloseable());
+                sourceInfo.getDetachable(), sourceInfo.getCloseable());
         builder.setAutoClose(true);
         return builder;
     }
 
     public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration 
configuration,
             SOAPFactory soapFactory, InputSource rootPart, MimePartProvider 
mimePartProvider) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart);
-        MTOMStAXSOAPModelBuilder builder = new 
MTOMStAXSOAPModelBuilder(soapFactory,
-                sourceInfo.getReader(), mimePartProvider, 
sourceInfo.getCloseable());
+        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, 
false);
+        MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(
+                soapFactory,
+                sourceInfo.getReader(),
+                mimePartProvider,
+                mimePartProvider instanceof Detachable ? 
(Detachable)mimePartProvider : null,
+                sourceInfo.getCloseable());
         builder.setAutoClose(true);
         return builder;
     }

Added: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
 (added)
+++ 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,79 @@
+/*
+ * 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.om.impl.common.factory;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
+import org.apache.axiom.ext.io.StreamCopyException;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.impl.builder.Detachable;
+
+final class DetachableInputStream extends InputStream implements Detachable {
+    private InputStream target;
+    private final boolean closeOnDetach;
+
+    DetachableInputStream(InputStream target, boolean closeOnDetach) {
+        this.target = target;
+        this.closeOnDetach = closeOnDetach;
+    }
+
+    public int read() throws IOException {
+        return target.read();
+    }
+
+    public int read(byte[] b) throws IOException {
+        return target.read(b);
+    }
+
+    public int read(byte[] b, int off, int len) throws IOException {
+        return target.read(b, off, len);
+    }
+
+    public long skip(long n) throws IOException {
+        return target.skip(n);
+    }
+
+    public int available() throws IOException {
+        return target.available();
+    }
+
+    public void close() throws IOException {
+        target.close();
+    }
+
+    public void detach() throws OMException {
+        MemoryBlob blob = Blobs.createMemoryBlob();
+        try {
+            blob.readFrom(target);
+        } catch (StreamCopyException ex) {
+            throw new OMException(ex.getCause());
+        }
+        if (closeOnDetach) {
+            try {
+                target.close();
+            } catch (IOException ex) {
+                throw new OMException(ex);
+            }
+        }
+        target = blob.readOnce();
+    }
+}

Propchange: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
 (added)
+++ 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,86 @@
+/*
+ * 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.om.impl.common.factory;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.impl.builder.Detachable;
+
+final class DetachableReader extends Reader implements Detachable {
+    private static final Charset UTF8 = Charset.forName("UTF-8");
+    
+    private Reader target;
+
+    DetachableReader(Reader target) {
+        this.target = target;
+    }
+
+    public int read(CharBuffer target) throws IOException {
+        return target.read(target);
+    }
+
+    public int read() throws IOException {
+        return target.read();
+    }
+
+    public int read(char[] cbuf) throws IOException {
+        return target.read(cbuf);
+    }
+
+    public int read(char[] cbuf, int off, int len) throws IOException {
+        return target.read(cbuf, off, len);
+    }
+
+    public long skip(long n) throws IOException {
+        return target.skip(n);
+    }
+
+    public boolean ready() throws IOException {
+        return target.ready();
+    }
+
+    public void close() throws IOException {
+        target.close();
+    }
+    
+    public void detach() {
+        MemoryBlob blob = Blobs.createMemoryBlob();
+        Writer out = new OutputStreamWriter(blob.getOutputStream(), UTF8);
+        char[] buffer = new char[2048];
+        int c;
+        try {
+            while ((c = target.read(buffer)) != -1) {
+                out.write(buffer, 0, c);
+            }
+            out.close();
+        } catch (IOException ex) {
+            throw new OMException(ex);
+        }
+        target = new InputStreamReader(blob.readOnce(), UTF8);
+    }
+}

Propchange: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/DetachableReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
 (original)
+++ 
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
 Sat May 23 20:29:40 2015
@@ -181,4 +181,9 @@ public class SAXOMBuilder extends OMCont
             String replacementText) {
         factory.createOMEntityReference(parent, name, replacementText, true);
     }
+    
+    public void detach() {
+        // Force processing of the SAX source
+        getDocument();
+    }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
 Sat May 23 20:29:40 2015
@@ -29,7 +29,7 @@ import javax.xml.transform.sax.SAXSource
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.mime.ContentType;
-import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
+import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPModelBuilder;
@@ -454,7 +454,7 @@ public class OMXMLBuilderFactory {
         }
         InputSource rootPart = getRootPartInputSource(attachments, 
contentType);
         return omFactory.getMetaFactory().createOMBuilder(configuration, 
omFactory,
-                rootPart, new 
OMAttachmentAccessorMimePartProvider(attachments));
+                rootPart, new AttachmentsMimePartProvider(attachments));
     }
     
     /**
@@ -610,7 +610,7 @@ public class OMXMLBuilderFactory {
         }
         InputSource rootPart = getRootPartInputSource(attachments, 
contentType);
         return 
metaFactory.createSOAPModelBuilder(StAXParserConfiguration.SOAP, soapFactory,
-                rootPart, new 
OMAttachmentAccessorMimePartProvider(attachments));
+                rootPart, new AttachmentsMimePartProvider(attachments));
     }
     
     private static InputSource getRootPartInputSource(Attachments attachments, 
ContentType contentType) {

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLParserWrapper.java
 Sat May 23 20:29:40 2015
@@ -19,6 +19,16 @@
 
 package org.apache.axiom.om;
 
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.axiom.attachments.Attachments;
+import org.w3c.dom.Node;
+
 /** Interface OMXMLParserWrapper */
 public interface OMXMLParserWrapper {
     /**
@@ -152,4 +162,39 @@ public interface OMXMLParserWrapper {
      * <b>not</b> close the underlying input source.
      */
     void close();
+    
+    /**
+     * Detach this builder from its underlying source, so that the state of 
the source object can be
+     * changed without impact on the object model produced by this builder. 
The effect of this
+     * method depends on the type of source object passed to {@link 
OMXMLBuilderFactory} to create
+     * the builder:
+     * <p>
+     * <table border="2" rules="all" cellpadding="4" cellspacing="0">
+     * <tr>
+     * <th>Source object type</th>
+     * <th>Action performed by this method</th>
+     * </tr>
+     * <tr>
+     * <td>{@link InputStream}, {@link Reader}, {@link StreamSource} with 
{@link InputStream} or
+     * {@link Reader}</td>
+     * <td>The remaining unprocessed content of the stream is read into memory 
so that it can be
+     * safely closed. Note that this method doesn't close the stream; this is 
the responsibility of
+     * the caller.</td>
+     * </tr>
+     * <tr>
+     * <td>{@link StreamSource} with system ID and no stream</td>
+     * <td>The remaining unprocessed content of the document is read into 
memory and the associated
+     * stream is closed.</td>
+     * <tr>
+     * <td>{@link Node}, {@link DOMSource}, {@link SAXSource}</td>
+     * <td>The object model is built completely.</td>
+     * </tr>
+     * <tr>
+     * <td>{@link Attachments}</td>
+     * <td>All MIME parts are fetched so that the stream from which the {@link 
Attachments} object
+     * has been created can safely be closed.</td>
+     * </tr>
+     * </table>
+     */
+    void detach();
 }

Copied: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
 (from r1676748, 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java)
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java?p2=webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java&p1=webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java&r1=1676748&r2=1681379&rev=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMAttachmentAccessorMimePartProvider.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/AttachmentsMimePartProvider.java
 Sat May 23 20:29:40 2015
@@ -23,21 +23,23 @@ import java.io.IOException;
 
 import javax.activation.DataHandler;
 
-import org.apache.axiom.om.OMAttachmentAccessor;
+import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.util.stax.xop.MimePartProvider;
 
 /**
- * Adapts an {@link OMAttachmentAccessor} instance to the {@link 
MimePartProvider} interface.
+ * Adapts an {@link Attachments} instance to the {@link MimePartProvider} 
interface.
+ * <p>
+ * For internal use only.
  */
-public class OMAttachmentAccessorMimePartProvider implements MimePartProvider {
-    private final OMAttachmentAccessor attachments;
+public class AttachmentsMimePartProvider implements MimePartProvider, 
Detachable {
+    private final Attachments attachments;
 
-    public OMAttachmentAccessorMimePartProvider(OMAttachmentAccessor 
attachments) {
+    public AttachmentsMimePartProvider(Attachments attachments) {
         this.attachments = attachments;
     }
 
     public boolean isLoaded(String contentID) {
-        // TODO: probably we can only determine this for an Attachments object
+        // TODO: implement this
         return false;
     }
 
@@ -49,4 +51,8 @@ public class OMAttachmentAccessorMimePar
             return dh;
         }
     }
+
+    public void detach() {
+        attachments.getAllContentIDs();
+    }
 }

Added: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
 (added)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,28 @@
+/*
+ * 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.om.impl.builder;
+
+import org.apache.axiom.om.OMException;
+
+/**
+ * For internal use only.
+ */
+public interface Detachable {
+    void detach() throws OMException;
+}

Propchange: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/Detachable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
 Sat May 23 20:29:40 2015
@@ -66,6 +66,7 @@ public abstract class StAXBuilder implem
     /** Field omfactory */
     protected OMFactoryEx omfactory;
     
+    private final Detachable detachable;
     private final Closeable closeable;
 
     /** Field lastNode */
@@ -132,8 +133,9 @@ public abstract class StAXBuilder implem
      * For internal use only.
      */
     protected StAXBuilder(OMFactory omFactory, XMLStreamReader parser, String 
encoding,
-            Closeable closeable) {
+            Detachable detachable, Closeable closeable) {
         omfactory = (OMFactoryEx)omFactory;
+        this.detachable = detachable;
         this.closeable = closeable;
         charEncoding = encoding;
         initParser(parser);
@@ -142,9 +144,10 @@ public abstract class StAXBuilder implem
     /**
      * For internal use only.
      */
-    protected StAXBuilder(OMFactory omFactory, XMLStreamReader parser, 
Closeable closeable) {
+    protected StAXBuilder(OMFactory omFactory, XMLStreamReader parser, 
Detachable detachable,
+            Closeable closeable) {
         // The getEncoding information is only available at the START_DOCUMENT 
event.
-        this(omFactory, parser, parser.getEncoding(), closeable);
+        this(omFactory, parser, parser.getEncoding(), detachable, closeable);
     }
     
     /**
@@ -155,7 +158,7 @@ public abstract class StAXBuilder implem
      * @param parser
      */
     protected StAXBuilder(OMFactory omFactory, XMLStreamReader parser) {
-        this(omFactory, parser, (Closeable)null);
+        this(omFactory, parser, null, null);
     }
     
     /**
@@ -169,7 +172,7 @@ public abstract class StAXBuilder implem
     protected StAXBuilder(OMFactory omFactory, 
                           XMLStreamReader parser, 
                           String encoding) {
-        this(omFactory, parser, encoding, null);
+        this(omFactory, parser, encoding, null, null);
     }
 
     private void initParser(XMLStreamReader parser) {
@@ -193,6 +196,7 @@ public abstract class StAXBuilder implem
      * @deprecated
      */
     protected StAXBuilder() {
+        detachable = null;
         closeable = null;
     }
 
@@ -820,4 +824,14 @@ public abstract class StAXBuilder implem
      */
     public void releaseParserOnClose(boolean value) {
     }
+
+    public void detach() throws OMException {
+        if (detachable != null) {
+            detachable.detach();
+        } else {
+            while (!done) {
+                next();
+            }
+        }
+    }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
 Sat May 23 20:29:40 2015
@@ -101,8 +101,9 @@ public class StAXOMBuilder extends StAXB
     /**
      * For internal use only.
      */
-    public StAXOMBuilder(OMFactory ombuilderFactory, XMLStreamReader parser, 
Closeable closeable) {
-        super(ombuilderFactory, parser, closeable);
+    public StAXOMBuilder(OMFactory ombuilderFactory, XMLStreamReader parser, 
Detachable detachable,
+            Closeable closeable) {
+        super(ombuilderFactory, parser, detachable, closeable);
     }
     
     /**

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
 Sat May 23 20:29:40 2015
@@ -51,7 +51,7 @@ public class XOPAwareStAXOMBuilder
     public XOPAwareStAXOMBuilder(OMFactory ombuilderFactory,
                                  XMLStreamReader parser, Attachments 
attachments) {
         super(ombuilderFactory, new XOPDecodingStreamReader(parser,
-                new OMAttachmentAccessorMimePartProvider(attachments)));
+                new AttachmentsMimePartProvider(attachments)));
         this.attachments = attachments;
     }
 
@@ -65,7 +65,7 @@ public class XOPAwareStAXOMBuilder
     public XOPAwareStAXOMBuilder(OMFactory factory, XMLStreamReader parser,
                                  OMElement element, Attachments attachments) {
         super(factory, new XOPDecodingStreamReader(parser,
-                new OMAttachmentAccessorMimePartProvider(attachments)), 
element);
+                new AttachmentsMimePartProvider(attachments)), element);
         this.attachments = attachments;
     }
 
@@ -78,7 +78,7 @@ public class XOPAwareStAXOMBuilder
             throws XMLStreamException,
             FileNotFoundException {
         super(new XOPDecodingStreamReader(StAXUtils.createXMLStreamReader(new 
FileInputStream(
-                filePath)), new 
OMAttachmentAccessorMimePartProvider(attachments)));
+                filePath)), new AttachmentsMimePartProvider(attachments)));
         this.attachments = attachments;
     }
 
@@ -89,7 +89,7 @@ public class XOPAwareStAXOMBuilder
     public XOPAwareStAXOMBuilder(InputStream inStream, Attachments attachments)
             throws XMLStreamException {
         super(new 
XOPDecodingStreamReader(StAXUtils.createXMLStreamReader(inStream),
-                new OMAttachmentAccessorMimePartProvider(attachments)));
+                new AttachmentsMimePartProvider(attachments)));
         this.attachments = attachments;
     }
 
@@ -99,7 +99,7 @@ public class XOPAwareStAXOMBuilder
      * @param parser
      */
     public XOPAwareStAXOMBuilder(XMLStreamReader parser, Attachments 
attachments) {
-        super(new XOPDecodingStreamReader(parser, new 
OMAttachmentAccessorMimePartProvider(
+        super(new XOPDecodingStreamReader(parser, new 
AttachmentsMimePartProvider(
                 attachments)));
         this.attachments = attachments;
     }
@@ -108,8 +108,8 @@ public class XOPAwareStAXOMBuilder
      * For internal use only.
      */
     public XOPAwareStAXOMBuilder(OMFactory omFactory, XMLStreamReader reader,
-            MimePartProvider mimePartProvider, Closeable closeable) {
-        super(omFactory, new XOPDecodingStreamReader(reader, 
mimePartProvider), closeable);
+            MimePartProvider mimePartProvider, Detachable detachable, 
Closeable closeable) {
+        super(omFactory, new XOPDecodingStreamReader(reader, 
mimePartProvider), detachable, closeable);
         attachments = null;
     }
 

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
 Sat May 23 20:29:40 2015
@@ -23,7 +23,8 @@ import java.io.Closeable;
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
+import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
+import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.builder.XOPBuilder;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.util.stax.xop.MimePartProvider;
@@ -40,7 +41,7 @@ public class MTOMStAXSOAPModelBuilder ex
     public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
                                     SOAPFactory factory, Attachments 
attachments,
                                     String soapVersion) {
-        super(new XOPDecodingStreamReader(parser, new 
OMAttachmentAccessorMimePartProvider(
+        super(new XOPDecodingStreamReader(parser, new 
AttachmentsMimePartProvider(
                 attachments)), factory, soapVersion);
         this.attachments = attachments;
     }
@@ -51,14 +52,14 @@ public class MTOMStAXSOAPModelBuilder ex
      */
     public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
                                     Attachments attachments, String 
soapVersion) {
-        super(new XOPDecodingStreamReader(reader, new 
OMAttachmentAccessorMimePartProvider(
+        super(new XOPDecodingStreamReader(reader, new 
AttachmentsMimePartProvider(
                 attachments)), soapVersion);
         this.attachments = attachments;
     }
 
     public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
                                     Attachments attachments) {
-        super(new XOPDecodingStreamReader(reader, new 
OMAttachmentAccessorMimePartProvider(
+        super(new XOPDecodingStreamReader(reader, new 
AttachmentsMimePartProvider(
                 attachments)));
         this.attachments = attachments;
     }
@@ -67,9 +68,9 @@ public class MTOMStAXSOAPModelBuilder ex
      * For internal use only.
      */
     public MTOMStAXSOAPModelBuilder(SOAPFactory soapFactory, XMLStreamReader 
reader,
-            MimePartProvider mimePartProvider, Closeable closeable) {
+            MimePartProvider mimePartProvider, Detachable detachable, 
Closeable closeable) {
         super(new XOPDecodingStreamReader(reader, mimePartProvider), 
soapFactory,
-                soapFactory.getSoapVersionURI(), closeable);
+                soapFactory.getSoapVersionURI(), detachable, closeable);
         attachments = null;
     }
 

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
 Sat May 23 20:29:40 2015
@@ -30,6 +30,7 @@ import org.apache.axiom.om.OMMetaFactory
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
+import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP11Version;
@@ -130,8 +131,8 @@ public class StAXSOAPModelBuilder extend
      * For internal use only.
      */
     public StAXSOAPModelBuilder(OMMetaFactory metaFactory, XMLStreamReader 
parser,
-            Closeable closeable) {
-        super(metaFactory.getOMFactory(), parser, closeable);
+            Detachable detachable, Closeable closeable) {
+        super(metaFactory.getOMFactory(), parser, detachable, closeable);
         this.metaFactory = metaFactory;
     }
     
@@ -143,15 +144,15 @@ public class StAXSOAPModelBuilder extend
      * @param parser the parser to read the SOAP message from
      */
     public StAXSOAPModelBuilder(OMMetaFactory metaFactory, XMLStreamReader 
parser) {
-        this(metaFactory, parser, (Closeable)null);
+        this(metaFactory, parser, null, null);
     }
 
     /**
      * For internal use only.
      */
     public StAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, 
String soapVersion,
-            Closeable closeable) {
-        super(factory, parser, closeable);
+            Detachable detachable, Closeable closeable) {
+        super(factory, parser, detachable, closeable);
         soapFactory = (SOAPFactoryEx)factory;
         identifySOAPVersion(soapVersion);
     }
@@ -165,7 +166,7 @@ public class StAXSOAPModelBuilder extend
      *                    of the message
      */
     public StAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, 
String soapVersion) {
-        this(parser, factory, soapVersion, null);
+        this(parser, factory, soapVersion, null, null);
     }
 
     /** @param soapVersionURIFromTransport  */

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
 Sat May 23 20:29:40 2015
@@ -27,7 +27,7 @@ import javax.xml.stream.XMLStreamReader;
 import junit.framework.TestCase;
 
 import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
+import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.testutils.stax.XMLStreamReaderComparator;
 import org.apache.axiom.ts.soap.MTOMSample;
@@ -39,7 +39,7 @@ public class XOPDecodingStreamReaderTest
                 MTOMSample.SAMPLE1.getContentType());
         return new XOPDecodingStreamReader(
                 
StAXUtils.createXMLStreamReader(attachments.getRootPartInputStream()),
-                new OMAttachmentAccessorMimePartProvider(attachments));
+                new AttachmentsMimePartProvider(attachments));
     }
     
     public void testCompareToInlined() throws Exception {

Modified: 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
 Sat May 23 20:29:40 2015
@@ -24,7 +24,7 @@ import javax.xml.stream.XMLStreamReader;
 import junit.framework.TestCase;
 
 import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
+import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.testutils.stax.XMLStreamReaderComparator;
 import org.apache.axiom.ts.soap.MTOMSample;
@@ -47,7 +47,7 @@ public class XOPEncodingStreamReaderTest
                     MTOMSample.SAMPLE1.getContentType());
             soapPartReader[i] = 
StAXUtils.createXMLStreamReader(attachments[i].getRootPartInputStream());
         }
-        XMLStreamReader actual = new XOPEncodingStreamReader(new 
XOPDecodingStreamReader(soapPartReader[1], new 
OMAttachmentAccessorMimePartProvider(attachments[1])), contentIDGenerator, 
OptimizationPolicy.DEFAULT);
+        XMLStreamReader actual = new XOPEncodingStreamReader(new 
XOPDecodingStreamReader(soapPartReader[1], new 
AttachmentsMimePartProvider(attachments[1])), contentIDGenerator, 
OptimizationPolicy.DEFAULT);
         new XMLStreamReaderComparator(soapPartReader[0], actual).compare();
         for (int i=0; i<2; i++) {
             soapPartReader[i].close();

Modified: 
webservices/axiom/trunk/modules/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-compat/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
 Sat May 23 20:29:40 2015
@@ -506,4 +506,8 @@ public class SAXOMBuilder extends Defaul
     public void close() {
         // This is a no-op
     }
+
+    public void detach() {
+        throw new UnsupportedOperationException();
+    }
 }

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=1681379&r1=1681378&r2=1681379&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
 Sat May 23 20:29:40 2015
@@ -119,6 +119,13 @@ public class OMTestSuiteBuilder extends
         addTest(new 
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderIncorrectState(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing2(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.builder.TestDetachWithDOM(metaFactory, false));
+        addTest(new 
org.apache.axiom.ts.om.builder.TestDetachWithDOM(metaFactory, true));
+        for (StreamType streamType : Multiton.getInstances(StreamType.class)) {
+            addTest(new 
org.apache.axiom.ts.om.builder.TestDetachWithStream(metaFactory, streamType, 
false));
+            addTest(new 
org.apache.axiom.ts.om.builder.TestDetachWithStream(metaFactory, streamType, 
true));
+        }
+        addTest(new 
org.apache.axiom.ts.om.builder.TestDetachWithSAXSource(metaFactory));
         for (BuilderFactory bf : getInstances(BuilderFactory.class)) {
             addTest(new 
org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory, bf, null));
             addTest(new 
org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory, bf, 
Boolean.FALSE));

Added: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/DummyXMLReader.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/DummyXMLReader.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/DummyXMLReader.java
 (added)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/DummyXMLReader.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,52 @@
+/*
+ * 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.builder;
+
+import java.io.IOException;
+
+import org.apache.axiom.util.sax.AbstractXMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+final class DummyXMLReader extends AbstractXMLReader {
+    private boolean parsed;
+    
+    @Override
+    public void parse(InputSource input) throws IOException, SAXException {
+        parse();
+    }
+
+    @Override
+    public void parse(String systemId) throws IOException, SAXException {
+        parse();
+    }
+    
+    private void parse() throws SAXException {
+        parsed = true;
+        contentHandler.startDocument();
+        contentHandler.startElement("", "test", "test", new AttributesImpl());
+        contentHandler.endElement("", "test", "test");
+        contentHandler.endDocument();
+    }
+
+    public boolean isParsed() {
+        return parsed;
+    }
+}

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

Added: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithDOM.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithDOM.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithDOM.java
 (added)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithDOM.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,59 @@
+/*
+ * 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.builder;
+
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestDetachWithDOM extends AxiomTestCase {
+    private final boolean useDOMSource;
+    
+    public TestDetachWithDOM(OMMetaFactory metaFactory, boolean useDOMSource) {
+        super(metaFactory);
+        this.useDOMSource = useDOMSource;
+        addTestParameter("useDOMSource", useDOMSource);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Document document = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        Element root = document.createElementNS("", "root");
+        root.appendChild(document.createElementNS("", "a"));
+        OMXMLParserWrapper builder;
+        if (useDOMSource) {
+            builder = 
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new 
DOMSource(root));
+        } else {
+            builder = 
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), root, false);
+        }
+        OMElement omRoot = builder.getDocumentElement();
+        builder.detach();
+        root.appendChild(document.createElementNS("", "b"));
+        ASSERT.that(omRoot).hasNumberOfChildren(1);
+    }
+}

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

Added: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithSAXSource.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithSAXSource.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithSAXSource.java
 (added)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithSAXSource.java
 Sat May 23 20:29:40 2015
@@ -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.builder;
+
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.InputSource;
+
+public class TestDetachWithSAXSource extends AxiomTestCase {
+    public TestDetachWithSAXSource(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        DummyXMLReader xmlReader = new DummyXMLReader();
+        OMXMLParserWrapper builder = 
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
+                new SAXSource(xmlReader, new InputSource()), false);
+        ASSERT.that(xmlReader.isParsed()).isFalse();
+        builder.detach();
+        ASSERT.that(xmlReader.isParsed()).isTrue();
+    }
+}

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

Added: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithStream.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithStream.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithStream.java
 (added)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestDetachWithStream.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,60 @@
+/*
+ * 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.builder;
+
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.testutils.io.InstrumentedStream;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.StreamTypeAdapter;
+import org.apache.axiom.ts.xml.StreamType;
+import org.apache.axiom.ts.xml.XMLSample;
+
+public class TestDetachWithStream extends AxiomTestCase {
+    private final StreamType streamType;
+    private final boolean useStreamSource;
+    
+    public TestDetachWithStream(OMMetaFactory metaFactory, StreamType 
streamType, boolean useStreamSource) {
+        super(metaFactory);
+        this.streamType = streamType;
+        this.useStreamSource = useStreamSource;
+        addTestParameter("streamType", streamType.getType().getSimpleName());
+        addTestParameter("useStreamSource", useStreamSource);
+    }
+
+    @Override
+    protected final void runTest() throws Throwable {
+        InstrumentedStream stream = 
streamType.instrumentStream(streamType.getStream(XMLSample.LARGE));
+        OMXMLParserWrapper builder;
+        if (useStreamSource) {
+            builder = 
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), 
streamType.createStreamSource(stream));
+        } else {
+            builder = 
streamType.getAdapter(StreamTypeAdapter.class).createOMBuilder(metaFactory.getOMFactory(),
 stream);
+        }
+        long countBeforeDetach = stream.getCount();
+        builder.detach();
+        ASSERT.that(stream.getCount()).isGreaterThan(countBeforeDetach);
+        ASSERT.that(stream.isClosed()).isFalse();
+        stream.close();
+        builder.getDocument().build();
+    }
+}

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

Modified: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
 (original)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
 Sat May 23 20:29:40 2015
@@ -363,6 +363,7 @@ public class SOAPTestSuiteBuilder extend
         addTest(new 
org.apache.axiom.ts.soap12.headerblock.TestGetMustUnderstandWithParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.headerblock.TestGetRelayWithParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.headerblock.TestGetRoleWithParser(metaFactory));
+        addTest(new 
org.apache.axiom.ts.soap12.mtom.TestBuilderDetach(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.mtom.TestGetXMLStreamReaderMTOMEncoded(metaFactory, 
true));
         addTest(new 
org.apache.axiom.ts.soap12.mtom.TestGetXMLStreamReaderMTOMEncoded(metaFactory, 
false));
     }

Added: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java?rev=1681379&view=auto
==============================================================================
--- 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java
 (added)
+++ 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java
 Sat May 23 20:29:40 2015
@@ -0,0 +1,71 @@
+/*
+ * 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.soap12.mtom;
+
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPModelBuilder;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.testutils.io.InstrumentedInputStream;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.soap.MTOMSample;
+
+public class TestBuilderDetach extends AxiomTestCase {
+    public TestBuilderDetach(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        MTOMSample sample = MTOMSample.SAMPLE1;
+        InstrumentedInputStream in = new 
InstrumentedInputStream(sample.getInputStream());
+        Attachments attachments = new Attachments(in, sample.getContentType());
+        SOAPModelBuilder builder = 
OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, attachments);
+        SOAPEnvelope envelope = builder.getSOAPEnvelope();
+        long countBeforeDetach = in.getCount();
+        builder.detach();
+        ASSERT.that(in.getCount()).isGreaterThan(countBeforeDetach);
+        ASSERT.that(in.isClosed()).isFalse();
+        int binaryCount = 0;
+        for (Iterator it = envelope.getDescendants(false); it.hasNext(); ) {
+            OMNode node = (OMNode)it.next();
+            if (node instanceof OMText) {
+                OMText text = (OMText)node;
+                if (text.isBinary()) {
+                    IOTestUtils.compareStreams(
+                            sample.getPart(text.getContentID()),
+                            
((DataHandler)text.getDataHandler()).getInputStream());
+                    binaryCount++;
+                }
+            }
+        }
+        ASSERT.that(binaryCount).isGreaterThan(0);
+        in.close();
+    }
+}

Propchange: 
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/mtom/TestBuilderDetach.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/axiom/trunk/testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/MIMESample.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/MIMESample.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/MIMESample.java
 (original)
+++ 
webservices/axiom/trunk/testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/MIMESample.java
 Sat May 23 20:29:40 2015
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import javax.activation.DataSource;
+import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.MimeMultipart;
@@ -113,6 +114,24 @@ public abstract class MIMESample {
         } catch (IOException ex) {
             throw new Error(ex);
         } catch (MessagingException ex) {
+            throw new Error(ex);
+        }
+    }
+    
+    public final InputStream getPart(String cid) {
+        try {
+            MimeMultipart mp = getMultipart();
+            BodyPart part = mp.getBodyPart(cid);
+            if (part == null) {
+                part = mp.getBodyPart("<" + cid + ">");
+            }
+            if (part == null) {
+                throw new IllegalArgumentException("Part " + cid + " not 
found");
+            }
+            return part.getInputStream();
+        } catch (IOException ex) {
+            throw new Error(ex);
+        } catch (MessagingException ex) {
             throw new Error(ex);
         }
     }

Modified: 
webservices/axiom/trunk/testing/xml-testsuite/src/main/java/org/apache/axiom/ts/xml/StreamType.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-testsuite/src/main/java/org/apache/axiom/ts/xml/StreamType.java?rev=1681379&r1=1681378&r2=1681379&view=diff
==============================================================================
--- 
webservices/axiom/trunk/testing/xml-testsuite/src/main/java/org/apache/axiom/ts/xml/StreamType.java
 (original)
+++ 
webservices/axiom/trunk/testing/xml-testsuite/src/main/java/org/apache/axiom/ts/xml/StreamType.java
 Sat May 23 20:29:40 2015
@@ -27,6 +27,7 @@ import java.nio.charset.Charset;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
 
 import org.apache.axiom.testing.multiton.Multiton;
 import org.apache.axiom.testutils.io.InstrumentedInputStream;
@@ -49,6 +50,11 @@ public abstract class StreamType extends
         public XMLStreamReader createXMLStreamReader(XMLInputFactory factory, 
Closeable stream) throws XMLStreamException {
             return factory.createXMLStreamReader((InputStream)stream);
         }
+
+        @Override
+        public StreamSource createStreamSource(Closeable stream) {
+            return new StreamSource((InputStream)stream);
+        }
     };
     
     public static final StreamType CHARACTER_STREAM = new 
StreamType(Reader.class) {
@@ -66,6 +72,11 @@ public abstract class StreamType extends
         public XMLStreamReader createXMLStreamReader(XMLInputFactory factory, 
Closeable stream) throws XMLStreamException {
             return factory.createXMLStreamReader((Reader)stream);
         }
+
+        @Override
+        public StreamSource createStreamSource(Closeable stream) {
+            return new StreamSource((Reader)stream);
+        }
     };
     
     private final Class<? extends Closeable> type;
@@ -81,4 +92,5 @@ public abstract class StreamType extends
     public abstract Closeable getStream(XMLSample sample);
     public abstract InstrumentedStream instrumentStream(Closeable stream);
     public abstract XMLStreamReader createXMLStreamReader(XMLInputFactory 
factory, Closeable stream) throws XMLStreamException;
+    public abstract StreamSource createStreamSource(Closeable stream);
 }


Reply via email to