Author: veithen
Date: Thu Aug 13 20:28:27 2009
New Revision: 804020

URL: http://svn.apache.org/viewvc?rev=804020&view=rev
Log:
Closing the XMLStreamWriter in serialize methods that write to an InputStream 
or Writer should not be an optional operation. If we don't do it in the 
serialize method, nobody will ever close the XMLStreamWriter. Note that there 
is no valid reason not to close the XMLStreamReader. In particular, closing the 
XMLStreamWriter has no impact on the underlying stream. Therefore we should 
always do it so that the StAX implementation can free the resources associated 
with the writer.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
 Thu Aug 13 20:28:27 2009
@@ -307,10 +307,16 @@
         return sb.toString();
     }
 
+    /**
+     * @deprecated
+     */
     public boolean isAutoCloseWriter() {
         return autoCloseWriter;
     }
 
+    /**
+     * @deprecated
+     */
     public void setAutoCloseWriter(boolean autoCloseWriter) {
         this.autoCloseWriter = autoCloseWriter;
     }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 Thu Aug 13 20:28:27 2009
@@ -167,6 +167,7 @@
     }
 
     public void close() throws XMLStreamException {
+        // TODO: we should probably call flush if the attachments have not 
been written yet
         if (isDebugEnabled) {
             log.debug("close");
         }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
 Thu Aug 13 20:28:27 2009
@@ -123,7 +123,6 @@
     public static long logDebug(OMElement om, Log log, int limit) {
         OMOutputFormat format = new OMOutputFormat();
         format.setDoOptimize(true);
-        format.setAutoCloseWriter(true);
         format.setIgnoreXMLDeclaration(true);
         return logDebug(om, log, limit, format);
     }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
 Thu Aug 13 20:28:27 2009
@@ -796,11 +796,10 @@
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
         try {
             internalSerialize(writer, true);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
-            if (format.isAutoCloseWriter()) {
-                writer.close();
-            }
+            writer.close();
         }
     }
 
@@ -811,11 +810,10 @@
         writer.setOutputFormat(format);
         try {
             internalSerialize(writer, true);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
-            if (format.isAutoCloseWriter()) {
-                writer.close();
-            }
+            writer.close();
         }
     }
 
@@ -824,11 +822,10 @@
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
         try {
             internalSerialize(writer, false);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
             writer.flush();
         } finally {
-            if (format.isAutoCloseWriter()) {
-                writer.close();
-            }
+            writer.close();
         }
     }
 
@@ -838,12 +835,11 @@
                 .createXMLStreamWriter(writer2));
         try {
             writer.setOutputFormat(format);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
             internalSerialize(writer, false);
             writer.flush();
         } finally {
-            if (format.isAutoCloseWriter()) {
-                writer.close();
-            }
+            writer.close();
         }
     }
 

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
 Thu Aug 13 20:28:27 2009
@@ -347,9 +347,11 @@
 
     public void serialize(OutputStream output, OMOutputFormat format) throws 
XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
-        internalSerialize(writer, true);
-        writer.flush();
-        if (format.isAutoCloseWriter()) {
+        try {
+            internalSerialize(writer, true);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
+            writer.flush();
+        } finally {
             writer.close();
         }
     }
@@ -358,9 +360,11 @@
         MTOMXMLStreamWriter writer =
                 new 
MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer2));
         writer.setOutputFormat(format);
-        internalSerialize(writer, true);
-        writer.flush();
-        if (format.isAutoCloseWriter()) {
+        try {
+            internalSerialize(writer, true);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
+            writer.flush();
+        } finally {
             writer.close();
         }
     }
@@ -368,9 +372,11 @@
     public void serializeAndConsume(OutputStream output, OMOutputFormat format)
             throws XMLStreamException {
         MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format);
-        internalSerialize(writer, false);
-        writer.flush();
-        if (format.isAutoCloseWriter()) {
+        try {
+            internalSerialize(writer, false);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
+            writer.flush();
+        } finally {
             writer.close();
         }
     }
@@ -380,9 +386,11 @@
         MTOMXMLStreamWriter writer =
                 new 
MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer2));
         writer.setOutputFormat(format);
-        internalSerialize(writer, false);
-        writer.flush();
-        if (format.isAutoCloseWriter()) {
+        try {
+            internalSerialize(writer, false);
+            // TODO: the flush is necessary because of an issue with the 
lifecycle of MTOMXMLStreamWriter
+            writer.flush();
+        } finally {
             writer.close();
         }
     }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=804020&r1=804019&r2=804020&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
 Thu Aug 13 20:28:27 2009
@@ -772,7 +772,6 @@
             log.debug("serialize " + getPrintableName() + " to output stream");
         }
         OMOutputFormat format = new OMOutputFormat();
-        format.setAutoCloseWriter(true);
         if (isExpanded()) {
             super.serializeAndConsume(output, format);
         } else {
@@ -791,7 +790,6 @@
             super.serializeAndConsume(writer);
         } else {
             OMOutputFormat format = new OMOutputFormat();
-            format.setAutoCloseWriter(true);
             dataSource.serialize(writer, format); 
         }
     }


Reply via email to