public interface Gateway extends RichPlugin, Versioned
Context
to provide
one-line access to a suite of Service
s.
The get(java.lang.Class<S>)
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
Modifier and Type | Method and Description |
---|---|
AppService |
app() |
AppEventService |
appEvent() |
CommandService |
command() |
ConsoleService |
console() |
DisplayService |
display() |
EventService |
event() |
EventHistory |
eventHistory() |
<S extends Service> |
get(Class<S> serviceClass)
|
Service |
get(String serviceClassName)
|
App |
getApp() |
String |
getInfo(boolean mem) |
String |
getTitle() |
String |
getVersion()
Gets the version of the object.
|
IconService |
icon() |
InputService |
input() |
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() |
context, getContext, setContext
getPriority, setPriority
compareTo
getInfo, setInfo
<S extends Service> S get(Class<S> serviceClass)
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()
InputService input()
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 getInfo(boolean mem)
App.getInfo(boolean)
String getVersion()
Versioned
getVersion
in interface Versioned
App.getVersion()
Copyright © 2009–2015 SciJava. All rights reserved.