public final class ContextInjectionFactory extends Object
If annotations are supported by the runtime, matching of methods and fields to be injected is also performed using the annotations defined in packages javax.inject and org.eclipse.e4.core.di.annotations.
The injection of values is generally done as a number of calls. User objects that want to finalize the injected data (for instance, to perform calculations based on multiple injected values) can place such calculations in a method with the javax.annotation.PostConstruct annotation.
When injecting values, all fields are injected prior to injection of methods. When values are removed from the context or the context is disposed, injection of null values occurs in the reverse order: methods and then fields. As a result, injection methods can safely make use of injected field values. The order in which methods are injected is undefined, so injection methods should not rely on other injection methods having been run already. Methods and field on superclasses are injected before methods in fields on the subclasses.
When a context is disposed, the injection factory will attempt to notify all injected objects by calling methods with the javax.annotation.PreDestroy annotation. This class is not intended to be extended by clients.
Modifier and Type | Method and Description |
---|---|
static void |
inject(Object object,
IEclipseContext context)
Injects a context into a domain object.
|
static Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
IEclipseContext context)
Call a method, injecting the parameters from the context.
|
static Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
IEclipseContext context,
IEclipseContext localContext,
Object defaultValue)
Call a method, injecting the parameters from two contexts.
|
static Object |
invoke(Object object,
Class<? extends Annotation> qualifier,
IEclipseContext context,
Object defaultValue)
Call a method, injecting the parameters from the context.
|
static <T> T |
make(Class<T> clazz,
IEclipseContext context)
Obtain an instance of the specified class and inject it with the context.
|
static <T> T |
make(Class<T> clazz,
IEclipseContext context,
IEclipseContext staticContext)
Obtain an instance of the specified class and inject it with the context.
|
static void |
setDefault(IEclipseContext context)
Specifies context used by the injector to create its internal objects.
|
static void |
uninject(Object object,
IEclipseContext context)
Un-injects the context from the object.
|
public static void inject(Object object, IEclipseContext context) throws InjectionException
object
- The object to perform injection oncontext
- The context to obtain injected values fromInjectionException
- if an exception occurred while performing this operationpublic static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context) throws InjectionException
If no matching method is found on the class, an InjectionException will be thrown.
object
- The object to perform injection onqualifier
- the annotation tagging method to be calledcontext
- The context to obtain injected values fromnull
InjectionException
- if an exception occurred while performing this operationpublic static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context, Object defaultValue) throws InjectionException
If no matching method is found on the class, the defaultValue will be returned.
object
- The object to perform injection onqualifier
- the annotation tagging method to be calledcontext
- The context to obtain injected values fromdefaultValue
- A value to be returned if the method cannot be called, might be null
null
InjectionException
- if an exception occurred while performing this operationpublic static Object invoke(Object object, Class<? extends Annotation> qualifier, IEclipseContext context, IEclipseContext localContext, Object defaultValue) throws InjectionException
If values for the same key present in both the context and the local context, the values from the local context are injected.
If no matching method is found on the class, the defaultValue will be returned.
object
- The object to perform injection onqualifier
- the annotation tagging method to be calledcontext
- The context to obtain injected values fromlocalContext
- The context to obtain addition injected values fromdefaultValue
- A value to be returned if the method cannot be called, might be null
null
InjectionException
- if an exception occurred while performing this operationpublic static void uninject(Object object, IEclipseContext context) throws InjectionException
object
- The domain object previously injected with the contextcontext
- The context previously injected into the objectInjectionException
- if an exception occurred while performing this operationpublic static <T> T make(Class<T> clazz, IEclipseContext context) throws InjectionException
Class'es scope dictates if a new instance of the class will be created, or existing instance will be reused.
clazz
- The class to be instantiatedcontext
- The context to obtain injected values fromInjectionException
- if an exception occurred while performing this operationScope
,
Singleton
public static <T> T make(Class<T> clazz, IEclipseContext context, IEclipseContext staticContext) throws InjectionException
If values for the same key present in both the context and the static context, the values from the static context are injected.
Class'es scope dictates if a new instance of the class will be created, or existing instance will be reused.
clazz
- The class to be instantiatedcontext
- The context to obtain injected values fromstaticContext
- The context containing extra values; not trackedInjectionException
- if an exception occurred while performing this operationmake(Class, IEclipseContext)
public static void setDefault(IEclipseContext context)
context
- the context to be used as a data source by the injector
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.