public class TLcdXMLSchemaBasedEncoder extends Object implements ILcdOutputStreamFactoryCapable
ILcdXMLMarshaller
's and ILcdXMLTypeMarshaller
's.
This class is very similar in functionality to TLcdXMLEncoder
,
but adds extra support for XML schema:
ILcdXMLTypeMarshaller
's.TLcdXMLMarshallerProvider
will use the XML Schema substitution group information
from the XML Schema info to choose the best marshaller for each [XML element, Java class] pair.this package's documentation
and the
com.luciad.format.xml.bind package documentation
for a general
overview of the XML Binding Framework.Constructor and Description |
---|
TLcdXMLSchemaBasedEncoder()
Creates a new, empty XML encoder.
|
TLcdXMLSchemaBasedEncoder(ILcdXMLSchemaBasedEncoderLibrary aLibrary)
Creates an encoder for the specified encoder library.
|
TLcdXMLSchemaBasedEncoder(ILcdXMLSchemaBasedEncoderLibrary aLibrary,
TLcdXMLSchemaBasedMapping aMapping)
Creates an encoder for the specified encoder library.
|
TLcdXMLSchemaBasedEncoder(List<ILcdXMLSchemaBasedEncoderLibrary> aLibraries)
Creates an encoder for the specified encoder libraries.
|
TLcdXMLSchemaBasedEncoder(List<ILcdXMLSchemaBasedEncoderLibrary> aLibraries,
TLcdXMLSchemaBasedMapping aMapping)
Creates an encoder for the specified encoder libraries.
|
TLcdXMLSchemaBasedEncoder(TLcdXMLSchemaBasedMapping aMapping)
Creates a new, empty XML encoder.
|
Modifier and Type | Method and Description |
---|---|
void |
configure(TLcdDataModel aDataModel)
Configures this encoder for the given data model and all its
dependencies.
|
ILcdXMLDocumentContext |
createDocumentContext()
Creates a new
ILcdXMLDocumentContext 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 specified
OutputStream . |
void |
encode(Object aObject,
OutputStream aDestination,
ILcdXMLDocumentContext aDocumentContext)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
QName aRootElementSubstitutionGroup,
OutputStream aDestination)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
QName aRootElementSubstitutionGroup,
OutputStream aDestination,
ILcdXMLDocumentContext aDocumentContext)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
QName aRootElementSubstitutionGroup,
Result aResult,
ILcdXMLDocumentContext aDocumentContext)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
QName aRootElementSubstitutionGroup,
String aDestination,
ILcdXMLDocumentContext aDocumentContext)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
Result aResult)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
Result aResult,
ILcdXMLDocumentContext aDocumentContext)
Marshals the specified Java object to XML data, written to the specified
OutputStream . |
void |
encode(Object aObject,
String aDestination)
Marshals the specified Java object to XML data, written to the specified destination.
|
TLcdXMLSchemaBasedMapping |
getMapping()
Returns the
TLcdXMLSchemaMapping associated with this encoder. |
TLcdXMLSchemaBasedMarshallerProvider |
getMarshallerProvider()
Returns the marshaller provider for this encoder, containing marshallers for
converting Java object graphs to XML data.
|
Map<String,String> |
getNamespacePrefixes()
Returns a map containing as keys the namespaces supported by this encoder, and as values their
corresponding prefixes.
|
static Map<String,String> |
getNamespacePrefixes(ILcdXMLDocumentContext aContext)
Returns a mapping between name space and schema prefix.
|
Set<String> |
getNamespaceURIs()
Returns the set of namespaces which are supported by this encoder.
|
ILcdOutputStreamFactory |
getOutputStreamFactory()
Returns the
com.luciad.io.ILcdOutputStreamFactory that is used by this encoder for
creating output streams. |
Map<String,String> |
getSchemaLocations()
Returns a map containing as keys the namespaces supported by this encoder, and as values their
corresponding schema locations.
|
static Map<String,String> |
getSchemaLocations(ILcdXMLDocumentContext aContext)
Returns a mapping between name space and schema location.
|
TLcdXMLTypeMarshallerProvider |
getTypeMarshallerProvider()
Returns the schema type marshaller provider for this encoder, containing schema
type marshallers for converting Java object graphs to XML data.
|
XMLOutputFactory |
getXMLOutputFactory()
Returns the
javax.xml.stream.XMLOutputFactory that is used by this encoder for creating
javax.xml.stream.XMLStreamWriter instances. |
void |
registerNamespaceURI(String aNamespaceURI,
String aPrefix,
String aSchemaLocation)
Registers the specified namespace on this encoder.
|
void |
setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
Sets the
com.luciad.io.ILcdOutputStreamFactory that is to be used by this encoder for
creating output streams. |
void |
setXMLOutputFactory(XMLOutputFactory aXMLOutputFactory)
Sets the
javax.xml.stream.XMLOutputFactory to be used by this encoder for creating
javax.xml.stream.XMLStreamWriter instances. |
public TLcdXMLSchemaBasedEncoder()
public TLcdXMLSchemaBasedEncoder(TLcdXMLSchemaBasedMapping aMapping)
aMapping
- the schema mapping to be associated with this encoder. If null
,
this encoder will create an empty mapping itself.public TLcdXMLSchemaBasedEncoder(ILcdXMLSchemaBasedEncoderLibrary aLibrary)
TLcdXMLEncoder encoder = new TLcdXMLEncoder();
aLibrary.configureEncoder( this );
aLibrary
- the encoder library for which to create an encoder.public TLcdXMLSchemaBasedEncoder(List<ILcdXMLSchemaBasedEncoderLibrary> aLibraries)
TLcdXMLEncoder encoder = new TLcdXMLEncoder();
for ( ILcdXMLEncoderLibrary library : aLibraries ) {
library.configureEncoder( this );
}
aLibraries
- the encoder libraries for which to create an encoder.public TLcdXMLSchemaBasedEncoder(ILcdXMLSchemaBasedEncoderLibrary aLibrary, TLcdXMLSchemaBasedMapping aMapping)
TLcdXMLEncoder encoder = new TLcdXMLEncoder(aMapping);
aLibrary.configureEncoder( this );
aLibrary
- the encoder library for which to create an encoder.aMapping
- the schema mapping to be associated with this encoder. If null
,
this encoder will create an empty mapping itself.public TLcdXMLSchemaBasedEncoder(List<ILcdXMLSchemaBasedEncoderLibrary> aLibraries, TLcdXMLSchemaBasedMapping aMapping)
TLcdXMLEncoder encoder = new TLcdXMLEncoder(aMapping);
for ( ILcdXMLEncoderLibrary library : aLibraries ) {
library.configureEncoder( this );
}
aLibraries
- the encoder libraries for which to create an encoder.aMapping
- the schema mapping to be associated with this encoder. If null
,
this encoder will create an empty mapping itself.public ILcdOutputStreamFactory getOutputStreamFactory()
com.luciad.io.ILcdOutputStreamFactory
that is used by this encoder for
creating output streams.getOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable
com.luciad.io.ILcdOutputStreamFactory
that is used by this encoder for
creating output streams.public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
com.luciad.io.ILcdOutputStreamFactory
that is to be used by this encoder for
creating output streams.setOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable
aOutputStreamFactory
- the com.luciad.io.ILcdOutputStreamFactory
that is to beused by this encoder for
creating output streams.public XMLOutputFactory getXMLOutputFactory()
javax.xml.stream.XMLOutputFactory
that is used by this encoder for creating
javax.xml.stream.XMLStreamWriter
instances.javax.xml.stream.XMLOutputFactory
that is used by this encoder for creating
javax.xml.stream.XMLStreamWriter
instances.public void setXMLOutputFactory(XMLOutputFactory aXMLOutputFactory)
javax.xml.stream.XMLOutputFactory
to be used by this encoder for creating
javax.xml.stream.XMLStreamWriter
instances.aXMLOutputFactory
- the javax.xml.stream.XMLOutputFactory
to be used by this encoder
for creating javax.xml.stream.XMLStreamWriter
instances.public ILcdXMLDocumentContext createDocumentContext()
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.ILcdXMLDocumentContext
that can be used during encoding of an XML
document.public void encode(Object aObject, String aDestination) throws XMLStreamException, IOException
aObject
- the Java object to be marshalled.aDestination
- the data source to which the data should be written; typically a file name.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, QName aRootElementSubstitutionGroup, String aDestination, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aRootElementSubstitutionGroup
- the substitution group the root element of the resulting
XML data should be part of.aDestination
- the data source to which the data should be written; typically a file name.aDocumentContext
- the document context to be used during marshalling.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, OutputStream aDestination) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aDestination
- the OutputStream
to which the resulting XML data should be
written.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, Result aResult) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aResult
- the Result
to which the resulting XML data should be
written.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.UnsupportedOperationException
- in case the XMLOutputFactory
doesn't
support the given result.public void encode(Object aObject, QName aRootElementSubstitutionGroup, OutputStream aDestination) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aRootElementSubstitutionGroup
- the substitution group the root element of the resulting
XML data should be part of.aDestination
- the OutputStream
to which the resulting XML data
should be written.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
OutputStream
.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.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, QName aRootElementSubstitutionGroup, OutputStream aDestination, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aRootElementSubstitutionGroup
- the substitution group the root element of the resulting
XML data should be part of.aDestination
- the OutputStream
to which the resulting XML data
should be written.aDocumentContext
- the document context to be used during marshalling.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public void encode(Object aObject, Result aResult, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aResult
- the result
to which the resulting XML data
should be written.aDocumentContext
- the document context to be used during marshalling.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.UnsupportedOperationException
- in case the XMLOutputFactory
doesn't
support the given result.public void encode(Object aObject, QName aRootElementSubstitutionGroup, Result aResult, ILcdXMLDocumentContext aDocumentContext) throws XMLStreamException, IOException
OutputStream
.aObject
- the Java object to be marshalled.aRootElementSubstitutionGroup
- the substitution group the root element of the resulting
XML data should be part of.aResult
- the result
to which the resulting XML data
should be written.aDocumentContext
- the document context to be used during marshalling.XMLStreamException
- if an unexpected processing exception occurs during marshalling.IOException
- if an java.io.IOException
occurs during marshalling.public TLcdXMLSchemaBasedMarshallerProvider getMarshallerProvider()
public TLcdXMLSchemaBasedMapping getMapping()
TLcdXMLSchemaMapping
associated with this encoder. This mapping
is used by the encoder to retrieve schema information and object factories.TLcdXMLSchemaMapping
associated with this decoder.public TLcdXMLTypeMarshallerProvider getTypeMarshallerProvider()
public Set<String> getNamespaceURIs()
public Map<String,String> getSchemaLocations()
xsi:schemaLocations
attribute.public static Map<String,String> getNamespacePrefixes(ILcdXMLDocumentContext aContext)
getNamespacePrefixes()
and in the map
returned by this method, the prefix defined in this map is used.getNamespacePrefixes()
.public static Map<String,String> getSchemaLocations(ILcdXMLDocumentContext aContext)
xsi:schemaLocations
attribute.
When a name space occurs both in getNamespacePrefixes()
and in the map
returned by this method, the schema location defined in this map is used.getSchemaLocations()
.public Map<String,String> getNamespacePrefixes()
public void registerNamespaceURI(String aNamespaceURI, String aPrefix, String aSchemaLocation)
aNamespaceURI
- the namespace of an XML Schema 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.aSchemaLocation
- a location where the schema for the specified namespace can be found. This
location will be encoded in the root element of all
documents encoded by this encoder via the xsi:schemaLocations
attribute.public void configure(TLcdDataModel aDataModel)
Configures this encoder for the given data model and all its
dependencies. Configuration is done using all ILcdXMLSchemaBasedEncoderLibrary
instances that are annotated (see TLcdXMLSchemaMappingAnnotation
)
on the given data model and its dependencies.
Note that creating a new encoder and configuring it with a data model is equivalent to creating an encoder with the encoder libraries of the data model and all its dependencies as constructor parameters.
aDataModel
- the data model for which this encoder is to be configured