ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1849254 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/ axiom-api/src/main/java/org/apache/axiom/om/ src/site/markdown/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/ser...
Date Wed, 19 Dec 2018 00:32:10 GMT
Author: veithen
Date: Wed Dec 19 00:32:10 2018
New Revision: 1849254

URL: http://svn.apache.org/viewvc?rev=1849254&view=rev
Log:
Introduce serialize methods in OMContainer that throw the right exceptions and that make it
easier to switch between caching and non caching mode.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    webservices/axiom/trunk/src/site/markdown/roadmap.md
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToOutputStream.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToWriter.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj?rev=1849254&r1=1849253&r2=1849254&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomContainerSupport.aj
Wed Dec 19 00:32:10 2018
@@ -237,7 +237,7 @@ public aspect AxiomContainerSupport {
         return result;
     }
 
-    private void AxiomContainer.serialize(XmlHandler handler, NamespaceContextProvider namespaceContextProvider,
OMOutputFormat format, boolean cache) throws XMLStreamException {
+    private void AxiomContainer.serialize(XmlHandler handler, NamespaceContextProvider namespaceContextProvider,
OMOutputFormat format, boolean cache) throws StreamException {
         handler = new XmlDeclarationRewriterHandler(handler, format);
         CoreElement contextElement = getContextElement();
         if (contextElement != null) {
@@ -248,22 +248,41 @@ public aspect AxiomContainerSupport {
             internalSerialize(handler, cache);
         } catch (CoreModelException ex) {
             throw AxiomExceptionTranslator.translate(ex);
+        }
+    }
+
+    private void AxiomContainer.serializeAndSurfaceIOException(XmlHandler handler, NamespaceContextProvider
namespaceContextProvider, OMOutputFormat format, boolean cache) throws IOException {
+        try {
+            serialize(handler, namespaceContextProvider, format, cache);
         } catch (StreamException ex) {
-            throw AxiomExceptionTranslator.toXMLStreamException(ex);
+            Throwable cause = ex.getCause();
+            if (cause instanceof IOException) {
+                throw (IOException)cause;
+            } else {
+                throw new OMException(ex);
+            }
         }
     }
 
     public abstract CoreElement AxiomContainer.getContextElement();
     
     public final void AxiomContainer.serialize(XMLStreamWriter writer, boolean cache) throws
XMLStreamException {
-        serialize(new XMLStreamWriterHandler(writer), new XMLStreamWriterNamespaceContextProvider(writer),
new OMOutputFormat(), cache);
+        try {
+            serialize(new XMLStreamWriterHandler(writer), new XMLStreamWriterNamespaceContextProvider(writer),
new OMOutputFormat(), cache);
+        } catch (StreamException ex) {
+            throw AxiomExceptionTranslator.toXMLStreamException(ex);
+        }
     }
 
-    private void AxiomContainer.serialize(Writer writer, boolean cache) throws XMLStreamException
{
+    public final void AxiomContainer.serialize(Writer writer, boolean cache) throws IOException
{
         serialize(writer, new OMOutputFormat(), cache);
     }
 
-    private void AxiomContainer.serialize(OutputStream out, final OMOutputFormat format,
final boolean cache) throws XMLStreamException {
+    public final void AxiomContainer.serialize(OutputStream out, boolean cache) throws IOException
{
+        serialize(out, new OMOutputFormat(), cache);
+    }
+
+    public final void AxiomContainer.serialize(OutputStream out, OMOutputFormat format, boolean
cache) throws IOException {
         String encoding = format.getCharSetEncoding();
         if (encoding == null) { //Default encoding is UTF-8
             format.setCharSetEncoding(encoding = OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
@@ -273,11 +292,7 @@ public aspect AxiomContainerSupport {
         OutputStream rootPartOutputStream;
         if (format.isOptimized()) {
             multipartWriter = new OMMultipartWriter(out, format);
-            try {
-                rootPartOutputStream = multipartWriter.writeRootPart();
-            } catch (IOException ex) {
-                throw new XMLStreamException(ex);
-            }
+            rootPartOutputStream = multipartWriter.writeRootPart();
         } else {
             multipartWriter = null;
             rootPartOutputStream = out;
@@ -297,30 +312,26 @@ public aspect AxiomContainerSupport {
             encoder = null;
         }
         
-        serialize(handler, null, format, cache);
+        serializeAndSurfaceIOException(handler, null, format, cache);
 
         if (encoder != null) {
-            try {
-                rootPartOutputStream.close();
-                for (String contentID : encoder.getContentIDs()) {
-                    DataHandler dataHandler = encoder.getDataHandler(contentID);
-                    if (cache || !(dataHandler instanceof PartDataHandler)) {
-                        multipartWriter.writePart(dataHandler, contentID);
-                    } else {
-                        OutputStream part = multipartWriter.writePart(dataHandler.getContentType(),
contentID);
-                        IOUtils.copy(((PartDataHandler)dataHandler).getPart().getInputStream(false),
part, -1);
-                        part.close();
-                    }
+            rootPartOutputStream.close();
+            for (String contentID : encoder.getContentIDs()) {
+                DataHandler dataHandler = encoder.getDataHandler(contentID);
+                if (cache || !(dataHandler instanceof PartDataHandler)) {
+                    multipartWriter.writePart(dataHandler, contentID);
+                } else {
+                    OutputStream part = multipartWriter.writePart(dataHandler.getContentType(),
contentID);
+                    IOUtils.copy(((PartDataHandler)dataHandler).getPart().getInputStream(false),
part, -1);
+                    part.close();
                 }
-                multipartWriter.complete();
-            } catch (IOException ex) {
-                throw new XMLStreamException(ex);
             }
+            multipartWriter.complete();
         };
     }
 
-    private void AxiomContainer.serialize(Writer writer, OMOutputFormat format, boolean cache)
throws XMLStreamException {
-        serialize(new Serializer(writer), null, format, cache);
+    public final void AxiomContainer.serialize(Writer writer, OMOutputFormat format, boolean
cache) throws IOException {
+        serializeAndSurfaceIOException(new Serializer(writer), null, format, cache);
     }
 
     public final void AxiomContainer.serialize(OutputStream output) throws XMLStreamException
{
@@ -332,27 +343,51 @@ public aspect AxiomContainerSupport {
     }
 
     public final void AxiomContainer.serialize(OutputStream output, OMOutputFormat format)
throws XMLStreamException {
-        serialize(output, format, true);
+        try {
+            serialize(output, format, true);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.serializeAndConsume(OutputStream output, OMOutputFormat
format) throws XMLStreamException {
-        serialize(output, format, false);
+        try {
+            serialize(output, format, false);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.serialize(Writer writer) throws XMLStreamException {
-        serialize(writer, true);
+        try {
+            serialize(writer, true);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.serializeAndConsume(Writer writer) throws XMLStreamException
{
-        serialize(writer, false);
+        try {
+            serialize(writer, false);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.serialize(Writer writer, OMOutputFormat format) throws
XMLStreamException {
-        serialize(writer, format, true);
+        try {
+            serialize(writer, format, true);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.serializeAndConsume(Writer writer, OMOutputFormat format)
throws XMLStreamException {
-        serialize(writer, format, false);
+        try {
+            serialize(writer, format, false);
+        } catch (IOException ex) {
+            throw new XMLStreamException(ex);
+        }
     }
 
     public final void AxiomContainer.close(boolean build) {

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1849254&r1=1849253&r2=1849254&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java Wed
Dec 19 00:32:10 2018
@@ -32,6 +32,7 @@ import org.xml.sax.DTDHandler;
 import org.xml.sax.ext.DeclHandler;
 import org.xml.sax.ext.LexicalHandler;
 
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
 import java.util.Iterator;
@@ -146,32 +147,36 @@ public interface OMContainer extends OMS
     void removeChildren();
     
     /**
-     * Serialize the node with caching enabled.
+     * Serialize the node.
      * <p>
      * This method will always serialize the infoset as plain XML. In particular, any {@link
OMText}
      * containing optimized binary will be inlined using base64 encoding.
      * 
      * @param output
      *            the byte stream to write the serialized infoset to
-     * @throws XMLStreamException
+     * @param cache
+     *            indicates if caching should be enabled
+     * @throws IOException if the stream throws an {@link IOException}
      */
     // TODO: need to specify which charset encoding the method will use, in particular for
OMDocument nodes
-    void serialize(OutputStream output) throws XMLStreamException;
+    void serialize(OutputStream output, boolean cache) throws IOException;
 
     /**
-     * Serialize the node with caching enabled.
+     * Serialize the node.
      * <p>
      * This method will always serialize the infoset as plain XML. In particular, any {@link
OMText}
      * containing optimized binary will be inlined using base64 encoding.
      * 
      * @param writer
      *            the character stream to write the serialized infoset to
-     * @throws XMLStreamException
+     * @param cache
+     *            indicates if caching should be enabled
+     * @throws IOException if the stream throws an {@link IOException}
      */
-    void serialize(Writer writer) throws XMLStreamException;
+    void serialize(Writer writer, boolean cache) throws IOException;
 
     /**
-     * Serialize the node with caching enabled.
+     * Serialize the node.
      * <p>
      * The format of the output is controlled by the provided {@link OMOutputFormat} object.
In
      * particular, {@link OMOutputFormat#setDoOptimize(boolean)} can be used to instruct
this method
@@ -181,75 +186,67 @@ public interface OMContainer extends OMS
      *            the byte stream to write the serialized infoset to
      * @param format
      *            the output format to use
-     * @throws XMLStreamException
+     * @param cache
+     *            indicates if caching should be enabled
+     * @throws IOException if the stream throws an {@link IOException}
      */
-    void serialize(OutputStream output, OMOutputFormat format)
-            throws XMLStreamException;
+    void serialize(OutputStream output, OMOutputFormat format, boolean cache) throws IOException;
 
     /**
-     * Serialize the node with caching enabled.
+     * Serialize the node.
      *
      * @param writer
      *            the character stream to write the serialized infoset to
      * @param format
      *            the output format to use
-     * @throws XMLStreamException
+     * @param cache
+     *            indicates if caching should be enabled
+     * @throws IOException if the stream throws an {@link IOException}
      */
-    void serialize(Writer writer, OMOutputFormat format)
-            throws XMLStreamException;
+    // TODO: need to clarify what OMOutputFormat settings are actually taken into account
+    //       (obviously the method can't produce XOP/MTOM and the charset encoding is ignored)
+    void serialize(Writer writer, OMOutputFormat format, boolean cache) throws IOException;
 
     /**
-     * Serialize the node without caching.
-     * <p>
-     * This method will always serialize the infoset as plain XML. In particular, any {@link
OMText}
-     * containing optimized binary will be inlined using base64 encoding.
-     *
-     * @param output
-     *            the byte stream to write the serialized infoset to
-     * @throws XMLStreamException
+     * @deprecated Use {@link #serialize(OutputStream, boolean)} instead.
+     */
+    void serialize(OutputStream output) throws XMLStreamException;
+
+    /**
+     * @deprecated Use {@link #serialize(Writer, boolean)} instead.
+     */
+    void serialize(Writer writer) throws XMLStreamException;
+
+    /**
+     * @deprecated Use {@link #serialize(OutputStream, OMOutputFormat, boolean)} instead.
+     */
+    void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException;
+
+    /**
+     * @deprecated Use {@link #serialize(Writer, OMOutputFormat, boolean)} instead.
+     */
+    void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException;
+
+    /**
+     * @deprecated Use {@link #serialize(OutputStream, boolean)} instead.
      */
     void serializeAndConsume(OutputStream output)
             throws XMLStreamException;
 
     /**
-     * Serialize the node without caching.
-     * <p>
-     * This method will always serialize the infoset as plain XML. In particular, any {@link
OMText}
-     * containing optimized binary will be inlined using base64 encoding.
-     *
-     * @param writer
-     *            the character stream to write the serialized infoset to
-     * @throws XMLStreamException
+     * @deprecated Use {@link #serialize(Writer, boolean)} instead.
      */
     void serializeAndConsume(Writer writer) throws XMLStreamException;
 
     /**
-     * Serialize the node without caching.
-     * <p>
-     * The format of the output is controlled by the provided {@link OMOutputFormat} object.
In
-     * particular, {@link OMOutputFormat#setDoOptimize(boolean)} can be used to instruct
this method
-     * to produce an XOP/MTOM encoded MIME message.
-     *
-     * @param output
-     *            the byte stream to write the serialized infoset to
-     * @param format
-     *            the output format to use
-     * @throws XMLStreamException
+     * @deprecated Use {@link #serialize(OutputStream, OMOutputFormat, boolean)} instead.
      */
     void serializeAndConsume(OutputStream output, OMOutputFormat format)
             throws XMLStreamException;
 
     /**
-     * Serialize the node without caching.
-     *
-     * @param writer
-     *            the character stream to write the serialized infoset to
-     * @param format
-     *            the output format to use
-     * @throws XMLStreamException
+     * @deprecated Use {@link #serialize(Writer, OMOutputFormat, boolean)} instead.
      */
-    // TODO: need to clarify what OMOutputFormat settings are actually taken into account
-    //       (obviously the method can't produce XOP/MTOM and the charset encoding is ignored)
     void serializeAndConsume(Writer writer, OMOutputFormat format)
             throws XMLStreamException;
 

Modified: webservices/axiom/trunk/src/site/markdown/roadmap.md
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/src/site/markdown/roadmap.md?rev=1849254&r1=1849253&r2=1849254&view=diff
==============================================================================
--- webservices/axiom/trunk/src/site/markdown/roadmap.md (original)
+++ webservices/axiom/trunk/src/site/markdown/roadmap.md Wed Dec 19 00:32:10 2018
@@ -63,11 +63,6 @@ Axiom 1.3 to meet the following requirem
     Therefore methods defined by the Axiom API should only declare `XMLStreamException` if
they interact
     directly with a StAX object supplied by application code.
 
-    A good example is the `OMContainer#serialize(OutputStream)` method. In Axiom 1.2.x this
method
-    is declared to throw `XMLStreamException`. This assumes that the implementation necessarily
uses
-    StAX as XML serializer. This is a wrong assumption, because the implementation is free
to use its
-    own serializer. Also note that the method doesn't declare `IOException` which would be
much more relevant.
-   
 *   Axiom should have well-defined (and distinct) exceptions for at least the following two
error cases:
 
     *   An I/O error occurs during a deferred parsing operation. In that case, the unchecked
exception should

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToOutputStream.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToOutputStream.java?rev=1849254&r1=1849253&r2=1849254&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToOutputStream.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToOutputStream.java
Wed Dec 19 00:32:10 2018
@@ -25,8 +25,7 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.testutils.suite.MatrixTestCase;
 
 /**
- * Serializes an {@link OMContainer} using {@link OMContainer#serialize(OutputStream)} or
- * {@link OMContainer#serializeAndConsume(OutputStream)}.
+ * Serializes an {@link OMContainer} using {@link OMContainer#serialize(OutputStream, boolean)}.
  */
 public class SerializeToOutputStream extends SerializationStrategy {
     private final boolean cache;
@@ -44,11 +43,7 @@ public class SerializeToOutputStream ext
     @Override
     public XML serialize(OMContainer container) throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        if (cache) {
-            container.serialize(baos);
-        } else {
-            container.serializeAndConsume(baos);
-        }
+        container.serialize(baos, cache);
         return new XMLAsByteArray(baos.toByteArray());
     }
 

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToWriter.java?rev=1849254&r1=1849253&r2=1849254&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToWriter.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/serialization/SerializeToWriter.java
Wed Dec 19 00:32:10 2018
@@ -25,8 +25,7 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.testutils.suite.MatrixTestCase;
 
 /**
- * Serializes an {@link OMContainer} using {@link OMContainer#serialize(Writer)} or
- * {@link OMContainer#serializeAndConsume(Writer)}.
+ * Serializes an {@link OMContainer} using {@link OMContainer#serialize(Writer, boolean)}.
  */
 public class SerializeToWriter extends SerializationStrategy {
     private final boolean cache;
@@ -44,11 +43,7 @@ public class SerializeToWriter extends S
     @Override
     public XML serialize(OMContainer container) throws Exception {
         StringWriter sw = new StringWriter();
-        if (cache) {
-            container.serialize(sw);
-        } else {
-            container.serializeAndConsume(sw);
-        }
+        container.serialize(sw, cache);
         return new XMLAsString(sw.toString());
     }
 



Mime
View raw message