Class MTOMXMLStreamWriter

java.lang.Object
org.apache.axiom.om.impl.MTOMXMLStreamWriter
All Implemented Interfaces:
XMLStreamWriter

public abstract class MTOMXMLStreamWriter extends Object implements XMLStreamWriter
MTOMXMLStreamWriter is an XML + Attachments stream writer. For the moment this assumes that transport takes the decision of whether to optimize or not by looking at whether the MTOM optimize is enabled and also looking at the OM tree whether it has any optimizable content.
  • Constructor Details

    • MTOMXMLStreamWriter

      public MTOMXMLStreamWriter()
  • Method Details

    • isOptimized

      public abstract boolean isOptimized()
      Check if MTOM is enabled.

      Note that serialization code should use XMLStreamWriterUtils.writeBlob(XMLStreamWriter, Blob, String, boolean) or XMLStreamWriterUtils.writeBlob(XMLStreamWriter, BlobProvider, String, boolean) to submit any binary content and let this writer decide whether the content should be written as base64 encoded character data or using xop:Include. This makes optimization entirely transparent for the caller and there should be no need to check if the writer is producing MTOM. However, in some cases this is not possible, such as when integrating with 3rd party libraries. The serialization code should then use prepareBlob(Blob) so that it can write xop:Include elements directly to the stream. In that case, the code may use the isOptimized() method check if MTOM is enabled at all.

      Returns:
      true if MTOM is enabled, false otherwise
    • prepareBlob

      public abstract String prepareBlob(Blob blob)
      Prepare a Blob for serialization without using the BlobWriter API. The method first determines whether the binary data represented by the Blob should be optimized or inlined. If the data should not be optimized, then the method returns null and the caller is expected to use XMLStreamWriter.writeCharacters(String) or XMLStreamWriter.writeCharacters(char[], int, int) to write the base64 encoded data to the stream. If the data should be optimized, then the method returns a content ID and the caller is expected to generate an xop:Include element referring to that content ID.

      This method should only be used to integrate Axiom with third party libraries that support XOP. In all other cases, XMLStreamWriterUtils.writeBlob(XMLStreamWriter, Blob, String, boolean) or XMLStreamWriterUtils.writeBlob(XMLStreamWriter, BlobProvider, String, boolean) should be used to write base64Binary values and the application code should never generate xop:Include elements itself.

      Parameters:
      blob - the Blob that the caller intends to write to the stream
      Returns:
      the content ID that the caller must use in the xop:Include element or null if the base64 encoded data should not be optimized
    • getCharSetEncoding

      public abstract String getCharSetEncoding()
      Returns the character set encoding scheme. If the value of the charSetEncoding is not set then the default will be returned.
      Returns:
      Returns encoding.
    • getOutputFormat

      public abstract OMOutputFormat getOutputFormat()
      Get the output format used by this writer.

      The caller should use the returned instance in a read-only way, i.e. he should not modify the settings of the output format. Any attempt to do so will lead to unpredictable results.

      Returns:
      the output format used by this writer
    • getOutputStream

      public abstract OutputStream getOutputStream() throws XMLStreamException
      Get the underlying OutputStream for this writer, if available. This method allows a node (perhaps an OMSourcedElement) to write its content directly to the byte stream.

      WARNING: This method should be used with extreme care. The caller must be prepared to handle the following issues:

      • The caller must use the right charset encoding when writing to the stream.
      • The caller should avoid writing byte order marks to the stream.
      • The caller must be aware of the fact that a default namespace might have been set in the context where the byte stream is requested. If the XML data written to the stream contains unqualified elements, then the caller must make sure that the default namespace is redeclared as appropriate.
      Returns:
      the underlying byte stream, or null if the stream is not accessible
      Throws:
      XMLStreamException