Class TLcyCompositeModelEncoder

All Implemented Interfaces:
ILcyModelEncoderContainer, ILcdModelEncoder, Serializable, Iterable<TLcyModelEncoderHolder>

public class TLcyCompositeModelEncoder extends TLcyGenericComposite<TLcyModelEncoderHolder> implements ILcdModelEncoder, ILcyModelEncoderContainer

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:
  • Constructor Details

  • 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, 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).

      Specified by:
      addModelEncoder in interface ILcyModelEncoderContainer
      Parameters:
      aModelEncoder - The model encoder to add
      aFileTypeDescriptor - 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

      public void removeModelEncoder(ILcdModelEncoder aModelEncoder)
      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, 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.

      Specified by:
      removeModelEncoder in interface ILcyModelEncoderContainer
      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 interface ILcyModelEncoderContainer
      Returns:
      the number of model encoders currently in this container.
    • getModelEncoder

      public ILcdModelEncoder getModelEncoder(int aIndex)
      Description copied from interface: ILcyModelEncoderContainer
      Returns the model encoder at the given index.
      Specified by:
      getModelEncoder in interface ILcyModelEncoderContainer
      Parameters:
      aIndex - The index of the asked model encoder. Make sure 0 <= aIndex < getModelEncoderCount()
      Returns:
      The model encoder at the given index.
    • getEncoderFileTypeDescriptor

      public ALcyFileTypeDescriptor getEncoderFileTypeDescriptor(int aIndex)
      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 interface ILcyModelEncoderContainer
      Parameters:
      aIndex - The index to retrieve the file type descriptor for.
      Returns:
      the file type descriptor at the given index.
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdModelEncoder
      Returns a short, displayable name for the format this ILcdModelEncoder encodes to.
      Specified by:
      getDisplayName in interface ILcdModelEncoder
      Returns:
      the displayable name of this ILcdModelEncoder.
    • canSave

      public boolean canSave(ILcdModel aModel)
      Loops over its associated list of ILcdModelEncoders 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.
      Specified by:
      canSave in interface ILcdModelEncoder
      Parameters:
      aModel - The model to encode.
      Returns:
      true if such a suitable ILcdModelEncoder could be found, false otherwise.
      See Also:
    • save

      public void save(ILcdModel aModel) throws IOException
      Loops over its associated list of ILcdModelEncoders to find a suitable ILcdModelEncoder. Suitable means that canSave returns true. It delegates the saving to the first suitable ILcdModelEncoder that was found.
      Specified by:
      save in interface ILcdModelEncoder
      Parameters:
      aModel - The model to save.
      Throws:
      IOException - if an I/O error occurs during encoding.
    • canExport

      public boolean canExport(ILcdModel aModel, String aDestinationName)
      Loops over its associated list of ILcdModelEncoders 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.
      Specified by:
      canExport in interface ILcdModelEncoder
      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

      public void export(ILcdModel aModel, String aDestinationName) throws IOException

      Loops over its associated list of ILcdModelEncoders 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.

      Specified by:
      export in interface ILcdModelEncoder
      Parameters:
      aModel - The model to export.
      aDestinationName - The destination name to export to.
      Throws:
      IOException - if an I/O error occurs during encoding.