Class TLcyCompositeDataSourceHandler
Composite implementation (see composite design pattern) of ALcyDataSourceHandler
.
It keeps a list of associated ALcyDataSourceHandler
s. When it is asked to handle a
data source, it loops over its associated ALcyDataSourceHandler
s 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 ALcyDataSourceHandler
s 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
ConstructorDescriptionDefault constructor.TLcyCompositeDataSourceHandler
(ILcyLucyEnv aLucyEnv) Constructs aTLcyCompositeDataSourceHandler
working on the Lucy back-end. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataSourceHandler
(ALcyDataSourceHandler aHandler, ALcyFileTypeDescriptor aFileTypeDescriptor) Adds the givenALcyDataSourceHandler
to the list of associatedALcyDataSourceHandler
s.boolean
canHandleDataSource
(String aSourceName, Object aTarget) Loops over its list ofALcyDataSourceHandler
s to find a suitableALcyDataSourceHandler
.getDataSourceHandler
(int aIndex) Returns theALcyDataSourceHandler
at the given index.int
Returns the number of associatedALcyDataSourceHandler
s.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.void
handleDataSource
(String aSourceName, Object aTarget) Loops over its list ofALcyDataSourceHandler
s to find a suitableALcyDataSourceHandler
.void
removeDataSourceHandler
(ALcyDataSourceHandler aHandler) Removes the givenALcyDataSourceHandler
from the list of associatedALcyDataSourceHandler
s.
-
Constructor Details
-
TLcyCompositeDataSourceHandler
public TLcyCompositeDataSourceHandler()Default constructor. No
ALcyDataSourceHandler
s are associated.The created instance will only work on the
ALcyDataSourceHandler
instances registered to it. If you want to use all registeredALcyDataSourceHandler
instances of the Lucy back-end, useTLcyCompositeDataSourceHandler(com.luciad.lucy.ILcyLucyEnv)
instead.- See Also:
-
TLcyCompositeDataSourceHandler
Constructs a
TLcyCompositeDataSourceHandler
working on the Lucy back-end.It will use all
ALcyDataSourceHandler
instances registered to the back-end, and adding and/or removingALcyDataSourceHandler
s to/from thisTLcyCompositeDataSourceHandler
will respectively add/remove it as service from the back-end.If you want to create a
TLcyCompositeDataSourceHandler
which 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
ALcyDataSourceHandler
to the list of associatedALcyDataSourceHandler
s.If the constructor specifying an
ILcyLucyEnv
is used, theALcyFileTypeDescriptor
and its associatedALcyDataSourceHandler
will 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 registeredALcyFileTypeDescriptor
and its associatedALcyDataSourceHandler
, useremoveDataSourceHandler(ALcyDataSourceHandler)
and notILcyLucyEnv.removeService(Object)
.- Parameters:
aHandler
- TheALcyDataSourceHandler
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
Removes the given
ALcyDataSourceHandler
from the list of associatedALcyDataSourceHandler
s. Has no effect if the givenALcyDataSourceHandler
was never added. The correspondingALcyFileTypeDescriptor
is also removed.If the constructor specifying an
ILcyLucyEnv
is used, theTLcyDataSourceHandlerHolder
object containing theALcyDataSourceHandler
aHandler
will be removed as service from the Lucy back-end (seeILcyLucyEnv.removeService(Object)
).
Note: it is only possible to removeTLcyDataSourceHandlerHolder
instances which were registered using theaddDataSourceHandler(ALcyDataSourceHandler, ALcyFileTypeDescriptor)
method.- Parameters:
aHandler
- TheALcyDataSourceHandler
to remove.- See Also:
-
getDataSourceHandlerCount
public int getDataSourceHandlerCount()Returns the number of associatedALcyDataSourceHandler
s.- Returns:
- the number of associated
ALcyDataSourceHandler
s.
-
getDataSourceHandler
Returns theALcyDataSourceHandler
at the given index.- Parameters:
aIndex
- The index to retrieve theALcyDataSourceHandler
at.0 <= aIndex < getURIHandlerCount
- Returns:
- the
ALcyDataSourceHandler
at 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: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 classALcyDataSourceHandler
- Returns:
- The display name.
-
canHandleDataSource
Loops over its list ofALcyDataSourceHandler
s to find a suitableALcyDataSourceHandler
. Suitable means that canHandleDataSource returns true. This method returns true if such a suitable handler could be found.- Specified by:
canHandleDataSource
in classALcyDataSourceHandler
- 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
Loops over its list ofALcyDataSourceHandler
s to find a suitableALcyDataSourceHandler
. Suitable means that canHandleDataSource returns true. That suitableALcyDataSourceHandler
is asked to handle the data source.- Specified by:
handleDataSource
in classALcyDataSourceHandler
- Parameters:
aSourceName
- The name of the source to handle.aTarget
- An optional target param.- Throws:
IOException
- In case of IO failure.
-