Class TLcyCompositeModelDecoder
- All Implemented Interfaces:
ILcyModelDecoderContainer
,ILcdDataSourceModelDecoder
,ILcdModelDecoder
,Iterable<TLcyModelDecoderHolder>
Composite implementation (see composite design pattern) of ILcdModelDecoder
. It
keeps a list of associated ILcdModelDecoder
s. When it is asked to decode a model, it
loops over its associated ILcdModelDecoder
s to find a suitable
ILcdModelDecoder
. That ILcdModelDecoder
is asked to decode a
model.
When creating a new TLcyCompositeModelDecoder
using the default constructor (see
TLcyCompositeModelDecoder()
, the created instance will only work on/with the ILcdModelDecoders registered on this composite instance (see addModelDecoder(com.luciad.model.ILcdModelDecoder, ALcyFileTypeDescriptor)
and removeModelDecoder(com.luciad.model.ILcdModelDecoder)
.
When creating a new TLcyCompositeModelDecoder
using the constructor specifying an
ILcyLucyEnv
instance (see TLcyCompositeModelDecoder(com.luciad.lucy.ILcyLucyEnv)
,
the created instance will work on the Lucy back-end services. It will use all registered ILcdModelDecoder instances of the Lucy back-end, adding and/or removing an
ILcdModelDecoder
will add/remove the ILcdModelDecoder
as service from Lucy, ... .
Decoding a source into an ILcdModel
using the back-end based implementation can
be done by creating a new instance of this class:
//Create a new instance whenever you need it
TLcyCompositeModelDecoder decoder = new TLcyCompositeModelDecoder( aLucyEnv );
try{
ILcdModel model = decoder.decode( String aSourceName );
} catch( IOException aException ){
//an IOException occurred during the decoding of aSourceName
}
//There is no need to keep a reference to the composite instance, you can create a new one
//the next time you would need it
decoder = null;
Note: the ILcdModelDecoder
s are not directly registered as service to
Lucy, but wrapped with a holder object.
This holder object allows to register the ILcdModelDecoder
with some extra
information like e.g. an ALcyFileTypeDescriptor
. Using a back-end based
TLcyCompositeModelDecoder
will only use the registered TLcyModelDecoderHolder
objects, and not for example an
ILcdModelDecoder
which was directly (=not wrapped) registered as a service .
- See Also:
-
Field Summary
Fields inherited from class com.luciad.lucy.util.TLcyGenericComposite
PRIORITY_DEFAULT, PRIORITY_FALLBACK
-
Constructor Summary
ConstructorDescriptionDefault constructor.TLcyCompositeModelDecoder
(ILcyLucyEnv aLucyEnv) Construct aTLcyCompositeModelDecoder
working on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addModelDecoder
(ILcdModelDecoder aModelDecoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model decoder to this container.boolean
canDecodeSource
(ILcdDataSource aDataSource) Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
.boolean
canDecodeSource
(String aSourceName) Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
.Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
.decodeSource
(ILcdDataSource aDataSource) Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
.getDecoderFileTypeDescriptor
(int aIndex) Retrieves the file type descriptor at the given index, or null if the decoder was added with null as a descriptor.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.getModelDecoder
(int aIndex) Returns the model decoder at the given index.int
Returns the number of model decoders currently in this container.void
removeModelDecoder
(ILcdModelDecoder aModelDecoder) Removes the given model decoder from this container.Methods inherited from class com.luciad.lucy.util.TLcyGenericComposite
add, add, getList, getPriority, iterator, remove
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.model.ILcdModelDecoder
decodeModelMetadata, decodeModelMetadata, discoverDataSources
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TLcyCompositeModelDecoder
public TLcyCompositeModelDecoder()Default constructor. No
ILcdModelDecoder
s are associated.The created instance will only work on the
ILcdModelDecoder
instances registered to it. If you want to use all registeredILcdModelDecoder
instances of the Lucy back-end, useTLcyCompositeModelDecoder(com.luciad.lucy.ILcyLucyEnv)
instead.- See Also:
-
TLcyCompositeModelDecoder
Construct a
TLcyCompositeModelDecoder
working on the Lucy back-end.It will use all
ILcdModelDecoder
instances registered to the back-end, and adding and/or removingILcdModelDecoder
s to/from thisTLcyCompositeModelDecoder
will respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeModelDecoder
which does not use the back-end, useTLcyCompositeModelDecoder()
instead.- Parameters:
aLucyEnv
- The Lucy back-end.- See Also:
-
-
Method Details
-
addModelDecoder
public void addModelDecoder(ILcdModelDecoder aModelDecoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model decoder to this container.If the constructor specifying an
ILcyLucyEnv
is used, theALcyFileTypeDescriptor
and its associatedILcdModelDecoder
will be registered on the Lucy back-end (seeILcyLucyEnv.addService(Object, int)
by using anTLcyModelDecoderHolder
. When callingILcyLucyEnv.getServices(Class)
afterwards, the holder objects will only be returned when the requested class wasTLcyModelDecoderHolder.class
Note: if you want to remove the registeredALcyFileTypeDescriptor
and its associatedILcdModelDecoder
, useremoveModelDecoder(com.luciad.model.ILcdModelDecoder)
and notILcyLucyEnv.removeService(Object)
.- Specified by:
addModelDecoder
in interfaceILcyModelDecoderContainer
- Parameters:
aModelDecoder
- The model decoder to addaFileTypeDescriptor
- The file type descriptor that provides more information on the file types this decoder can handle, or null if this decoder does not work with files.- See Also:
-
removeModelDecoder
Removes the given model decoder from this container. Does nothing if the given decoder was not in this container. The correspondingALcyFileTypeDescriptor
is also removed.If the constructor specifying an
ILcyLucyEnv
is used, theTLcyModelDecoderHolder
object containing theILcdModelDecoder
aModelDecoder
will be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)
).
Note: it is only possible to removeTLcyModelDecoderHolder
instances which were registered using theaddModelDecoder(com.luciad.model.ILcdModelDecoder, ALcyFileTypeDescriptor)
method.- Specified by:
removeModelDecoder
in interfaceILcyModelDecoderContainer
- Parameters:
aModelDecoder
- The model decoder to remove.- See Also:
-
getModelDecoderCount
public int getModelDecoderCount()Description copied from interface:ILcyModelDecoderContainer
Returns the number of model decoders currently in this container.- Specified by:
getModelDecoderCount
in interfaceILcyModelDecoderContainer
- Returns:
- the number of model decoders currently in this container.
-
getModelDecoder
Description copied from interface:ILcyModelDecoderContainer
Returns the model decoder at the given index.- Specified by:
getModelDecoder
in interfaceILcyModelDecoderContainer
- Parameters:
aIndex
- The index of the asked model decoder. Make sure 0 <= aIndex <ILcyModelDecoderContainer.getModelDecoderCount()
- Returns:
- The model decoder at the given index.
-
getDecoderFileTypeDescriptor
Description copied from interface:ILcyModelDecoderContainer
Retrieves the file type descriptor at the given index, or null if the decoder was added with null as a descriptor.- Specified by:
getDecoderFileTypeDescriptor
in interfaceILcyModelDecoderContainer
- Parameters:
aIndex
- The index to retrieve the file type descriptor for.- Returns:
- the file type descriptor at the given index.
-
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
.
-
canDecodeSource
Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
. Suitable means that canDecodeSource returns true. If it can find such a suitableILcdModelDecoder
it returns true, false otherwise.- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- The name of the source to decode.- Returns:
- True if a suitable
ILcdModelDecoder
could be found, false otherwise. - See Also:
-
canDecodeSource
Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
. Suitable means that canDecodeSource returns true. If it can find such a suitableILcdModelDecoder
it returns true, false otherwise.- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- The object identifying the data source(s) to decode.- Returns:
- True if a suitable
ILcdModelDecoder
could be found, false otherwise. - See Also:
-
decode
Loops over its associated list of
ILcdModelDecoder
s to find a suitableILcdModelDecoder
. Suitable means that canDecodeSource returns true.It will first loop over all model decoders for which the associated
ALcyFileTypeDescriptor
acceptsaSourceName
. The decode will be delegated to the first of those decoders for which thecanDecode
returnstrue
.When none of those model decoders is suitable, it will loop over all available model decoders, and delegate the decode to the first suitable one.
- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- The name of the source to decode.- Returns:
- The model decoded by the first suitable
ILcdModelDecoder
- 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 decode( String aSourceName ) throws IOException { try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }
- See Also:
-
decodeSource
Loops over its associated list ofILcdModelDecoder
s to find a suitableILcdModelDecoder
. Suitable means that canDecodeSource returns true.The first suitable
ILcdModelDecoder
is used to decode the given source.- Specified by:
decodeSource
in interfaceILcdModelDecoder
- Parameters:
aDataSource
- The object identifying the data source(s) to decode.- Returns:
- The model decoded by the first suitable
ILcdModelDecoder
- 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:
-