public class TLcyCompositeModelEncoder extends TLcyGenericComposite<TLcyModelEncoderHolder> implements ILcdModelEncoder,ILcyModelEncoderContainer
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 .
TLcyModelEncoderHolder
,
Serialized FormPRIORITY_DEFAULT, PRIORITY_FALLBACK
Constructor and Description |
---|
TLcyCompositeModelEncoder()
Default constructor.
|
TLcyCompositeModelEncoder(ILcyLucyEnv aLucyEnv)
Construct a
TLcyCompositeModelEncoder working on the Lucy back-end. |
Modifier and Type | Method and Description |
---|---|
void |
addModelEncoder(ILcdModelEncoder aModelEncoder,
ALcyFileTypeDescriptor aFileTypeDescriptor)
Adds the given model encoder to this container.
|
boolean |
canExport(ILcdModel aModel,
String aDestinationName)
Loops over its associated list of
ILcdModelEncoder s to find a suitable
ILcdModelEncoder . |
boolean |
canSave(ILcdModel aModel)
Loops over its associated list of
ILcdModelEncoder s to find a suitable
ILcdModelEncoder . |
void |
export(ILcdModel aModel,
String aDestinationName)
Loops over its associated list of
ILcdModelEncoder s to find a suitable
ILcdModelEncoder . |
String |
getDisplayName()
Returns a short, displayable name for the format this
ILcdModelEncoder encodes to. |
ALcyFileTypeDescriptor |
getEncoderFileTypeDescriptor(int aIndex)
Retursn the file type descriptor at the given index, or null if the
encoder was added with null as a descriptor.
|
ILcdModelEncoder |
getModelEncoder(int aIndex)
Returns the model encoder at the given index.
|
int |
getModelEncoderCount()
Returns the number of model encoders currently in this container.
|
void |
removeModelEncoder(ILcdModelEncoder aModelEncoder)
Removes the given model encoder from this container.
|
void |
save(ILcdModel aModel)
Loops over its associated list of
ILcdModelEncoder s to find a suitable
ILcdModelEncoder . |
add, add, getList, getPriority, iterator, remove
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
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 registered ILcdModelEncoder
instances of
the Lucy back-end, use TLcyCompositeModelEncoder(com.luciad.lucy.ILcyLucyEnv)
instead.
public TLcyCompositeModelEncoder(ILcyLucyEnv aLucyEnv)
Construct a TLcyCompositeModelEncoder
working on the Lucy back-end.
It will use all ILcdModelEncoder
instances registered to the back-end, and
adding and/or removing ILcdModelEncoder
s to/from this
TLcyCompositeModelEncoder
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, use TLcyCompositeModelEncoder()
instead.
aLucyEnv
- The Lucy back-end.TLcyCompositeModelEncoder()
,
ILcyLucyEnv.addService(Object, int)
,
ILcyLucyEnv.removeService(Object)
public void addModelEncoder(ILcdModelEncoder aModelEncoder, ALcyFileTypeDescriptor aFileTypeDescriptor)
If the constructor specifying an ILcyLucyEnv
is used, the
ALcyFileTypeDescriptor
and its associated ILcdModelEncoder
will be
registered on the Lucy back-end (see ILcyLucyEnv.addService(Object,
int)
by using an TLcyModelEncoderHolder
. When calling ILcyLucyEnv.getServices(Class)
afterwards, the holder objects will only be
returned when the requested class was TLcyModelEncoderHolder.class
.
Note: if you want to remove the registered ALcyFileTypeDescriptor
and its
associated ILcdModelEncoder
, use removeModelEncoder(com.luciad.model.ILcdModelEncoder)
and not ILcyLucyEnv.removeService(Object)
.
addModelEncoder
in interface ILcyModelEncoderContainer
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.removeModelEncoder(com.luciad.model.ILcdModelEncoder)
public void removeModelEncoder(ILcdModelEncoder aModelEncoder)
If the constructor specifying an ILcyLucyEnv
is used, the
TLcyModelEncoderHolder
object containing the ILcdModelEncoder
aModelEncoder
will be removed as service from the Lucy back-end (see ILcyLucyEnv.removeService(Object)
).
Note: it is only possible to remove TLcyModelEncoderHolder
instances which
were registered using the addModelEncoder(com.luciad.model.ILcdModelEncoder, ALcyFileTypeDescriptor)
method.
removeModelEncoder
in interface ILcyModelEncoderContainer
aModelEncoder
- The model encoder to remove.addModelEncoder(com.luciad.model.ILcdModelEncoder, ALcyFileTypeDescriptor)
public int getModelEncoderCount()
ILcyModelEncoderContainer
getModelEncoderCount
in interface ILcyModelEncoderContainer
public ILcdModelEncoder getModelEncoder(int aIndex)
ILcyModelEncoderContainer
getModelEncoder
in interface ILcyModelEncoderContainer
aIndex
- The index of the asked model encoder. Make sure 0 <= aIndex < getModelEncoderCount()public ALcyFileTypeDescriptor getEncoderFileTypeDescriptor(int aIndex)
ILcyModelEncoderContainer
getEncoderFileTypeDescriptor
in interface ILcyModelEncoderContainer
aIndex
- The index to retrieve the file type descriptor for.public String getDisplayName()
ILcdModelEncoder
ILcdModelEncoder
encodes to.getDisplayName
in interface ILcdModelEncoder
ILcdModelEncoder
.public boolean canSave(ILcdModel aModel)
ILcdModelEncoder
s to find a suitable
ILcdModelEncoder
. Suitable means that canSave returns true. This method returns
true if such a suitable ILcdModelEncoder
could be found, false otherwise.canSave
in interface ILcdModelEncoder
aModel
- The model to encode.ILcdModelEncoder
could be found, false otherwise.ILcdModelEncoder.save(com.luciad.model.ILcdModel)
public void save(ILcdModel aModel) throws IOException
ILcdModelEncoder
s to find a suitable
ILcdModelEncoder
. Suitable means that canSave returns true. It delegates the
saving to the first suitable ILcdModelEncoder
that was found.save
in interface ILcdModelEncoder
aModel
- The model to save.IOException
- if an I/O error occurs during encoding.public boolean canExport(ILcdModel aModel, String aDestinationName)
ILcdModelEncoder
s to find a suitable
ILcdModelEncoder
. Suitable means that canExport returns true. This method returns
true if such a suitable ILcdModelEncoder
could be found, false otherwise.canExport
in interface ILcdModelEncoder
aModel
- The model to export.aDestinationName
- The destination name to export to.ILcdModelEncoder
could be found, false otherwise.ILcdModelEncoder.export(com.luciad.model.ILcdModel, java.lang.String)
public void export(ILcdModel aModel, String aDestinationName) throws IOException
Loops over its associated list of ILcdModelEncoder
s to find a suitable
ILcdModelEncoder
. Suitable means that when canExport
is invoked, it returns true
.
It will first loop over all model encoders for which the associated ALcyFileTypeDescriptor
accepts
aDestinationName
. The export will be delegated to the first of those encoders for which the canExport
returns true
.
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.
export
in interface ILcdModelEncoder
aModel
- The model to export.aDestinationName
- The destination name to export to.IOException
- if an I/O error occurs during encoding.