Package com.luciad.model
Class TLcdCompositeModelDecoder
java.lang.Object
com.luciad.model.TLcdCompositeModelDecoder
- All Implemented Interfaces:
ILcdInputStreamFactoryCapable
,ILcdDataSourceModelDecoder
,ILcdModelDecoder
public class TLcdCompositeModelDecoder
extends Object
implements ILcdModelDecoder, ILcdDataSourceModelDecoder, ILcdInputStreamFactoryCapable
Composite implementation of
This will use all model decoders annotated with the
ILcdModelDecoder
.
Any number of model decoders can be added to this composite.
The decode(java.lang.String)
delegates, in order, to the decoders in the list who can decode
the source.
See decode(String)
for details.
Example usage:
To create a composite instance which uses all default availableILcdModelDecoder
instances, you can use:
ILcdModelDecoder modelDecoder =
new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
@LcdService
annotation.- Since:
- 2013.0
-
Constructor Summary
ConstructorDescriptionCreates a new, empty composite model decoder.TLcdCompositeModelDecoder
(ILcdModelDecoder... aModelDecoders) Creates a new composite model decoder containing the supplied delegate decoders.TLcdCompositeModelDecoder
(Iterable<? extends ILcdModelDecoder> aModelDecoders) Creates a new composite model decoder that lazily uses the given Iterable to delegate to. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeSource
(ILcdDataSource aDataSource) Checks whether this model decoder can decode the data source(s), identified by the passedILcdDataSource
.boolean
canDecodeSource
(String aSourceName) Checks whether this model decoder can decode the specified data source.Decode the given data source through a suitable delegate model decoder.decodeModelMetadata
(ILcdDataSource aDataSource) Decodes the model metadata of the given data source through a suitable delegate model decoder.decodeModelMetadata
(String aSourceName) Decodes the model metadata of the given data source through a suitable delegate model decoder.decodeSource
(ILcdDataSource aDataSource) Decode the given data source through a suitable delegate model decoder.List
<? extends ILcdDataSource> discoverDataSources
(String aPath) Delegates to all decoders whosecanDecodeSource(String)
returns true for the given path.findModelDecoders
(ILcdDataSource aDataSource) Returns all model decoders thatcan decode
the given data sourcefindModelDecoders
(String aSourceName) Returns all model decoders thatcan decode
the given source nameReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.Returns the input stream factory that is used.Returns the list of delegate model decoders contained in this composite.void
setDisplayName
(String aDisplayName) Sets the display name for this model decodervoid
setInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory) If not null, overrides the input stream factory of the contained model decoders with the given factory.
-
Constructor Details
-
TLcdCompositeModelDecoder
public TLcdCompositeModelDecoder()Creates a new, empty composite model decoder. This decoder will not be able to create models until delegate model decoders are added to themodel decoder list
. -
TLcdCompositeModelDecoder
Creates a new composite model decoder that lazily uses the given Iterable to delegate to.- Parameters:
aModelDecoders
- anIterable
of model decoders
-
TLcdCompositeModelDecoder
Creates a new composite model decoder containing the supplied delegate decoders.- Parameters:
aModelDecoders
- delegate decoders to be added to the composite
-
-
Method Details
-
getModelDecoders
Returns the list of delegate model decoders contained in this composite. If the factory does not use an Iterable, delegates can be added or removed by modifying this list.- Returns:
- the list of delegate model decoders in this composite
-
findModelDecoders
Returns all model decoders thatcan decode
the given source name- Parameters:
aSourceName
- the source name to return the compatible model decoders for.- Returns:
- a list containing all decoders that can open the given source
-
findModelDecoders
Returns all model decoders thatcan decode
the given data source- Parameters:
aDataSource
- the data source to return the compatible model decoders for.- Returns:
- a list containing all decoders that can open the given source
- Since:
- 2017.0
-
getDisplayName
Description copied from interface:ILcdModelDecoder
Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.- Specified by:
getDisplayName
in interfaceILcdModelDecoder
- Returns:
- the displayable name of this
ILcdModelDecoder
.
-
setDisplayName
Sets the display name for this model decoder- Parameters:
aDisplayName
- The display name- See Also:
-
canDecodeSource
Description copied from interface:ILcdModelDecoder
Checks whether this model decoder can decode the specified data source. It is acceptable for this method to returntrue
for a source name whiledecode
throws an exception for that same source name.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the data source to be verified; typically a file name or a URL.- Returns:
true
if this decoder can likely decode the data specified by the source name,false
otherwise.- See Also:
-
decode
Decode the given data source through a suitable delegate model decoder. Notes:- Tries all delegate decoders that
can decode
the source, in order. - The first successfully created non-null model is returned.
- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the source for which a model should be created- Returns:
- a model created by the selected delegate decoder
- Throws:
IOException
-- If a delegate model decoder returns a null value, an
IOException
will be thrown. - If no delegate model decoder returns a non-null value, an
IOException
will be thrown. - If one or more delegate model decoders throw an
IOException
and no other delegate model decoder returns a non-null value, anIOException
will be thrown containing every suppressed exception. - If a delegate decoder throws an
InterruptedIOException
, the decoding stops and that exception is re-thrown.
- If a delegate model decoder returns a null value, an
- See Also:
- Tries all delegate decoders that
-
canDecodeSource
Description copied from interface:ILcdModelDecoder
Checks whether this model decoder can decode the data source(s), identified by the passed
ILcdDataSource
.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the instance class of
aDataSource
, or check the file extension if it is aTLcdDataSource
.The default implementation of this method will check if the given
ILcdDataSource
is aTLcdDataSource
. If not, this method returns false. Otherwise, it delegates the source to theILcdModelDecoder.canDecodeSource(String)
method.- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- theILcdModelSource
to be verified.- Returns:
true
if this decoder can likely decode the data specified byaDataSource
,false
otherwise.- See Also:
-
decodeSource
Decode the given data source through a suitable delegate model decoder. Seedecode(String)
for details.- Specified by:
decodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- the data source for which a model should be created- Returns:
- a model created by the selected delegate decoder
- Throws:
IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException { try { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }
- See Also:
-
discoverDataSources
Delegates to all decoders whosecanDecodeSource(String)
returns true for the given path. The first successfully created model is returned. If a decoder fails with anIOException
orRuntimeException
, the next decoder is tried.- Specified by:
discoverDataSources
in interfaceILcdModelDecoder
- Parameters:
aPath
- A path to the data source to be decoded; typically a file name or a URL.- Returns:
- A set of data sources for the given path
- Throws:
IOException
- When- No delegate model decoders return
true
forcanDecodeSource(String)
for the supplied path. - Any delegate model decoder throws an
IOException
, and no data sources could be retrieved. - an
IOException
will be thrown containing every suppressed exception.
- No delegate model decoders return
-
decodeModelMetadata
Decodes the model metadata of the given data source through a suitable delegate model decoder. Notes:- Tries all delegate decoders that return
true
forILcdModelDecoder.canDecodeSource(java.lang.String)
with the given the aSourceName, in order. - The first successfully created
TLcdModelMetadata
instance is returned. - Even if
canDecodeSource(java.lang.String)
returnstrue
, there is no guarantee that this method will be able to decode aSourceName.
- Specified by:
decodeModelMetadata
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the source from which model metadata should be extracted.- Returns:
- a
TLcdModelMetadata
instance, created by the selected delegate model decoder - Throws:
IOException
-- If no delegate model decoder successfully decodes the source, an
IOException
will be thrown. - If one or more delegate model decoders throw an
IOException
and no other delegate model decoder successfully decodes the source, anIOException
will be thrown containing every suppressed exception. - If a delegate decoder throws a
InterruptedIOException
, the decoding stops and that exception is re-thrown.
- If no delegate model decoder successfully decodes the source, an
- See Also:
- Tries all delegate decoders that return
-
decodeModelMetadata
Decodes the model metadata of the given data source through a suitable delegate model decoder. Notes:- Tries all delegate decoders that return
true
forILcdModelDecoder.canDecodeSource(java.lang.String)
with the given the aDataSource, in order. - The first successfully created
TLcdModelMetadata
instance is returned. - Even if
canDecodeSource(java.lang.String)
returnstrue
, there is no guarantee that this method will be able to decode aDataSource.
- Specified by:
decodeModelMetadata
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- the data source from which model metadata should be extracted.- Returns:
- a
TLcdModelMetadata
instance, created by the selected delegate model decoder - Throws:
IOException
-- If no delegate model decoder successfully decodes the source, an
IOException
will be thrown. - If one or more delegate model decoders throw an
IOException
and no other delegate model decoder successfully decodes the source, anIOException
will be thrown containing every suppressed exception. - If a delegate decoder throws a
InterruptedIOException
, the decoding stops and that exception is re-thrown.
- If no delegate model decoder successfully decodes the source, an
- See Also:
- Tries all delegate decoders that return
-
setInputStreamFactory
If not null, overrides the input stream factory of the contained model decoders with the given factory.- Specified by:
setInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Parameters:
aInputStreamFactory
- the input stream factory to be used.
-
getInputStreamFactory
Description copied from interface:ILcdInputStreamFactoryCapable
Returns the input stream factory that is used.- Specified by:
getInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Returns:
- the input stream factory that is used.
-