Author: veithen
Date: Sun Jul 19 15:32:39 2009
New Revision: 795556
URL: http://svn.apache.org/viewvc?rev=795556&view=rev
Log:
Get rid of the explicit dependency on MTOMXMLStreamWriter in
StreamingOMSerializer. Regression tested with Axis2 trunk.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamWriterUtil.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=795556&r1=795555&r2=795556&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
Sun Jul 19 15:32:39 2009
@@ -19,14 +19,12 @@
package org.apache.axiom.om.impl.serialize;
-import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
import org.apache.axiom.om.OMAttachmentAccessor;
-import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMSerializer;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.om.util.ElementHelper;
+import org.apache.axiom.util.stax.XMLStreamWriterUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,6 +36,7 @@
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import java.io.IOException;
import java.util.ArrayList;
/** Class StreamingOMSerializer */
@@ -61,6 +60,7 @@
public static final QName XOP_INCLUDE =
new QName("http://www.w3.org/2004/08/xop/include", "Include");
+ private DataHandlerWriter dataHandlerWriter;
private boolean inputHasAttachments = false;
private boolean skipEndElement = false;
@@ -90,6 +90,8 @@
inputHasAttachments = true;
}
+ dataHandlerWriter = XMLStreamWriterUtil.getDataHandlerWriter(writer);
+
serializeNode(reader, writer, startAtNext);
}
@@ -571,41 +573,23 @@
* @return true if inlined
*/
protected boolean serializeXOPInclude(XMLStreamReader reader,
- XMLStreamWriter writer) {
+ XMLStreamWriter writer) throws
XMLStreamException {
String cid = ElementHelper.getContentID(reader);
+ // TODO: this is suboptimal because it forces loading of the data; we
could do deferred loading here
DataHandler dh = getDataHandler(cid, (OMAttachmentAccessor) reader);
if (dh == null) {
return false;
}
- OMFactory omFactory = OMAbstractFactory.getOMFactory();
- OMText omText = omFactory.createOMText(dh, true);
- omText.setContentID(cid);
-
-
- MTOMXMLStreamWriter mtomWriter =
- (writer instanceof MTOMXMLStreamWriter) ?
- (MTOMXMLStreamWriter) writer :
- null;
-
- if (mtomWriter != null &&
- mtomWriter.isOptimized() &&
- mtomWriter.isOptimizedThreshold(omText)) {
- // This will write the attachment after the xml message
- mtomWriter.writeOptimized(omText);
- return false;
- }
-
- // This will inline the attachment
- omText.setOptimize(false);
try {
- writer.writeCharacters(omText.getText());
- return true;
- } catch (XMLStreamException e) {
- // Just writer out the xop:include
- return false;
+ dataHandlerWriter.writeDataHandler(dh, cid, true);
+ } catch (IOException ex) {
+ throw new XMLStreamException("Unable to read data handler for
content ID '" + cid + "'");
}
-
+ // The binary data always appears as "inlined" because
DataHandlerWriter either uses base64
+ // or generates an xop:Include element. Therefore we must always skip
the xop:Include in
+ // the original stream.
+ return true;
}
private DataHandler getDataHandler(String cid, OMAttachmentAccessor oaa) {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamWriterUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamWriterUtil.java?rev=795556&r1=795555&r2=795556&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamWriterUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamWriterUtil.java
Sun Jul 19 15:32:39 2009
@@ -66,7 +66,7 @@
}
}
- private static DataHandlerWriter getDataHandlerWriter(XMLStreamWriter
writer) {
+ private static DataHandlerWriter
internalGetDataHandlerWriter(XMLStreamWriter writer) {
try {
return
(DataHandlerWriter)writer.getProperty(DataHandlerWriter.PROPERTY);
} catch (IllegalArgumentException ex) {
@@ -75,6 +75,38 @@
}
/**
+ * Get the {...@link DataHandlerWriter} extension for a given {...@link
XMLStreamWriter}. If the
+ * writer expose the extension, a reference to the extension interface
implementation is
+ * returned. If the writer doesn't expose the extension, this method
returns an instance of the
+ * extension interface that emulates the extension (by writing the binary
data as base64
+ * character data to the stream).
+ *
+ * @param writer
+ * the stream for which the method should return the {...@link
DataHandlerWriter}
+ * extension
+ * @return a reference to the extension interface exposed by the writer or
an implementation the
+ * emulates the extension; the return value is never
<code>null</code>
+ */
+ public static DataHandlerWriter getDataHandlerWriter(final XMLStreamWriter
writer) {
+ DataHandlerWriter dataHandlerWriter =
internalGetDataHandlerWriter(writer);
+ if (dataHandlerWriter == null) {
+ return new DataHandlerWriter() {
+ public void writeDataHandler(DataHandler dataHandler, String
contentID,
+ boolean optimize) throws IOException,
XMLStreamException {
+ writeBase64(writer, dataHandler);
+ }
+
+ public void writeDataHandler(DataHandlerProvider
dataHandlerProvider,
+ String contentID, boolean optimize) throws
IOException, XMLStreamException {
+ writeBase64(writer, dataHandlerProvider.getDataHandler());
+ }
+ };
+ } else {
+ return dataHandlerWriter;
+ }
+ }
+
+ /**
* Write binary content to the stream. Depending on the supplied {...@link
XMLStreamWriter},
* the content will be written as base64 encoded character data or using
an optimization
* scheme such as XOP/MTOM. The method attempts to submit the binary
content using the
@@ -99,7 +131,7 @@
*/
public static void writeDataHandler(XMLStreamWriter writer, DataHandler
dataHandler,
String contentID, boolean optimize) throws IOException,
XMLStreamException {
- DataHandlerWriter dataHandlerWriter = getDataHandlerWriter(writer);
+ DataHandlerWriter dataHandlerWriter =
internalGetDataHandlerWriter(writer);
if (dataHandlerWriter != null) {
dataHandlerWriter.writeDataHandler(dataHandler, contentID,
optimize);
} else {
@@ -127,7 +159,7 @@
*/
public static void writeDataHandler(XMLStreamWriter writer,
DataHandlerProvider dataHandlerProvider,
String contentID, boolean optimize) throws IOException,
XMLStreamException {
- DataHandlerWriter dataHandlerWriter = getDataHandlerWriter(writer);
+ DataHandlerWriter dataHandlerWriter =
internalGetDataHandlerWriter(writer);
if (dataHandlerWriter != null) {
dataHandlerWriter.writeDataHandler(dataHandlerProvider, contentID,
optimize);
} else {