Class TLcyCompositeDataSourceHandler
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 Summary
ConstructorsConstructorDescriptionDefault constructor.TLcyCompositeDataSourceHandler(ILcyLucyEnv aLucyEnv) Constructs aTLcyCompositeDataSourceHandlerworking on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataSourceHandler(ALcyDataSourceHandler aHandler, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the givenALcyDataSourceHandlerto the list of associatedALcyDataSourceHandlers.booleancanHandleDataSource(String aSourceName, Object aTarget) Loops over its list ofALcyDataSourceHandlers to find a suitableALcyDataSourceHandler.getDataSourceHandler(int aIndex) Returns theALcyDataSourceHandlerat the given index.intReturns the number of associatedALcyDataSourceHandlers.Returns the display name of this data source handler.getFileTypeDescriptor(int aIndex) Retrieves the file type descriptor at the given index, or null if the handler was added with null as a descriptor.voidhandleDataSource(String aSourceName, Object aTarget) Loops over its list ofALcyDataSourceHandlers to find a suitableALcyDataSourceHandler.voidremoveDataSourceHandler(ALcyDataSourceHandler aHandler) Removes the givenALcyDataSourceHandlerfrom the list of associatedALcyDataSourceHandlers.
-
Constructor Details
-
TLcyCompositeDataSourceHandler
public TLcyCompositeDataSourceHandler()Default constructor. No
ALcyDataSourceHandlers are associated.The created instance will only work on the
ALcyDataSourceHandlerinstances registered to it. If you want to use all registeredALcyDataSourceHandlerinstances of the Lucy back-end, useTLcyCompositeDataSourceHandler(com.luciad.lucy.ILcyLucyEnv)instead.- See Also:
-
TLcyCompositeDataSourceHandler
Constructs a
TLcyCompositeDataSourceHandlerworking on the Lucy back-end.It will use all
ALcyDataSourceHandlerinstances registered to the back-end, and adding and/or removingALcyDataSourceHandlers to/from thisTLcyCompositeDataSourceHandlerwill respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeDataSourceHandlerwhich does not use the back-end, useTLcyCompositeDataSourceHandler()instead.- Parameters:
aLucyEnv- The Lucy back-end.- See Also:
-
-
Method Details
-
addDataSourceHandler
public void addDataSourceHandler(ALcyDataSourceHandler aHandler, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the given
ALcyDataSourceHandlerto the list of associatedALcyDataSourceHandlers.If the constructor specifying an
ILcyLucyEnvis used, theALcyFileTypeDescriptorand its associatedALcyDataSourceHandlerwill be registered on the Lucy back-end (seeILcyLucyEnv.addService(Object, int)by using anTLcyDataSourceHandlerHolder. When callingILcyLucyEnv.getServices(Class)afterwards, the holder objects will only be returned when the requested class wasTLcyDataSourceHandlerHolder.class
Note: if you want to remove the registeredALcyFileTypeDescriptorand its associatedALcyDataSourceHandler, useremoveDataSourceHandler(ALcyDataSourceHandler)and notILcyLucyEnv.removeService(Object).- Parameters:
aHandler- TheALcyDataSourceHandlerto 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
Removes the given
ALcyDataSourceHandlerfrom the list of associatedALcyDataSourceHandlers. Has no effect if the givenALcyDataSourceHandlerwas never added. The correspondingALcyFileTypeDescriptoris also removed.If the constructor specifying an
ILcyLucyEnvis used, theTLcyDataSourceHandlerHolderobject containing theALcyDataSourceHandleraHandlerwill be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)).
Note: it is only possible to removeTLcyDataSourceHandlerHolderinstances which were registered using theaddDataSourceHandler(ALcyDataSourceHandler, ALcyFileTypeDescriptor)method.- Parameters:
aHandler- TheALcyDataSourceHandlerto remove.- See Also:
-
getDataSourceHandlerCount
public int getDataSourceHandlerCount()Returns the number of associatedALcyDataSourceHandlers.- Returns:
- the number of associated
ALcyDataSourceHandlers.
-
getDataSourceHandler
Returns theALcyDataSourceHandlerat the given index.- Parameters:
aIndex- The index to retrieve theALcyDataSourceHandlerat.0 <= aIndex < getURIHandlerCount- Returns:
- the
ALcyDataSourceHandlerat the given index. - See Also:
-
getFileTypeDescriptor
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
Description copied from class:ALcyDataSourceHandlerReturns 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:
getDisplayNamein classALcyDataSourceHandler- Returns:
- The display name.
-
canHandleDataSource
Loops over its list ofALcyDataSourceHandlers to find a suitableALcyDataSourceHandler. Suitable means that canHandleDataSource returns true. This method returns true if such a suitable handler could be found.- Specified by:
canHandleDataSourcein classALcyDataSourceHandler- Parameters:
aSourceName- The name of the source to handle.aTarget- An optional target param.- Returns:
- True if a suitable
ALcyDataSourceHandlercould be found, false otherwise.
-
handleDataSource
Loops over its list ofALcyDataSourceHandlers to find a suitableALcyDataSourceHandler. Suitable means that canHandleDataSource returns true. That suitableALcyDataSourceHandleris asked to handle the data source.- Specified by:
handleDataSourcein classALcyDataSourceHandler- Parameters:
aSourceName- The name of the source to handle.aTarget- An optional target param.- Throws:
IOException- In case of IO failure.
-