Class TLcyCompositeModelDecoder
- All Implemented Interfaces:
ILcyModelDecoderContainer,ILcdDataSourceModelDecoder,ILcdModelDecoder,Iterable<TLcyModelDecoderHolder>
Composite implementation (see composite design pattern) of ILcdModelDecoder. It
keeps a list of associated ILcdModelDecoders. When it is asked to decode a model, it
loops over its associated ILcdModelDecoders 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 ILcdModelDecoders 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
ConstructorsConstructorDescriptionDefault constructor.TLcyCompositeModelDecoder(ILcyLucyEnv aLucyEnv) Construct aTLcyCompositeModelDecoderworking on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModelDecoder(ILcdModelDecoder aModelDecoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model decoder to this container.booleancanDecodeSource(ILcdDataSource aDataSource) Loops over its associated list ofILcdModelDecoders to find a suitableILcdModelDecoder.booleancanDecodeSource(String aSourceName) Loops over its associated list ofILcdModelDecoders to find a suitableILcdModelDecoder.Loops over its associated list ofILcdModelDecoders to find a suitableILcdModelDecoder.decodeSource(ILcdDataSource aDataSource) Loops over its associated list ofILcdModelDecoders 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.intReturns the number of model decoders currently in this container.voidremoveModelDecoder(ILcdModelDecoder aModelDecoder) Removes the given model decoder from this container.Methods inherited from class com.luciad.lucy.util.TLcyGenericComposite
add, add, getList, getPriority, iterator, removeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.model.ILcdModelDecoder
decodeModelMetadata, decodeModelMetadata, discoverDataSourcesMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TLcyCompositeModelDecoder
public TLcyCompositeModelDecoder()Default constructor. No
ILcdModelDecoders are associated.The created instance will only work on the
ILcdModelDecoderinstances registered to it. If you want to use all registeredILcdModelDecoderinstances of the Lucy back-end, useTLcyCompositeModelDecoder(com.luciad.lucy.ILcyLucyEnv)instead.- See Also:
-
TLcyCompositeModelDecoder
Construct a
TLcyCompositeModelDecoderworking on the Lucy back-end.It will use all
ILcdModelDecoderinstances registered to the back-end, and adding and/or removingILcdModelDecoders to/from thisTLcyCompositeModelDecoderwill respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeModelDecoderwhich 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
ILcyLucyEnvis used, theALcyFileTypeDescriptorand its associatedILcdModelDecoderwill 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 registeredALcyFileTypeDescriptorand its associatedILcdModelDecoder, useremoveModelDecoder(com.luciad.model.ILcdModelDecoder)and notILcyLucyEnv.removeService(Object).- Specified by:
addModelDecoderin 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 correspondingALcyFileTypeDescriptoris also removed.If the constructor specifying an
ILcyLucyEnvis used, theTLcyModelDecoderHolderobject containing theILcdModelDecoderaModelDecoderwill be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)).
Note: it is only possible to removeTLcyModelDecoderHolderinstances which were registered using theaddModelDecoder(com.luciad.model.ILcdModelDecoder, ALcyFileTypeDescriptor)method.- Specified by:
removeModelDecoderin interfaceILcyModelDecoderContainer- Parameters:
aModelDecoder- The model decoder to remove.- See Also:
-
getModelDecoderCount
public int getModelDecoderCount()Description copied from interface:ILcyModelDecoderContainerReturns the number of model decoders currently in this container.- Specified by:
getModelDecoderCountin interfaceILcyModelDecoderContainer- Returns:
- the number of model decoders currently in this container.
-
getModelDecoder
Description copied from interface:ILcyModelDecoderContainerReturns the model decoder at the given index.- Specified by:
getModelDecoderin 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:ILcyModelDecoderContainerRetrieves the file type descriptor at the given index, or null if the decoder was added with null as a descriptor.- Specified by:
getDecoderFileTypeDescriptorin 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:ILcdModelDecoderReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder.- Specified by:
getDisplayNamein interfaceILcdModelDecoder- Returns:
- the displayable name of this
ILcdModelDecoder.
-
canDecodeSource
Loops over its associated list ofILcdModelDecoders to find a suitableILcdModelDecoder. Suitable means that canDecodeSource returns true. If it can find such a suitableILcdModelDecoderit returns true, false otherwise.- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aSourceName- The name of the source to decode.- Returns:
- True if a suitable
ILcdModelDecodercould be found, false otherwise. - See Also:
-
canDecodeSource
Loops over its associated list ofILcdModelDecoders to find a suitableILcdModelDecoder. Suitable means that canDecodeSource returns true. If it can find such a suitableILcdModelDecoderit returns true, false otherwise.- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aDataSource- The object identifying the data source(s) to decode.- Returns:
- True if a suitable
ILcdModelDecodercould be found, false otherwise. - See Also:
-
decode
Loops over its associated list of
ILcdModelDecoders to find a suitableILcdModelDecoder. Suitable means that canDecodeSource returns true.It will first loop over all model decoders for which the associated
ALcyFileTypeDescriptoracceptsaSourceName. The decode will be delegated to the first of those decoders for which thecanDecodereturnstrue.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:
decodein 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 ofILcdModelDecoders to find a suitableILcdModelDecoder. Suitable means that canDecodeSource returns true.The first suitable
ILcdModelDecoderis used to decode the given source.- Specified by:
decodeSourcein 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:
-