|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.refractions.udig.catalog.IService
public abstract class IService
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.
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)
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)
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)
IServiceInfo
,
IServiceFactory
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface net.refractions.udig.catalog.IResolve |
---|
IResolve.Status |
Constructor Summary | |
---|---|
IService()
|
Method Summary | ||
---|---|---|
|
canResolve(java.lang.Class<T> adaptee)
Harded coded to capture the IService contract. |
|
void |
dispose(IProgressMonitor monitor)
Clean up after aquired resources - the handle will not function after being disposed. |
|
boolean |
equals(java.lang.Object arg0)
This should represent the identifier |
|
abstract java.util.Map<java.lang.String,java.io.Serializable> |
getConnectionParams()
Accessor to the set of params used to create this entry. |
|
abstract IServiceInfo |
getInfo(IProgressMonitor monitor)
|
|
int |
hashCode()
This should represent the identified |
|
abstract java.util.List<? extends IGeoResource> |
members(IProgressMonitor monitor)
Return list of IGeoResources managed by this service. |
|
ICatalog |
parent(IProgressMonitor monitor)
Returns LocalCatalog by defaul, subclass must override iff a custom catalog is used. |
|
|
resolve(java.lang.Class<T> adaptee,
IProgressMonitor monitor)
Will attempt to morph into the adaptee, and return that object. |
|
java.lang.String |
toString()
Indicate class and id. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.refractions.udig.catalog.IResolve |
---|
getIdentifier, getMessage, getStatus |
Constructor Detail |
---|
public IService()
Method Detail |
---|
public <T> T resolve(java.lang.Class<T> adaptee, IProgressMonitor monitor) throws java.io.IOException
That is we *must* resolve the following:
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);
}
resolve
in interface IResolve
adaptee
- monitor
-
java.io.IOException
- if result was unavailable due to a technical problemIServiceInfo
,
IGeoResource
,
IResolve.resolve(Class, IProgressMonitor)
public <T> boolean canResolve(java.lang.Class<T> adaptee)
That is we *must* resolve the following:
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));
}
canResolve
in interface IResolve
IResolve.resolve(Class, IProgressMonitor);
public ICatalog parent(IProgressMonitor monitor)
parent
in interface IResolve
monitor
- used to provide feedback during parent lookup
public abstract java.util.List<? extends IGeoResource> members(IProgressMonitor monitor) throws java.io.IOException
Many file based serivces will just contain a single IGeoResource.
members
in interface IResolve
monitor
- Monitor used to provide feedback during member lookup
java.io.IOException
- in the event of a technical problempublic abstract IServiceInfo getInfo(IProgressMonitor monitor) throws java.io.IOException
java.io.IOException
resolve(Class, IProgressMonitor)
public abstract java.util.Map<java.lang.String,java.io.Serializable> getConnectionParams()
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.)
IServiceFactory
public final boolean equals(java.lang.Object arg0)
equals
in class java.lang.Object
arg0
-
Object.equals(java.lang.Object)
public final int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
public void dispose(IProgressMonitor monitor)
IResolve
dispose
in interface IResolve
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |