Package com.luciad.format.xml.bind
Class TLcdXMLEncoder
java.lang.Object
com.luciad.format.xml.bind.TLcdXMLEncoder
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionCreate a new, emptyTLcdXMLEncoder
.TLcdXMLEncoder
(ILcdXMLEncoderLibrary aLibrary) Create a newTLcdXMLEncoder
for the specified encoder library.TLcdXMLEncoder
(List<ILcdXMLEncoderLibrary> aLibraries) Create a newTLcdXMLEncoder
for the specified encoder libraries.TLcdXMLEncoder
(List<ILcdXMLEncoderLibrary> aLibraries, TLcdXMLMapping aMapping) -
Method Summary
Modifier and TypeMethodDescriptionCreates a newILcdXMLDocumentContext
that can be used during encoding of an XML document.void
encode
(Object aObject, OutputStream aDestination) Marshals the specified Java object to XML data, written to the specifiedOutputStream
.void
encode
(Object aObject, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) Marshals the specified Java object to XML data, written to the specifiedOutputStream
.void
Marshals the specified Java object to XML data, written to the specified destination.void
encode
(Object aObject, QName aRootElementName, OutputStream aDestination) Marshals the specified Java object to XML data, written to the specifiedOutputStream
.void
encode
(Object aObject, QName aRootElementName, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) Marshals the specified Java object to XML data, written to the specifiedOutputStream
.Returns theTLcdXMLMapping
associated with this encoder.Returns the marshaller provider for this XML encoder, containing marshallers for converting Java object graphs to XML data.Returns the set of namespaces which are supported by this encoder.Returns thecom.luciad.io.ILcdOutputStreamFactory
that is used by this encoder for creating output streams.Returns thejavax.xml.stream.XMLOutputFactory
that is used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.void
registerNamespaceURI
(String aNamespaceURI, String aPrefix) Registers the specified namespace on this encoder.void
setOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory) Sets thecom.luciad.io.ILcdOutputStreamFactory
that is to be used by this encoder for creating output streams.void
setXMLOutputFactory
(XMLOutputFactory aXMLOutputFactory) Sets thejavax.xml.stream.XMLOutputFactory
to be used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.
-
Constructor Details
-
TLcdXMLEncoder
public TLcdXMLEncoder()Create a new, emptyTLcdXMLEncoder
. -
TLcdXMLEncoder
Create a newTLcdXMLEncoder
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
Create a newTLcdXMLEncoder
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
-
-
Method Details
-
getOutputStreamFactory
Returns thecom.luciad.io.ILcdOutputStreamFactory
that is used by this encoder for creating output streams.- Specified by:
getOutputStreamFactory
in interfaceILcdOutputStreamFactoryCapable
- Returns:
- the
com.luciad.io.ILcdOutputStreamFactory
that is used by this encoder for creating output streams.
-
setOutputStreamFactory
Sets thecom.luciad.io.ILcdOutputStreamFactory
that is to be used by this encoder for creating output streams.- Specified by:
setOutputStreamFactory
in interfaceILcdOutputStreamFactoryCapable
- Parameters:
aOutputStreamFactory
- thecom.luciad.io.ILcdOutputStreamFactory
that is to beused by this encoder for creating output streams.
-
getXMLOutputFactory
Returns thejavax.xml.stream.XMLOutputFactory
that is used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.- Returns:
- the
javax.xml.stream.XMLOutputFactory
that is used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.
-
setXMLOutputFactory
Sets thejavax.xml.stream.XMLOutputFactory
to be used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.- Parameters:
aXMLOutputFactory
- thejavax.xml.stream.XMLOutputFactory
to be used by this encoder for creatingjavax.xml.stream.XMLStreamWriter
instances.
-
createDocumentContext
Creates a newILcdXMLDocumentContext
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
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 anjava.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 specifiedOutputStream
.- Parameters:
aObject
- the Java object to be marshalled.aDestination
- theOutputStream
to which the resulting XML data should be written.- Throws:
XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if anjava.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 specifiedOutputStream
.- Parameters:
aObject
- the Java object to be marshalled.aRootElementName
- the name of the root element of the resulting XML data.aDestination
- theOutputStream
to which the resulting XML data should be written.- Throws:
XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if anjava.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 specifiedOutputStream
.- Parameters:
aObject
- the Java object to be marshalled.aDestination
- theOutputStream
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 anjava.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 specifiedOutputStream
.- Parameters:
aObject
- the Java object to be marshalled.aRootElementName
- the name of the root element of the resulting XML data.aDestination
- theOutputStream
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 anjava.io.IOException
occurs during marshalling.
-
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
Returns theTLcdXMLMapping
associated with this encoder.- Returns:
- the
TLcdXMLMapping
associated with this decoder.
-
registerNamespaceURI
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. IfaPrefix
was already registered for another namespace, oraPrefix == null
, the encoder will choose another prefix itself.
-
getNamespaceURIs
Returns the set of namespaces which are supported by this encoder.- Returns:
- the set of namespaces which aresupported by this encoder.
-