Interface InjectionManager
- All Known Implementing Classes:
InjectionManagerImpl
@Contract
public interface InjectionManager
InjectionManager provides runtime resource injection(@Resource, @EJB, etc.)
and generic callback(PostConstruct/PreDestroy) services.
It performs the actual injection into the fields and methods of designated JEE component instances and managed class instances. The decision as to when injection takes place is determined by the caller.
- Author:
- Kenneth Saks
-
Method Summary
Modifier and TypeMethodDescription<T> TcreateManagedObject(Class<T> clazz) Create a managed object for the given class.<T> TcreateManagedObject(Class<T> clazz, boolean invokePostConstruct) Create a managed object for the given class.voiddestroyManagedObject(Object managedObject) Destroy a managed object that was created via createManagedObject.voiddestroyManagedObject(Object managedObject, boolean validate) Destroy a managed object that may have been created via createManagedObject.<T> voidinject(Class<? extends T> clazz, T instance, com.sun.enterprise.deployment.JndiNameEnvironment envDescriptor, String componentId, boolean invokePostConstruct) Perform injection.voidinjectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) Inject the injectable resources from the given component environment into a Class instance.voidinjectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) Inject the injectable resources from the given component environment into a Class instance.voidinjectClass(Class<?> clazz, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct) Inject the injectable resources from the given component id into a Class instance.voidinjectInstance(Object instance) Inject the given object instance with the resources from its component environment.voidinjectInstance(Object instance, boolean invokePostConstruct) Inject the given object instance with the resources from its component environment.voidinjectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) Inject the injectable resources from the given component environment into an object instance.voidinjectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) Inject the injectable resources from the given component environment into an object instance.voidinjectInstance(Object instance, org.glassfish.api.naming.SimpleJndiName globalJndiName, boolean invokePostConstruct) Inject the injectable resources for the given component id into an object instance.voidinvokeClassPreDestroy(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) Invoke any static @PreDestroy methods defined on the class (and super-classes).voidinvokeInstancePostConstruct(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) Invoke any @PostConstruct methods defined on the instance's class (and super-classes).voidinvokeInstancePreDestroy(Object instance) Invoke any @PreDestroy methods defined on the instance's class (and super-classes).voidinvokeInstancePreDestroy(Object instance, boolean validate) Invoke any @PreDestroy methods defined on the instance's class (and super-classes).voidinvokeInstancePreDestroy(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) Invoke any @PreDestroy methods defined on the instance's class (and super-classes).
-
Method Details
-
injectInstance
Inject the given object instance with the resources from its component environment. The applicable component naming environment information will be retrieved from the current invocation context. Any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectInstance
Inject the given object instance with the resources from its component environment. The applicable component naming environment information will be retrieved from the current invocation context. If invokePostConstruct is true, any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectInstance
void injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException Inject the injectable resources from the given component environment into an object instance. The specified componentEnv must match the environment that is associated with the component on top of the invocation stack at the time this method is invoked. Any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectInstance
void injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) throws InjectionException Inject the injectable resources from the given component environment into an object instance. The specified componentEnv must match the environment that is associated with the component on top of the invocation stack at the time this method is invoked.- Parameters:
invokePostConstruct- if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectInstance
void injectInstance(Object instance, org.glassfish.api.naming.SimpleJndiName globalJndiName, boolean invokePostConstruct) throws InjectionException Inject the injectable resources for the given component id into an object instance.- Parameters:
invokePostConstruct- if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectClass
void injectClass(Class<?> clazz, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct) throws InjectionException Inject the injectable resources from the given component id into a Class instance. Only class-level(static) fields/methods are supported. E.g., this injection operation would be used for the Application Client Container main class.- Parameters:
invokePostConstruct- if true, invoke any @PostConstruct methods on the class(and super-classes) after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectClass
void injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException Inject the injectable resources from the given component environment into a Class instance. Only class-level(static) fields/methods are supported. E.g., this injection operation would be used for the Application Client Container main class. Any @PostConstruct methods on the class(and super-classes) will be invoked after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
injectClass
void injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) throws InjectionException Inject the injectable resources from the given component environment into a Class instance. Only class-level(static) fields/methods are supported. E.g., this injection operation would be used for the Application Client Container main class.- Parameters:
invokePostConstruct- if true, invoke any @PostConstruct methods on the class(and super-classes) after injection.- Throws:
InjectionException- Thrown if an error occurs during injection
-
invokeInstancePreDestroy
Invoke any @PreDestroy methods defined on the instance's class (and super-classes). Invocation information will be retrieved from the current component invocation context.- Throws:
InjectionException- Thrown if an error occurs
-
invokeInstancePreDestroy
Invoke any @PreDestroy methods defined on the instance's class (and super-classes). Invocation information will be retrieved from the current component invocation context.- Parameters:
validate- if false, do nothing if the instance is not registered- Throws:
InjectionException- Thrown if an error occurs
-
invokeInstancePreDestroy
void invokeInstancePreDestroy(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException Invoke any @PreDestroy methods defined on the instance's class (and super-classes). The specified componentEnv must match the environment that is associated with the component on top of the invocation stack at the time this method is invoked.- Throws:
InjectionException- Thrown if an error occurs
-
invokeInstancePostConstruct
void invokeInstancePostConstruct(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException Invoke any @PostConstruct methods defined on the instance's class (and super-classes). The specified componentEnv must match the environment that is associated with the component on top of the invocation stack at the time this method is invoked.- Throws:
InjectionException- Thrown if an error occurs
-
invokeClassPreDestroy
void invokeClassPreDestroy(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException Invoke any static @PreDestroy methods defined on the class (and super-classes). The specified componentEnv must match the environment that is associated with the component on top of the invocation stack at the time this method is invoked.- Throws:
InjectionException- Thrown if an error occurs
-
createManagedObject
Create a managed object for the given class. The object will be injected and any PostConstruct methods will be called. The returned object can be cast to the clazz type but is not necessarily a direct reference to the managed instance. All invocations on the returned object should be on its public methods. It is the responsibility of the caller to destroy the returned object by calling destroyManagedObject(Object managedObject).- Parameters:
clazz- Class to be instantiated- Returns:
- managed object
- Throws:
InjectionException
-
createManagedObject
Create a managed object for the given class. The object will be injected and if invokePostConstruct is true, any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection. The returned object can be cast to the clazz type but is not necessarily a direct reference to the managed instance. All invocations on the returned object should be on its public methods. It is the responsibility of the caller to destroy the returned object by calling destroyManagedObject(Object managedObject).- Parameters:
clazz- Class to be instantiatedinvokePostConstruct- if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.- Returns:
- managed object
- Throws:
InjectionException
-
destroyManagedObject
Destroy a managed object that was created via createManagedObject. Any PreDestroy methods will be called.- Parameters:
managedObject-- Throws:
InjectionException
-
destroyManagedObject
Destroy a managed object that may have been created via createManagedObject. Any PreDestroy methods will be called.- Parameters:
managedObject-validate- if false the object might not been created by createManagedObject() call- Throws:
InjectionException
-
inject
<T> void inject(Class<? extends T> clazz, T instance, com.sun.enterprise.deployment.JndiNameEnvironment envDescriptor, String componentId, boolean invokePostConstruct) throws InjectionException Perform injection.- Parameters:
clazz- The class of the instance to perform injection. This is needed b/c of static injection.instance- The instance on which to perform injection.envDescriptor- The descriptor containing the injection information.componentId- The id of the component in whose jndi environment injection actually occurs. Null indicates the current jndi environment.invokePostConstruct- if true, invoke any @PostConstruct methods- Throws:
InjectionException
-