Class TLcyCompositeDataSourceHandler

java.lang.Object
com.luciad.lucy.model.ALcyDataSourceHandler
com.luciad.lucy.model.TLcyCompositeDataSourceHandler

public class TLcyCompositeDataSourceHandler extends ALcyDataSourceHandler

Composite implementation (see composite design pattern) of ALcyDataSourceHandler. It keeps a list of associated ALcyDataSourceHandlers. When it is asked to handle a data source, it loops over its associated ALcyDataSourceHandlers to find a suitable ALcyDataSourceHandler. That ALcyDataSourceHandler is asked to handle the data source.

When creating a new TLcyCompositeDataSourceHandler using the constructor specifying an ILcyLucyEnv instance (see TLcyCompositeDataSourceHandler(com.luciad.lucy.ILcyLucyEnv), the created instance will work on the Lucy back-end services. It will use all registered ALcyDataSourceHandler instances of the Lucy back-end, adding and/or removing an ALcyDataSourceHandler will add/remove the ALcyDataSourceHandler as service from Lucy, ... .

Handling a data source 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
 TLcyCompositeDataSourceHandler handler = new TLcyCompositeDataSourceHandler( aLucyEnv );
 if ( handler.canHandleDataSource( aSourceName, aTarget ){
   try{
      handler.handleDataSource( aSourceName, aTarget );
    } catch ( IOException aException ){
      //IOException occurred during handling data source
    }
 }
 //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
 handler = null;
 

Note: the ALcyDataSourceHandlers are not directly registered as service to Lucy, but wrapped with a holder object. This holder objects allows to register the ALcyDataSourceHandler with some extra information like e.g. an ALcyFileTypeDescriptor. Using a back-end based TLcyCompositeDataSourceHandler will only use the registered TLcyDataSourceHandlerHolder objects, and not for example an ALcyDataSourceHandler which was directly (=not wrapped) registered as a service.

See Also:
  • Constructor Details

  • Method Details

    • addDataSourceHandler

      public void addDataSourceHandler(ALcyDataSourceHandler aHandler, ALcyFileTypeDescriptor aFileTypeDescriptor)

      Adds the given ALcyDataSourceHandler to the list of associated ALcyDataSourceHandlers.

      If the constructor specifying an ILcyLucyEnv is used, the ALcyFileTypeDescriptor and its associated ALcyDataSourceHandler will be registered on the Lucy back-end (see ILcyLucyEnv.addService(Object, int) by using an TLcyDataSourceHandlerHolder. When calling ILcyLucyEnv.getServices(Class) afterwards, the holder objects will only be returned when the requested class was TLcyDataSourceHandlerHolder.class
      Note: if you want to remove the registered ALcyFileTypeDescriptor and its associated ALcyDataSourceHandler, use removeDataSourceHandler(ALcyDataSourceHandler) and not ILcyLucyEnv.removeService(Object).

      Parameters:
      aHandler - The ALcyDataSourceHandler to add.
      aFileTypeDescriptor - The file type descriptor that provides more information on the file types this data source handler can handle, or null if this handler does not work with files.
      See Also:
    • removeDataSourceHandler

      public void removeDataSourceHandler(ALcyDataSourceHandler aHandler)

      Removes the given ALcyDataSourceHandler from the list of associated ALcyDataSourceHandlers. Has no effect if the given ALcyDataSourceHandler was never added. The corresponding ALcyFileTypeDescriptor is also removed.

      If the constructor specifying an ILcyLucyEnv is used, the TLcyDataSourceHandlerHolder object containing the ALcyDataSourceHandler aHandler will be removed as service from the Lucy back-end (see ILcyLucyEnv.removeService(Object)).
      Note: it is only possible to remove TLcyDataSourceHandlerHolder instances which were registered using the addDataSourceHandler(ALcyDataSourceHandler, ALcyFileTypeDescriptor) method.

      Parameters:
      aHandler - The ALcyDataSourceHandler to remove.
      See Also:
    • getDataSourceHandlerCount

      public int getDataSourceHandlerCount()
      Returns the number of associated ALcyDataSourceHandlers.
      Returns:
      the number of associated ALcyDataSourceHandlers.
    • getDataSourceHandler

      public ALcyDataSourceHandler getDataSourceHandler(int aIndex)
      Returns the ALcyDataSourceHandler at the given index.
      Parameters:
      aIndex - The index to retrieve the ALcyDataSourceHandler at. 0 <= aIndex < getURIHandlerCount
      Returns:
      the ALcyDataSourceHandler at the given index.
      See Also:
    • getFileTypeDescriptor

      public ALcyFileTypeDescriptor getFileTypeDescriptor(int aIndex)
      Retrieves the file type descriptor at the given index, or null if the handler was added with null as a descriptor.
      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 class: ALcyDataSourceHandler
      Returns the display name of this data source handler. This message will be displayed to a user, f.i. in a combo box if more than one handler can be used.
      Specified by:
      getDisplayName in class ALcyDataSourceHandler
      Returns:
      The display name.
    • canHandleDataSource

      public boolean canHandleDataSource(String aSourceName, Object aTarget)
      Loops over its list of ALcyDataSourceHandlers to find a suitable ALcyDataSourceHandler. Suitable means that canHandleDataSource returns true.

      This method returns true if such a suitable handler could be found.

      Specified by:
      canHandleDataSource in class ALcyDataSourceHandler
      Parameters:
      aSourceName - The name of the source to handle.
      aTarget - An optional target param.
      Returns:
      True if a suitable ALcyDataSourceHandler could be found, false otherwise.
    • handleDataSource

      public void handleDataSource(String aSourceName, Object aTarget) throws IOException
      Loops over its list of ALcyDataSourceHandlers to find a suitable ALcyDataSourceHandler. Suitable means that canHandleDataSource returns true.

      That suitable ALcyDataSourceHandler is asked to handle the data source.

      Specified by:
      handleDataSource in class ALcyDataSourceHandler
      Parameters:
      aSourceName - The name of the source to handle.
      aTarget - An optional target param.
      Throws:
      IOException - In case of IO failure.