Class TLcyCompositeModelEncoder
- All Implemented Interfaces:
ILcyModelEncoderContainer
,ILcdModelEncoder
,Serializable
,Iterable<TLcyModelEncoderHolder>
Composite implementation (see composite design pattern) of ILcdModelEncoder
. It
keeps a list of associated ILcdModelEncoder
s. When it is asked to encode a model, it
loops over its associated ILcdModelEncoder
s to find a suitable
ILcdModelEncoder
. That ILcdModelEncoder
is asked to encode the
model.
When creating a new TLcyCompositeModelEncoder
using the default constructor (see
TLcyCompositeModelEncoder()
), the created instance will only work on/with the ILcdModelEncoders registered on this composite instance (see addModelEncoder(com.luciad.model.ILcdModelEncoder, ALcyFileTypeDescriptor)
and removeModelEncoder(com.luciad.model.ILcdModelEncoder)
).
When creating a new TLcyCompositeModelEncoder
using the constructor specifying an
ILcyLucyEnv
instance (see TLcyCompositeModelEncoder(com.luciad.lucy.ILcyLucyEnv)
),
the created instance will work on the Lucy back-end services. It will use all registered ILcdModelEncoder instances of the Lucy back-end, adding and/or removing an
ILcdModelEncoder
will add/remove the ILcdModelEncoder
as service from Lucy, ... .
Encoding 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
TLcyCompositeModelEncoder encoder = new TLcyCompositeModelEncoder( aLucyEnv );
if ( encoder.canSave( aModel ) ){
try{
encoder.save( aModel );
} catch ( IllegalArgumentException aException ){
//IllegalArgumentException during saving
} catch ( IOException aIOException ){
//IOException during saving
}
}
//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
encoder = null;
Note: the ILcdModelEncoder
s are not directly registered as service to
Lucy, but wrapped with a holder object.
This holder object allows to register the ILcdModelEncoder
with some extra
information like e.g. an ALcyFileTypeDescriptor
. Using a back-end based
TLcyCompositeModelEncoder
will only use the registered TLcyModelEncoderHolder
objects, and not for example an
ILcdModelEncoder
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.TLcyCompositeModelEncoder
(ILcyLucyEnv aLucyEnv) Construct aTLcyCompositeModelEncoder
working on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addModelEncoder
(ILcdModelEncoder aModelEncoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model encoder to this container.boolean
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
.boolean
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
.void
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
.Returns a short, displayable name for the format thisILcdModelEncoder
encodes to.getEncoderFileTypeDescriptor
(int aIndex) Retursn the file type descriptor at the given index, or null if the encoder was added with null as a descriptor.getModelEncoder
(int aIndex) Returns the model encoder at the given index.int
Returns the number of model encoders currently in this container.void
removeModelEncoder
(ILcdModelEncoder aModelEncoder) Removes the given model encoder from this container.void
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
.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 java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TLcyCompositeModelEncoder
public TLcyCompositeModelEncoder()Default constructor. No
ILcdModelEncoder
s are associated.The created instance will only work on the
ILcdModelEncoder
instances registered to it. If you want to use all registeredILcdModelEncoder
instances of the Lucy back-end, useTLcyCompositeModelEncoder(com.luciad.lucy.ILcyLucyEnv)
instead.- See Also:
-
TLcyCompositeModelEncoder
Construct a
TLcyCompositeModelEncoder
working on the Lucy back-end.It will use all
ILcdModelEncoder
instances registered to the back-end, and adding and/or removingILcdModelEncoder
s to/from thisTLcyCompositeModelEncoder
will respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeModelEncoder
which does not use the back-end, useTLcyCompositeModelEncoder()
instead.- Parameters:
aLucyEnv
- The Lucy back-end.- See Also:
-
-
Method Details
-
addModelEncoder
public void addModelEncoder(ILcdModelEncoder aModelEncoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model encoder to this container.If the constructor specifying an
ILcyLucyEnv
is used, theALcyFileTypeDescriptor
and its associatedILcdModelEncoder
will be registered on the Lucy back-end (seeILcyLucyEnv.addService(Object, int)
by using anTLcyModelEncoderHolder
. When callingILcyLucyEnv.getServices(Class)
afterwards, the holder objects will only be returned when the requested class wasTLcyModelEncoderHolder.class
.
Note: if you want to remove the registeredALcyFileTypeDescriptor
and its associatedILcdModelEncoder
, useremoveModelEncoder(com.luciad.model.ILcdModelEncoder)
and notILcyLucyEnv.removeService(Object)
.- Specified by:
addModelEncoder
in interfaceILcyModelEncoderContainer
- Parameters:
aModelEncoder
- The model encoder to addaFileTypeDescriptor
- Descriptor that provides additional information about the file types this decoder can handle, or null if this encoder does not work with files.- See Also:
-
removeModelEncoder
Removes the given model encoder from this container. Does nothing if the given encoder was not in this container.If the constructor specifying an
ILcyLucyEnv
is used, theTLcyModelEncoderHolder
object containing theILcdModelEncoder
aModelEncoder
will be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)
).
Note: it is only possible to removeTLcyModelEncoderHolder
instances which were registered using theaddModelEncoder(com.luciad.model.ILcdModelEncoder, ALcyFileTypeDescriptor)
method.- Specified by:
removeModelEncoder
in interfaceILcyModelEncoderContainer
- Parameters:
aModelEncoder
- The model encoder to remove.- See Also:
-
getModelEncoderCount
public int getModelEncoderCount()Description copied from interface:ILcyModelEncoderContainer
Returns the number of model encoders currently in this container.- Specified by:
getModelEncoderCount
in interfaceILcyModelEncoderContainer
- Returns:
- the number of model encoders currently in this container.
-
getModelEncoder
Description copied from interface:ILcyModelEncoderContainer
Returns the model encoder at the given index.- Specified by:
getModelEncoder
in interfaceILcyModelEncoderContainer
- Parameters:
aIndex
- The index of the asked model encoder. Make sure0 <= aIndex < getModelEncoderCount()
- Returns:
- The model encoder at the given index.
-
getEncoderFileTypeDescriptor
Description copied from interface:ILcyModelEncoderContainer
Retursn the file type descriptor at the given index, or null if the encoder was added with null as a descriptor.- Specified by:
getEncoderFileTypeDescriptor
in interfaceILcyModelEncoderContainer
- 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:ILcdModelEncoder
Returns a short, displayable name for the format thisILcdModelEncoder
encodes to.- Specified by:
getDisplayName
in interfaceILcdModelEncoder
- Returns:
- the displayable name of this
ILcdModelEncoder
.
-
canSave
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
. Suitable means that canSave returns true. This method returns true if such a suitableILcdModelEncoder
could be found, false otherwise.- Specified by:
canSave
in interfaceILcdModelEncoder
- Parameters:
aModel
- The model to encode.- Returns:
- true if such a suitable
ILcdModelEncoder
could be found, false otherwise. - See Also:
-
save
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
. Suitable means that canSave returns true. It delegates the saving to the first suitableILcdModelEncoder
that was found.- Specified by:
save
in interfaceILcdModelEncoder
- Parameters:
aModel
- The model to save.- Throws:
IOException
- if an I/O error occurs during encoding.
-
canExport
Loops over its associated list ofILcdModelEncoder
s to find a suitableILcdModelEncoder
. Suitable means that canExport returns true. This method returns true if such a suitableILcdModelEncoder
could be found, false otherwise.- Specified by:
canExport
in interfaceILcdModelEncoder
- Parameters:
aModel
- The model to export.aDestinationName
- The destination name to export to.- Returns:
- True if such a suitable
ILcdModelEncoder
could be found, false otherwise. - See Also:
-
export
Loops over its associated list of
ILcdModelEncoder
s to find a suitableILcdModelEncoder
. Suitable means that whencanExport
is invoked, it returnstrue
.It will first loop over all model encoders for which the associated
ALcyFileTypeDescriptor
acceptsaDestinationName
. The export will be delegated to the first of those encoders for which thecanExport
returnstrue
.When none of those model encoders is suitable, it will loop over all available model encoders, and delegate the export to the first suitable one.
- Specified by:
export
in interfaceILcdModelEncoder
- Parameters:
aModel
- The model to export.aDestinationName
- The destination name to export to.- Throws:
IOException
- if an I/O error occurs during encoding.
-