Package org.eclipse.e4.core.contexts
Interface IContextFunction
-
- All Known Implementing Classes:
ContextFunction
public interface IContextFunction
A context function encapsulates evaluation of some code within anIEclipseContext
. The result of the function must be derived purely from the provided arguments and context objects, and must be free from side-effects other than the function's return value. In particular, the function must be idempotent - subsequent invocations of the same function with the same inputs must produce the same result.A common use for context functions is as a place holder for an object that has not yet been created. These place holders can be stored as values in an
IEclipseContext
, allowing the concrete value they represent to be computed lazily only when requested.Context functions can optionally be registered as OSGi services. Context implementations may use such registered services to seed context instances with initial values. Registering your context function as a service is a signal that contexts are free to add an instance of your function to their context automatically, using the key specified by the
SERVICE_CONTEXT_KEY
service property.- Since:
- 1.3
- See Also:
IEclipseContext.set(String, Object)
- Restriction:
- This interface is not intended to be implemented by clients.
Function implementations must subclass
ContextFunction
instead.
-
-
Field Summary
Fields Modifier and Type Field Description static String
SERVICE_CONTEXT_KEY
An OSGi service property used to indicate the context key this function should be registered in.static String
SERVICE_NAME
The OSGi service name for a context function service.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Object
compute(IEclipseContext context, String contextKey)
Evaluates the function based on the provided arguments and context to produce a consistent result.static IEclipseContext
getRootContext(IEclipseContext context)
Recursively looks up the rootIEclipseContext
in the context hierarchy.
-
-
-
Field Detail
-
SERVICE_NAME
static final String SERVICE_NAME
The OSGi service name for a context function service. This name can be used to obtain instances of the service.
-
SERVICE_CONTEXT_KEY
static final String SERVICE_CONTEXT_KEY
An OSGi service property used to indicate the context key this function should be registered in.
-
-
Method Detail
-
compute
Object compute(IEclipseContext context, String contextKey)
Evaluates the function based on the provided arguments and context to produce a consistent result.- Parameters:
context
- The context in which to perform the value computation.contextKey
- The context key used to find this function; may benull
such as if invoked directly.- Returns:
- The concrete value. Implementations may return
IInjector.NOT_A_VALUE
to cause lookup to continue up the context hierarchy.
-
getRootContext
static IEclipseContext getRootContext(IEclipseContext context)
Recursively looks up the rootIEclipseContext
in the context hierarchy.- Parameters:
context
-IEclipseContext
to get the parentIEclipseContext
from- Returns:
- the root
IEclipseContext
in the context hierarchy - Since:
- 1.8
-
-