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
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionbooleancanDecodeSource(ILcdDataSource aDataSource) Checks whether this model decoder can decode the data source(s), identified by the passedILcdDataSource.booleancanDecodeSource(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 decodethe given data sourcefindModelDecoders(String aSourceName) Returns all model decoders thatcan decodethe 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.voidsetDisplayName(String aDisplayName) Sets the display name for this model decodervoidsetInputStreamFactory(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- anIterableof 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 decodethe 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 decodethe 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:ILcdModelDecoderReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder.- Specified by:
getDisplayNamein 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:ILcdModelDecoderChecks whether this model decoder can decode the specified data source. It is acceptable for this method to returntruefor a source name whiledecodethrows 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:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aSourceName- the data source to be verified; typically a file name or a URL.- Returns:
trueif this decoder can likely decode the data specified by the source name,falseotherwise.- See Also:
-
decode
Decode the given data source through a suitable delegate model decoder. Notes:- Tries all delegate decoders that
can decodethe source, in order. - The first successfully created non-null model is returned.
- Specified by:
decodein 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
IOExceptionwill be thrown. - If no delegate model decoder returns a non-null value, an
IOExceptionwill be thrown. - If one or more delegate model decoders throw an
IOExceptionand no other delegate model decoder returns a non-null value, anIOExceptionwill 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:ILcdModelDecoderChecks 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
ILcdDataSourceis aTLcdDataSource. If not, this method returns false. Otherwise, it delegates the source to theILcdModelDecoder.canDecodeSource(String)method.- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aDataSource- theILcdModelSourceto be verified.- Returns:
trueif this decoder can likely decode the data specified byaDataSource,falseotherwise.- See Also:
-
decodeSource
Decode the given data source through a suitable delegate model decoder. Seedecode(String)for details.- Specified by:
decodeSourcein 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 anIOExceptionorRuntimeException, the next decoder is tried.- Specified by:
discoverDataSourcesin 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
trueforcanDecodeSource(String)for the supplied path. - Any delegate model decoder throws an
IOException, and no data sources could be retrieved. - an
IOExceptionwill 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
trueforILcdModelDecoder.canDecodeSource(java.lang.String)with the given the aSourceName, in order. - The first successfully created
TLcdModelMetadatainstance is returned. - Even if
canDecodeSource(java.lang.String)returnstrue, there is no guarantee that this method will be able to decode aSourceName.
- Specified by:
decodeModelMetadatain interfaceILcdModelDecoder- Parameters:
aSourceName- the source from which model metadata should be extracted.- Returns:
- a
TLcdModelMetadatainstance, created by the selected delegate model decoder - Throws:
IOException-- If no delegate model decoder successfully decodes the source, an
IOExceptionwill be thrown. - If one or more delegate model decoders throw an
IOExceptionand no other delegate model decoder successfully decodes the source, anIOExceptionwill 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
trueforILcdModelDecoder.canDecodeSource(java.lang.String)with the given the aDataSource, in order. - The first successfully created
TLcdModelMetadatainstance is returned. - Even if
canDecodeSource(java.lang.String)returnstrue, there is no guarantee that this method will be able to decode aDataSource.
- Specified by:
decodeModelMetadatain interfaceILcdModelDecoder- Parameters:
aDataSource- the data source from which model metadata should be extracted.- Returns:
- a
TLcdModelMetadatainstance, created by the selected delegate model decoder - Throws:
IOException-- If no delegate model decoder successfully decodes the source, an
IOExceptionwill be thrown. - If one or more delegate model decoders throw an
IOExceptionand no other delegate model decoder successfully decodes the source, anIOExceptionwill 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:
setInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Parameters:
aInputStreamFactory- the input stream factory to be used.
-
getInputStreamFactory
Description copied from interface:ILcdInputStreamFactoryCapableReturns the input stream factory that is used.- Specified by:
getInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Returns:
- the input stream factory that is used.
-