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
@version 1.2
@see IServiceInfo
@see IServiceFactory