Class InjectionManagerImpl

java.lang.Object
com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
All Implemented Interfaces:
InjectionManager, org.glassfish.hk2.api.PostConstruct

@Service public class InjectionManagerImpl extends Object implements InjectionManager, org.glassfish.hk2.api.PostConstruct
Implementation of InjectionManager.
Author:
Kenneth Saks
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    Create a managed object for the given class.
    <T> T
    createManagedObject(Class<T> clazz, boolean invokePostConstruct)
    Create a managed object for the given class.
    void
    Destroy a managed object that was created via createManagedObject.
    void
    destroyManagedObject(Object managedObject, boolean validate)
    Destroy a managed object that was created via createManagedObject.
    <T> void
    inject(Class<? extends T> clazz, T instance, com.sun.enterprise.deployment.JndiNameEnvironment envDescriptor, String componentId, boolean invokePostConstruct)
    Perform injection.
    void
    injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv)
    Inject the injectable resources from the given component environment into a Class instance.
    void
    injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct)
    Inject the injectable resources from the given component environment into a Class instance.
    void
    injectClass(Class<?> clazz, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct)
    Inject the injectable resources from the given component id into a Class instance.
    void
    Inject the given object instance with the resources from its component environment.
    void
    injectInstance(Object instance, boolean invokePostConstruct)
    Inject the given object instance with the resources from its component environment.
    void
    injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv)
    Inject the injectable resources from the given component environment into an object instance.
    void
    injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct)
    Inject the injectable resources from the given component environment into an object instance.
    void
    injectInstance(Object instance, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct)
    Inject the injectable resources for the given component id into an object instance.
    void
    invokeClassPreDestroy(Class clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv)
    Invoke any static @PreDestroy methods defined on the class (and super-classes).
    void
    invokeInstancePostConstruct(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv)
    Invoke any @PostConstruct methods defined on the instance's class (and super-classes).
    void
    Invoke any @PreDestroy methods defined on the instance's class (and super-classes).
    void
    invokeInstancePreDestroy(Object instance, boolean validate)
    Invoke any @PreDestroy methods defined on the instance's class (and super-classes).
    void
    invokeInstancePreDestroy(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv)
    Invoke any @PreDestroy methods defined on the instance's class (and super-classes).
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InjectionManagerImpl

      public InjectionManagerImpl()
  • Method Details

    • postConstruct

      public void postConstruct()
      Specified by:
      postConstruct in interface org.glassfish.hk2.api.PostConstruct
    • injectInstance

      public void injectInstance(Object instance) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectInstance in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs during injection
    • injectInstance

      public void injectInstance(Object instance, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectInstance in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs during injection
    • injectInstance

      public void injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectInstance in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs during injection
    • injectInstance

      public void injectInstance(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectInstance in interface InjectionManager
      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

      public void injectInstance(Object instance, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      Inject the injectable resources for the given component id into an object instance.
      Specified by:
      injectInstance in interface InjectionManager
      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

      public void injectClass(Class<?> clazz, org.glassfish.api.naming.SimpleJndiName jndiName, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectClass in interface InjectionManager
      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

      public void injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectClass in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs during injection
    • injectClass

      public void injectClass(Class<?> clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      injectClass in interface InjectionManager
      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

      public void invokeInstancePreDestroy(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      invokeInstancePreDestroy in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs
    • invokeInstancePostConstruct

      public void invokeInstancePostConstruct(Object instance, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      invokeInstancePostConstruct in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs
    • invokeInstancePreDestroy

      public void invokeInstancePreDestroy(Object instance) throws InjectionException
      Description copied from interface: InjectionManager
      Invoke any @PreDestroy methods defined on the instance's class (and super-classes). Invocation information will be retrieved from the current component invocation context.
      Specified by:
      invokeInstancePreDestroy in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs
    • invokeInstancePreDestroy

      public void invokeInstancePreDestroy(Object instance, boolean validate) throws InjectionException
      Description copied from interface: InjectionManager
      Invoke any @PreDestroy methods defined on the instance's class (and super-classes). Invocation information will be retrieved from the current component invocation context.
      Specified by:
      invokeInstancePreDestroy in interface InjectionManager
      validate - if false, do nothing if the instance is not registered
      Throws:
      InjectionException - Thrown if an error occurs
    • invokeClassPreDestroy

      public void invokeClassPreDestroy(Class clazz, com.sun.enterprise.deployment.JndiNameEnvironment componentEnv) throws InjectionException
      Description copied from interface: InjectionManager
      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.
      Specified by:
      invokeClassPreDestroy in interface InjectionManager
      Throws:
      InjectionException - Thrown if an error occurs
    • createManagedObject

      public <T> T createManagedObject(Class<T> clazz) throws InjectionException
      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).
      Specified by:
      createManagedObject in interface InjectionManager
      Parameters:
      clazz - Class to be instantiated
      Returns:
      managed object
      Throws:
      InjectionException
    • createManagedObject

      public <T> T createManagedObject(Class<T> clazz, boolean invokePostConstruct) throws InjectionException
      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).
      Specified by:
      createManagedObject in interface InjectionManager
      Parameters:
      clazz - Class to be instantiated
      invokePostConstruct - if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.
      Returns:
      managed object
      Throws:
      InjectionException
    • destroyManagedObject

      public void destroyManagedObject(Object managedObject) throws InjectionException
      Destroy a managed object that was created via createManagedObject. Any PreDestroy methods will be called.
      Specified by:
      destroyManagedObject in interface InjectionManager
      Parameters:
      managedObject -
      Throws:
      InjectionException
    • destroyManagedObject

      public void destroyManagedObject(Object managedObject, boolean validate) throws InjectionException
      Destroy a managed object that was created via createManagedObject. Any PreDestroy methods will be called.
      Specified by:
      destroyManagedObject in interface InjectionManager
      Parameters:
      managedObject -
      validate - if false, do nothing if the instance is not registered
      Throws:
      InjectionException
    • inject

      public <T> void inject(Class<? extends T> clazz, T instance, com.sun.enterprise.deployment.JndiNameEnvironment envDescriptor, String componentId, boolean invokePostConstruct) throws InjectionException
      Description copied from interface: InjectionManager
      Perform injection.
      Specified by:
      inject in interface InjectionManager
      Parameters:
      instance - Target instance for injection, or null if injection is class-based. Any error encountered during any portion of injection is propagated immediately.
      clazz - The class of the instance to perform injection. This is needed b/c of static 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