|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Gateway
Interface for convenience classes that wrap a Context
to provide
one-line access to a suite of Service
s.
The get(java.lang.Class
methods provide consistent )Service
instantiation,
while throwing NoSuchServiceException
if the requested
Service
is not found.
Let's say we have a Kraken
service and a Cow
service. Using
the Context
directly, the code would look like:
Context context = new Context(); context.getService(Cow.class).feedToKraken(); context.getService(Kraken.class).burp();
To perform these actions, you have to know a priori to ask for a
Cow
and a Kraken
; i.e., your IDE's code completion will not
give you a hint. Further, if either service is unavailable, a
NullPointerException
is thrown.
But if we create a Gateway
class called Animals
with the
following signatures:
public Cow cow() { return get(Cow.class); } public Kraken kraken() { return get(Kraken.class); }
We can now access our services through the new Animals
gateway:
Animals animals = new Animals(); animals.cow().feedToKraken(); animals.kraken().burp();
This provides succinct yet explicit access to the Cow
and
Kraken
services; it is a simple two-layer access to functionality,
which an IDE can auto-complete. And if one of the services is not available,
a NoSuchServiceException
is thrown, which facilitates appropriate
(but optional) handling of missing services.
Gateways discoverable at runtime must implement this interface and be
annotated with @Gateway
with attribute Plugin.type()
=
Gateway
.class. While it possible to create a gateway merely by
implementing this interface, it is encouraged to instead extend
AbstractGateway
, for convenience.
Context
Method Summary | ||
---|---|---|
AppService |
app()
|
|
AppEventService |
appEvent()
|
|
CommandService |
command()
|
|
ConsoleService |
console()
|
|
DisplayService |
display()
|
|
EventService |
event()
|
|
EventHistory |
eventHistory()
|
|
|
get(Class<S> serviceClass)
Returns an implementation of the requested Service , if it exists in
the underlying Context . |
|
Service |
get(String serviceClassName)
Returns an implementation of the Service with the given class name,
if it exists in the underlying Context . |
|
App |
getApp()
|
|
String |
getInfo(boolean mem)
|
|
String |
getTitle()
|
|
String |
getVersion()
|
|
IconService |
icon()
|
|
IOService |
io()
|
|
LogService |
log()
|
|
MenuService |
menu()
|
|
ModuleService |
module()
|
|
ObjectService |
object()
|
|
OptionsService |
options()
|
|
PlatformService |
platform()
|
|
PluginService |
plugin()
|
|
RecentFileService |
recentFile()
|
|
ScriptService |
script()
|
|
StatusService |
status()
|
|
TextService |
text()
|
|
ThreadService |
thread()
|
|
ToolService |
tool()
|
|
WidgetService |
widget()
|
Methods inherited from interface org.scijava.Contextual |
---|
context, getContext, setContext |
Methods inherited from interface org.scijava.Prioritized |
---|
getPriority, setPriority |
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Methods inherited from interface org.scijava.plugin.HasPluginInfo |
---|
getInfo, setInfo |
Method Detail |
---|
<S extends Service> S get(Class<S> serviceClass)
Service
, if it exists in
the underlying Context
.
serviceClass
- the requested Service
NullContextException
- if the application context is not set.
NoSuchServiceException
- if there is no service of the given class.Service get(String serviceClassName)
Service
with the given class name,
if it exists in the underlying Context
.
serviceClassName
- name of the requested Service
Service
NullContextException
- if the application context is not set.
NoSuchServiceException
- if there is no service matching
serviceClassName
.AppEventService appEvent()
AppService app()
CommandService command()
ConsoleService console()
DisplayService display()
EventHistory eventHistory()
EventService event()
IconService icon()
IOService io()
LogService log()
MenuService menu()
ModuleService module()
ObjectService object()
OptionsService options()
PlatformService platform()
PluginService plugin()
RecentFileService recentFile()
ScriptService script()
StatusService status()
TextService text()
ThreadService thread()
ToolService tool()
WidgetService widget()
App getApp()
AppService
String getTitle()
App.getTitle()
String getVersion()
App.getVersion()
String getInfo(boolean mem)
App.getInfo(boolean)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |