public class TLcdCompositeModelDecoder extends Object implements ILcdModelDecoder,ILcdDataSourceModelDecoder, ILcdInputStreamFactoryCapable
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.
ILcdModelDecoder
instances, you can use:
ILcdModelDecoder modelDecoder =
new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
This will use all model decoders annotated with the @LcdService
annotation.Constructor and Description |
---|
TLcdCompositeModelDecoder()
Creates 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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(ILcdDataSource aDataSource)
Checks whether this model decoder can decode the data source(s), identified by the passed
ILcdDataSource . |
boolean |
canDecodeSource(String aSourceName)
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(String aSourceName)
Decode the given data source through a suitable delegate model decoder.
|
TLcdModelMetadata |
decodeModelMetadata(ILcdDataSource aDataSource)
<
Decodes the model metadata of the given data source through a suitable delegate model decoder.
|
TLcdModelMetadata |
decodeModelMetadata(String aSourceName)
Decodes the model metadata of the given data source through a suitable delegate model decoder.
|
ILcdModel |
decodeSource(ILcdDataSource aDataSource)
Decode the given data source through a suitable delegate model decoder.
|
List<? extends ILcdDataSource> |
discoverDataSources(String aPath)
Delegates to all decoders whose
canDecodeSource(String) returns true for the
given path. |
List<ILcdModelDecoder> |
findModelDecoders(ILcdDataSource aDataSource)
Returns all model decoders that
can decode the given data source |
List<ILcdModelDecoder> |
findModelDecoders(String aSourceName)
Returns all model decoders that
can decode the given source name |
String |
getDisplayName()
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the input stream factory that is used.
|
List<ILcdModelDecoder> |
getModelDecoders()
Returns the list of delegate model decoders contained in this composite.
|
void |
setDisplayName(String aDisplayName)
Sets the display name for this model decoder
|
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
If not null, overrides the input stream factory of the contained model decoders with the given
factory.
|
public TLcdCompositeModelDecoder()
model decoder list
.public TLcdCompositeModelDecoder(Iterable<? extends ILcdModelDecoder> aModelDecoders)
aModelDecoders
- an Iterable
of model decoderspublic TLcdCompositeModelDecoder(ILcdModelDecoder... aModelDecoders)
aModelDecoders
- delegate decoders to be added to the compositepublic List<ILcdModelDecoder> getModelDecoders()
public List<ILcdModelDecoder> findModelDecoders(String aSourceName)
can decode
the given source nameaSourceName
- the source name to return the compatible model decoders for.public List<ILcdModelDecoder> findModelDecoders(ILcdDataSource aDataSource)
can decode
the given data sourceaDataSource
- the data source to return the compatible model decoders for.public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.getDisplayName
in interface ILcdModelDecoder
ILcdModelDecoder
.public void setDisplayName(String aDisplayName)
aDisplayName
- The display namegetDisplayName()
public boolean canDecodeSource(String aSourceName)
ILcdModelDecoder
true
for a source name while decode
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.
canDecodeSource
in interface ILcdModelDecoder
aSourceName
- the data source to be verified; typically a file name or a URL.true
if this decoder can likely decode the data specified by the source name, false
otherwise.ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
can decode
the source, in order.decode
in interface ILcdModelDecoder
aSourceName
- the source for which a model should be createdIOException
- IOException
will be thrown.IOException
will be thrown.IOException
and no other delegate model decoder returns a non-null value, an IOException
will be thrown containing every suppressed exception.InterruptedIOException
, the decoding stops and that exception is re-thrown.ILcdModelDecoder.canDecodeSource(String)
public boolean canDecodeSource(ILcdDataSource aDataSource)
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 a TLcdDataSource
.
The default implementation of this method will check if the given ILcdDataSource
is a
TLcdDataSource
. If not, this method returns false. Otherwise, it delegates
the source to the ILcdModelDecoder.canDecodeSource(String)
method.
canDecodeSource
in interface ILcdModelDecoder
aDataSource
- the ILcdModelSource
to be verified.true
if this decoder can likely decode the data specified by aDataSource
, false
otherwise.ILcdModelDecoder.decodeSource(ILcdDataSource)
,
ILcdModelDecoder.decodeModelMetadata(ILcdDataSource)
public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
decode(String)
for details.decodeSource
in interface ILcdModelDecoder
aDataSource
- the data source for which a model should be createdIOException
- 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);
}
}
ILcdModelDecoder.canDecodeSource(ILcdDataSource)
public List<? extends ILcdDataSource> discoverDataSources(String aPath) throws IOException
canDecodeSource(String)
returns true for the
given path.
The first successfully created model is returned. If a decoder fails with an IOException
or RuntimeException
,
the next decoder is tried.discoverDataSources
in interface ILcdModelDecoder
aPath
- A path to the data source to be decoded; typically a file name or a URL.IOException
- When
true
for canDecodeSource(String)
for the supplied path.IOException
, and no data sources could be retrieved.IOException
will be thrown containing every suppressed exception.public TLcdModelMetadata decodeModelMetadata(String aSourceName) throws IOException
true
for ILcdModelDecoder.canDecodeSource(java.lang.String)
with the given the aSourceName, in order.TLcdModelMetadata
instance is returned.canDecodeSource(java.lang.String)
returns true
, there is no guarantee that this method will be able to decode aSourceName.decodeModelMetadata
in interface ILcdModelDecoder
aSourceName
- the source from which model metadata should be extracted.TLcdModelMetadata
instance, created by the selected delegate model decoderIOException
- IOException
will be thrown.IOException
and no other delegate model decoder successfully decodes the source,
an IOException
will be thrown containing every suppressed exception.InterruptedIOException
, the decoding stops and that exception is re-thrown.ILcdModelDecoder.canDecodeSource(String)
public TLcdModelMetadata decodeModelMetadata(ILcdDataSource aDataSource) throws IOException
true
for ILcdModelDecoder.canDecodeSource(java.lang.String)
with the given the aDataSource, in order.TLcdModelMetadata
instance is returned.canDecodeSource(java.lang.String)
returns true
, there is no guarantee that this method will be able to decode aDataSource.decodeModelMetadata
in interface ILcdModelDecoder
aDataSource
- the data source from which model metadata should be extracted.TLcdModelMetadata
instance, created by the selected delegate model decoderIOException
- IOException
will be thrown.IOException
and no other delegate model decoder successfully decodes the source,
an IOException
will be thrown containing every suppressed exception.InterruptedIOException
, the decoding stops and that exception is re-thrown.ILcdModelDecoder.canDecodeSource(ILcdDataSource)
public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
aInputStreamFactory
- the input stream factory to be used.public ILcdInputStreamFactory getInputStreamFactory()
ILcdInputStreamFactoryCapable
getInputStreamFactory
in interface ILcdInputStreamFactoryCapable