Class TLcdXMLEncoder

java.lang.Object
com.luciad.format.xml.bind.TLcdXMLEncoder
All Implemented Interfaces:
ILcdOutputStreamFactoryCapable

public class TLcdXMLEncoder extends Object implements ILcdOutputStreamFactoryCapable
Utility class for marshalling Java object graphs into XML documents, using ILcdXMLMarshaller's.

This encoder will set up a new XMLStreamWriter for each Java object graph to be marshalled, create a new document context, look up a marshaller for the root element of the Java object graph and delegate the marshalling process to this marshaller.

This encoder is thread-safe and can be shared among multiple threads.

Please refer to the package documentation for a general overview of the XML Binding Framework.

Since:
9.0
  • Constructor Details

    • TLcdXMLEncoder

      public TLcdXMLEncoder()
      Create a new, empty TLcdXMLEncoder.
    • TLcdXMLEncoder

      public TLcdXMLEncoder(ILcdXMLEncoderLibrary aLibrary)
      Create a new TLcdXMLEncoder for the specified encoder library.

      This is a convenience constructor, being identical to:

      
         TLcdXMLEncoder encoder = new TLcdXMLEncoder();
         aLibrary.configureEncoder(encoder);
       
      Parameters:
      aLibrary - the encoder library for which to create an XML encoder.
    • TLcdXMLEncoder

      public TLcdXMLEncoder(List<ILcdXMLEncoderLibrary> aLibraries)
      Create a new TLcdXMLEncoder for the specified encoder libraries.

      This is a convenience constructor, being identical to:

      
         TLcdXMLEncoder encoder = new TLcdXMLEncoder();
         for ( ILcdXMLEncoderLibrary library : aLibraries ) {
           library.configureEncoder( this );
         }
       
      Parameters:
      aLibraries - the encoder libraries for which to create an XML encoder.
    • TLcdXMLEncoder

      public TLcdXMLEncoder(List<ILcdXMLEncoderLibrary> aLibraries, TLcdXMLMapping aMapping)
  • Method Details

    • getOutputStreamFactory

      public ILcdOutputStreamFactory getOutputStreamFactory()
      Returns the com.luciad.io.ILcdOutputStreamFactory that is used by this encoder for creating output streams.
      Specified by:
      getOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Returns:
      the com.luciad.io.ILcdOutputStreamFactory that is used by this encoder for creating output streams.
    • setOutputStreamFactory

      public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
      Sets the com.luciad.io.ILcdOutputStreamFactory that is to be used by this encoder for creating output streams.
      Specified by:
      setOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Parameters:
      aOutputStreamFactory - the com.luciad.io.ILcdOutputStreamFactory that is to beused by this encoder for creating output streams.
    • getXMLOutputFactory

      public XMLOutputFactory getXMLOutputFactory()
      Returns the javax.xml.stream.XMLOutputFactory that is used by this encoder for creating javax.xml.stream.XMLStreamWriter instances.
      Returns:
      the javax.xml.stream.XMLOutputFactory that is used by this encoder for creating javax.xml.stream.XMLStreamWriter instances.
    • setXMLOutputFactory

      public void setXMLOutputFactory(XMLOutputFactory aXMLOutputFactory)
      Sets the javax.xml.stream.XMLOutputFactory to be used by this encoder for creating javax.xml.stream.XMLStreamWriter instances.
      Parameters:
      aXMLOutputFactory - the javax.xml.stream.XMLOutputFactory to be used by this encoder for creating javax.xml.stream.XMLStreamWriter instances.
    • createDocumentContext

      public ILcdXMLDocumentContext createDocumentContext()
      Creates a new ILcdXMLDocumentContext that can be used during encoding of an XML document. A document context may only be used for encoding a single XML document and should be discarded afterwards.
      Returns:
      a new ILcdXMLDocumentContext that can be used during encoding of an XML document.
    • encode

      public void encode(Object aObject, String aDestinationName) throws XMLStreamException, IOException
      Marshals the specified Java object to XML data, written to the specified destination.
      Parameters:
      aObject - the Java object to be marshalled.
      aDestinationName - the data source to which the data should be written; typically a file name.
      Throws:
      XMLStreamException - if an unexpected processing exception occurs during marshalling.
      IOException - if an java.io.IOException occurs during marshalling.
    • encode

      public void encode(Object aObject, OutputStream aDestination) throws XMLStreamException, IOException
      Marshals the specified Java object to XML data, written to the specified OutputStream.
      Parameters:
      aObject - the Java object to be marshalled.
      aDestination - the OutputStream to which the resulting XML data should be written.
      Throws:
      XMLStreamException - if an unexpected processing exception occurs during marshalling.
      IOException - if an java.io.IOException occurs during marshalling.
    • encode

      public void encode(Object aObject, QName aRootElementName, OutputStream aDestination) throws XMLStreamException, IOException
      Marshals the specified Java object to XML data, written to the specified OutputStream.
      Parameters:
      aObject - the Java object to be marshalled.
      aRootElementName - the name of the root element of the resulting XML data.
      aDestination - the OutputStream to which the resulting XML data should be written.
      Throws:
      XMLStreamException - if an unexpected processing exception occurs during marshalling.
      IOException - if an java.io.IOException occurs during marshalling.
    • encode

      public void encode(Object aObject, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
      Marshals the specified Java object to XML data, written to the specified OutputStream.
      Parameters:
      aObject - the Java object to be marshalled.
      aDestination - the OutputStream to which the resulting XML data should be written.
      aDocumentContext - the document context to be used during marshalling.
      Throws:
      XMLStreamException - if an unexpected processing exception occurs during marshalling.
      IOException - if an java.io.IOException occurs during marshalling.
    • encode

      public void encode(Object aObject, QName aRootElementName, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
      Marshals the specified Java object to XML data, written to the specified OutputStream.
      Parameters:
      aObject - the Java object to be marshalled.
      aRootElementName - the name of the root element of the resulting XML data.
      aDestination - the OutputStream to which the resulting XML data should be written.
      aDocumentContext - the document context to be used during marshalling.
      Throws:
      XMLStreamException - if an unexpected processing exception occurs during marshalling.
      IOException - if an java.io.IOException occurs during marshalling.
    • getMarshallerProvider

      public TLcdXMLMarshallerProvider getMarshallerProvider()
      Returns the marshaller provider for this XML encoder, containing marshallers for converting Java object graphs to XML data.
      Returns:
      the marshaller provider for this XML encoder.
    • getMapping

      public TLcdXMLMapping getMapping()
      Returns the TLcdXMLMapping associated with this encoder.
      Returns:
      the TLcdXMLMapping associated with this decoder.
    • registerNamespaceURI

      public void registerNamespaceURI(String aNamespaceURI, String aPrefix)
      Registers the specified namespace on this encoder. Namespaces should be registered to indicate that they are supported by this encoder.
      Parameters:
      aNamespaceURI - the namespace for which marshallers are registered on this encoder.
      aPrefix - the preferred prefix to be used for encoding elements in the specified namespace. If aPrefix was already registered for another namespace, or aPrefix == null, the encoder will choose another prefix itself.
    • getNamespaceURIs

      public Set<String> getNamespaceURIs()
      Returns the set of namespaces which are supported by this encoder.
      Returns:
      the set of namespaces which aresupported by this encoder.