org.scijava
Interface Gateway

All Superinterfaces:
Comparable<Prioritized>, Contextual, HasPluginInfo, Prioritized, RichPlugin, SciJavaPlugin
All Known Implementing Classes:
AbstractGateway, SciJava

public interface Gateway
extends RichPlugin

Interface for convenience classes that wrap a Context to provide one-line access to a suite of Services.

The get(java.lang.Class) methods provide consistent Service instantiation, while throwing NoSuchServiceException if the requested Service is not found.

Sample implementation

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.

Author:
Mark Hiner, Curtis Rueden
See Also:
Context

Method Summary
 AppService app()
           
 AppEventService appEvent()
           
 CommandService command()
           
 ConsoleService console()
           
 DisplayService display()
           
 EventService event()
           
 EventHistory eventHistory()
           
<S extends Service>
S
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

get

<S extends Service> S get(Class<S> serviceClass)
Returns an implementation of the requested Service, if it exists in the underlying Context.

Parameters:
serviceClass - the requested Service
Returns:
The singleton instance of the given class
Throws:
NullContextException - if the application context is not set.
NoSuchServiceException - if there is no service of the given class.

get

Service get(String serviceClassName)
Returns an implementation of the Service with the given class name, if it exists in the underlying Context.

Parameters:
serviceClassName - name of the requested Service
Returns:
The singleton instance of the requested Service
Throws:
NullContextException - if the application context is not set.
NoSuchServiceException - if there is no service matching serviceClassName.

appEvent

AppEventService appEvent()

app

AppService app()

command

CommandService command()

console

ConsoleService console()

display

DisplayService display()

eventHistory

EventHistory eventHistory()

event

EventService event()

icon

IconService icon()

io

IOService io()

log

LogService log()

menu

MenuService menu()

module

ModuleService module()

object

ObjectService object()

options

OptionsService options()

platform

PlatformService platform()

plugin

PluginService plugin()

recentFile

RecentFileService recentFile()

script

ScriptService script()

status

StatusService status()

text

TextService text()

thread

ThreadService thread()

tool

ToolService tool()

widget

WidgetService widget()

getApp

App getApp()
See Also:
AppService

getTitle

String getTitle()
See Also:
App.getTitle()

getVersion

String getVersion()
See Also:
App.getVersion()

getInfo

String getInfo(boolean mem)
See Also:
App.getInfo(boolean)


Copyright © 2009–2014 SciJava. All rights reserved.