Class TLcyCompositeModelEncoder
- All Implemented Interfaces:
ILcyModelEncoderContainer,ILcdModelEncoder,Serializable,Iterable<TLcyModelEncoderHolder>
Composite implementation (see composite design pattern) of ILcdModelEncoder. It
keeps a list of associated ILcdModelEncoders. When it is asked to encode a model, it
loops over its associated ILcdModelEncoders 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 ILcdModelEncoders 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
ConstructorsConstructorDescriptionDefault constructor.TLcyCompositeModelEncoder(ILcyLucyEnv aLucyEnv) Construct aTLcyCompositeModelEncoderworking on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModelEncoder(ILcdModelEncoder aModelEncoder, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given model encoder to this container.booleanLoops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder.booleanLoops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder.voidLoops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder.Returns a short, displayable name for the format thisILcdModelEncoderencodes 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.intReturns the number of model encoders currently in this container.voidremoveModelEncoder(ILcdModelEncoder aModelEncoder) Removes the given model encoder from this container.voidLoops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder.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 java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TLcyCompositeModelEncoder
public TLcyCompositeModelEncoder()Default constructor. No
ILcdModelEncoders are associated.The created instance will only work on the
ILcdModelEncoderinstances registered to it. If you want to use all registeredILcdModelEncoderinstances of the Lucy back-end, useTLcyCompositeModelEncoder(com.luciad.lucy.ILcyLucyEnv)instead.- See Also:
-
TLcyCompositeModelEncoder
Construct a
TLcyCompositeModelEncoderworking on the Lucy back-end.It will use all
ILcdModelEncoderinstances registered to the back-end, and adding and/or removingILcdModelEncoders to/from thisTLcyCompositeModelEncoderwill respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeModelEncoderwhich 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
ILcyLucyEnvis used, theALcyFileTypeDescriptorand its associatedILcdModelEncoderwill 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 registeredALcyFileTypeDescriptorand its associatedILcdModelEncoder, useremoveModelEncoder(com.luciad.model.ILcdModelEncoder)and notILcyLucyEnv.removeService(Object).- Specified by:
addModelEncoderin 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
ILcyLucyEnvis used, theTLcyModelEncoderHolderobject containing theILcdModelEncoderaModelEncoderwill be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)).
Note: it is only possible to removeTLcyModelEncoderHolderinstances which were registered using theaddModelEncoder(com.luciad.model.ILcdModelEncoder, ALcyFileTypeDescriptor)method.- Specified by:
removeModelEncoderin interfaceILcyModelEncoderContainer- Parameters:
aModelEncoder- The model encoder to remove.- See Also:
-
getModelEncoderCount
public int getModelEncoderCount()Description copied from interface:ILcyModelEncoderContainerReturns the number of model encoders currently in this container.- Specified by:
getModelEncoderCountin interfaceILcyModelEncoderContainer- Returns:
- the number of model encoders currently in this container.
-
getModelEncoder
Description copied from interface:ILcyModelEncoderContainerReturns the model encoder at the given index.- Specified by:
getModelEncoderin 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:ILcyModelEncoderContainerRetursn the file type descriptor at the given index, or null if the encoder was added with null as a descriptor.- Specified by:
getEncoderFileTypeDescriptorin 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:ILcdModelEncoderReturns a short, displayable name for the format thisILcdModelEncoderencodes to.- Specified by:
getDisplayNamein interfaceILcdModelEncoder- Returns:
- the displayable name of this
ILcdModelEncoder.
-
canSave
Loops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder. Suitable means that canSave returns true. This method returns true if such a suitableILcdModelEncodercould be found, false otherwise.- Specified by:
canSavein interfaceILcdModelEncoder- Parameters:
aModel- The model to encode.- Returns:
- true if such a suitable
ILcdModelEncodercould be found, false otherwise. - See Also:
-
save
Loops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder. Suitable means that canSave returns true. It delegates the saving to the first suitableILcdModelEncoderthat was found.- Specified by:
savein interfaceILcdModelEncoder- Parameters:
aModel- The model to save.- Throws:
IOException- if an I/O error occurs during encoding.
-
canExport
Loops over its associated list ofILcdModelEncoders to find a suitableILcdModelEncoder. Suitable means that canExport returns true. This method returns true if such a suitableILcdModelEncodercould be found, false otherwise.- Specified by:
canExportin interfaceILcdModelEncoder- Parameters:
aModel- The model to export.aDestinationName- The destination name to export to.- Returns:
- True if such a suitable
ILcdModelEncodercould be found, false otherwise. - See Also:
-
export
Loops over its associated list of
ILcdModelEncoders to find a suitableILcdModelEncoder. Suitable means that whencanExportis invoked, it returnstrue.It will first loop over all model encoders for which the associated
ALcyFileTypeDescriptoracceptsaDestinationName. The export will be delegated to the first of those encoders for which thecanExportreturnstrue.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:
exportin interfaceILcdModelEncoder- Parameters:
aModel- The model to export.aDestinationName- The destination name to export to.- Throws:
IOException- if an I/O error occurs during encoding.
-