| java.lang.Object net.refractions.udig.catalog.IService
All known Subclasses: net.refractions.udig.catalog.rasterings.AbstractRasterService, net.refractions.udig.catalog.internal.oracle.OracleServiceImpl, net.refractions.udig.catalog.internal.db2.DB2Service, net.refractions.udig.catalog.hsql.internal.HsqlServiceImpl, net.refractions.udig.catalog.memory.internal.MemoryServiceImpl, net.refractions.udig.mapgraphic.internal.MapGraphicService, net.refractions.udig.catalog.internal.shp.ShpServiceImpl, net.refractions.udig.catalog.internal.wfs.WFSServiceImpl, net.refractions.udig.catalog.internal.postgis.PostGISServiceImpl, net.refractions.udig.catalog.internal.gml.GMLServiceImpl, net.refractions.udig.catalog.internal.arcsde.ArcServiceImpl, net.refractions.udig.catalog.internal.wms.WMSServiceImpl,
IService | abstract public class IService implements IResolve(Code) | | Represents a geo spatial service handle. Follows the same design as IResource.
Represents a spatial service, which may be lazily loaded. The existance of this object does not
ensure that the advertized data is guaranteed to exist, nor does this interface guarantee that
the service exists based on this object's existance. We should also note the resource management
is left to the user, and that resolve() is not guaranteed to return the same instance object from
two subsequent calls, but may. This is merely a handle to some information about a service, and a
method of aquiring an instance of the service ...
NOTE: This may be the result of communications with a metadata service, and as such this service
described may not be running right now. Remember to check the service status.
Implementing an IService
Implement the abstract methods and you are good to go.
Extending an IService
You may want to implement your own IService in order to provide a handle for a new kind of API.
- New method:
public API getAPI( ProgressMonitor monitor){
if (monitor == null) monitor = new NullProgressMonitor();
monitor.beingTask("Connect to API",2);
try {
String server = getConnectionParams().get("server");
monitor.worked(1);
return new API( s );
}
finally {
monitor.done();
}
}
(note the use of NullProgressMonitor)
- Optional: Customize resolve method to advertise your new API "dynamically"
public <T> boolean canResolve( Class<T> adaptee ) {
return adaptee != null
&& (adaptee.isAssignableFrom(API.class) || super.canResolve(adaptee));
}
public <T> T resolve( Class<T> adaptee, IProgressMonitor monitor ) throws IOException {
if (monitor == null) monitor = new NullProgressMonitor();
if (adaptee == null)
throw new NullPointerException("No adaptor specified" );
if (adaptee.isAssignableFrom(API.class)) {
return adaptee.cast(getAPI(monitor));
}
return super.resolve(adaptee, monitor);
}
(note the call to super)
- Optional: cache your API as the "connection"
API api = null;
Throwable msg = null;
public synchronized API getAPI( ProgressMonitor monitor){
if( api != null ) return api;
if (monitor == null) monitor = new NullProgressMonitor();
monitor.beingTask("Connect to API",2);
try {
String server = getConnectionParams().get("server");
monitor.worked(1);
api = new API( s );
monitor.worked(1);
return api;
}
finally {
monitor.done();
}
}
public Status getStatus() {
return msg != null? Status.BROKEN : api == null? Status.NOTCONNECTED : Status.CONNECTED;
}
public Throwable getMessage(){
return msg;
}
public synchronized void dispose( ProgressMonitor monitor ){
if( api != null ){
api.dispose();
api = null;
}
if( msg != null ) msg = null;
}
(Note the use of getMessage and getStatus)
author: David Zwiers, Refractions Research since: 0.6 See Also: IServiceInfo See Also: IServiceFactory |
Method Summary | |
public boolean | canResolve(Class<T> adaptee) Harded coded to capture the IService contract. | public void | dispose(IProgressMonitor monitor) | final public boolean | equals(Object arg0) | abstract public Map<String, Serializable> | getConnectionParams() Accessor to the set of params used to create this entry. | abstract public IServiceInfo | getInfo(IProgressMonitor monitor) | final public int | hashCode() | abstract public List<? extends IGeoResource> | members(IProgressMonitor monitor) Return list of IGeoResources managed by this service. | public ICatalog | parent(IProgressMonitor monitor) Returns LocalCatalog by defaul, subclass must override iff a custom catalog is used. | public T | resolve(Class<T> adaptee, IProgressMonitor monitor) Will attempt to morph into the adaptee, and return that object. | public String | toString() Indicate class and id. |
canResolve | public boolean canResolve(Class<T> adaptee)(Code) | | Harded coded to capture the IService contract.
That is we *must* resolve the following:
- IService: this
- IServiceInfo.class: getInfo
- List.class: members
- ICatalog.class: parent
Here is an implementation example (for something that can adapt to DataStore):
public <T> boolean canResolve( Class<T> adaptee ) {
return adaptee != null
&& (adaptee.isAssignableFrom(DataStore.class) || super.canResolve(adaptee));
}
|
dispose | public void dispose(IProgressMonitor monitor)(Code) | | |
getConnectionParams | abstract public Map<String, Serializable> getConnectionParams()(Code) | | Accessor to the set of params used to create this entry. There is no guarantee that these
params created a usable service (@see getStatus() ). These params may have been modified
within the factory during creation. This method is intended to be used for cloning (@see
IServiceFactory) or for persistence between sessions.
IMPORTANT: Because of the serialization currently used only types that can be reconstructed from their toString() representation
can be used. For example:
valueThatIsSaved=url.toString().
URL restoredValue=new URL(valueThatIsSaved);
Also only classes that this plugin can load can be loaded so custom classes from downstream plugins cannot be used.
It is recommended that only "normal" types be used like Integer, URL, Float, etc...
This restriction will be lifted in the future. (Except for the loading issue that is a design issue that we will live with.)
See Also: IServiceFactory |
members | abstract public List<? extends IGeoResource> members(IProgressMonitor monitor) throws IOException(Code) | | Return list of IGeoResources managed by this service.
Many file based serivces will just contain a single IGeoResource.
|
parent | public ICatalog parent(IProgressMonitor monitor)(Code) | | Returns LocalCatalog by defaul, subclass must override iff a custom catalog is used.
|
resolve | public T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOException(Code) | | Will attempt to morph into the adaptee, and return that object. Harded coded to capture the
IService contract.
That is we *must* resolve the following:
- IService: this
- IServiceInfo.class: getInfo
- ICatalog.class: parent
Recomended adaptations:
- ImageDescriptor.class: for a custom icon
- List.class: members
May Block.
Example implementation:
public <T> T resolve( Class<T> adaptee, IProgressMonitor monitor ) throws IOException {
if (monitor == null) monitor = new NullProgressMonitor();
if (adaptee == null)
throw new NullPointerException("No adaptor specified" );
if (adaptee.isAssignableFrom(API.class)) {
return adaptee.cast(getAPI(monitor));
}
return super.resolve(adaptee, monitor);
}
Parameters: adaptee - Parameters: monitor - instance of adaptee, or null if unavailable (IServiceInfo and Listmust be supported) See Also: IServiceInfo See Also: IGeoResource See Also: IResolve.resolve(ClassIProgressMonitor) |
toString | public String toString()(Code) | | Indicate class and id.
string representing this IResolve |
|
|