public class TLcyCompositeDataSourceHandler extends ALcyDataSourceHandler
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.
TLcyDataSourceHandlerHolder
Constructor and Description |
---|
TLcyCompositeDataSourceHandler()
Default constructor.
|
TLcyCompositeDataSourceHandler(ILcyLucyEnv aLucyEnv)
Constructs a
TLcyCompositeDataSourceHandler working on the Lucy back-end. |
Modifier and Type | Method and Description |
---|---|
void |
addDataSourceHandler(ALcyDataSourceHandler aHandler,
ALcyFileTypeDescriptor aFileTypeDescriptor)
Adds the given
ALcyDataSourceHandler to the list of associated
ALcyDataSourceHandler s. |
boolean |
canHandleDataSource(String aSourceName,
Object aTarget)
Loops over its list of
ALcyDataSourceHandler s to find a suitable
ALcyDataSourceHandler . |
ALcyDataSourceHandler |
getDataSourceHandler(int aIndex)
Returns the
ALcyDataSourceHandler at the given index. |
int |
getDataSourceHandlerCount()
Returns the number of associated
ALcyDataSourceHandler s. |
String |
getDisplayName()
Returns the display name of this data source handler.
|
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.
|
void |
handleDataSource(String aSourceName,
Object aTarget)
Loops over its list of
ALcyDataSourceHandler s to find a suitable
ALcyDataSourceHandler . |
void |
removeDataSourceHandler(ALcyDataSourceHandler aHandler)
Removes the given
ALcyDataSourceHandler from the list of associated
ALcyDataSourceHandler s. |
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 registered ALcyDataSourceHandler
instances of the Lucy back-end, use TLcyCompositeDataSourceHandler(com.luciad.lucy.ILcyLucyEnv)
instead.
public TLcyCompositeDataSourceHandler(ILcyLucyEnv aLucyEnv)
Constructs a TLcyCompositeDataSourceHandler
working on the Lucy back-end.
It will use all ALcyDataSourceHandler
instances registered to the back-end, and
adding and/or removing ALcyDataSourceHandler
s to/from this
TLcyCompositeDataSourceHandler
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, use TLcyCompositeDataSourceHandler()
instead.
aLucyEnv
- The Lucy back-end.TLcyCompositeDataSourceHandler()
,
addDataSourceHandler(ALcyDataSourceHandler, ALcyFileTypeDescriptor)
,
removeDataSourceHandler(ALcyDataSourceHandler)
public void addDataSourceHandler(ALcyDataSourceHandler aHandler, ALcyFileTypeDescriptor aFileTypeDescriptor)
Adds the given ALcyDataSourceHandler
to the list of associated
ALcyDataSourceHandler
s.
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)
.
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.removeDataSourceHandler(com.luciad.lucy.model.ALcyDataSourceHandler)
public void removeDataSourceHandler(ALcyDataSourceHandler aHandler)
Removes the given ALcyDataSourceHandler
from the list of associated
ALcyDataSourceHandler
s. 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.
aHandler
- The ALcyDataSourceHandler
to remove.addDataSourceHandler(com.luciad.lucy.model.ALcyDataSourceHandler, com.luciad.lucy.model.ALcyFileTypeDescriptor)
public int getDataSourceHandlerCount()
ALcyDataSourceHandler
s.ALcyDataSourceHandler
s.public ALcyDataSourceHandler getDataSourceHandler(int aIndex)
ALcyDataSourceHandler
at the given index.aIndex
- The index to retrieve the ALcyDataSourceHandler
at. 0 <= aIndex < getURIHandlerCount
ALcyDataSourceHandler
at the given index.getDataSourceHandlerCount()
public ALcyFileTypeDescriptor getFileTypeDescriptor(int aIndex)
aIndex
- The index to retrieve the file type descriptor for.public String getDisplayName()
ALcyDataSourceHandler
getDisplayName
in class ALcyDataSourceHandler
public boolean canHandleDataSource(String aSourceName, Object aTarget)
ALcyDataSourceHandler
s to find a suitable
ALcyDataSourceHandler
. Suitable means that canHandleDataSource returns true.
This method returns true if such a suitable handler could be found.canHandleDataSource
in class ALcyDataSourceHandler
aSourceName
- The name of the source to handle.aTarget
- An optional target param.ALcyDataSourceHandler
could be found, false otherwise.public void handleDataSource(String aSourceName, Object aTarget) throws IOException
ALcyDataSourceHandler
s to find a suitable
ALcyDataSourceHandler
. Suitable means that canHandleDataSource returns true.
That suitable ALcyDataSourceHandler
is asked to handle the data source.handleDataSource
in class ALcyDataSourceHandler
aSourceName
- The name of the source to handle.aTarget
- An optional target param.IOException
- In case of IO failure.