Class AbstractHk2InjectionManager

java.lang.Object
org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager
All Implemented Interfaces:
InjectionManager
Direct Known Subclasses:
DelayedHk2InjectionManager, ImmediateHk2InjectionManager

abstract class AbstractHk2InjectionManager extends Object implements InjectionManager
Abstract class dedicated to implementations of InjectionManager providing several convenient methods.
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • factory

      private static final org.glassfish.hk2.api.ServiceLocatorFactory factory
    • locator

      private org.glassfish.hk2.api.ServiceLocator locator
  • Constructor Details

    • AbstractHk2InjectionManager

      AbstractHk2InjectionManager(Object parent)
      Private constructor.
      Parameters:
      parent - parent of type InjectionManager or ServiceLocator.
  • Method Details

    • createLocator

      private static org.glassfish.hk2.api.ServiceLocator createLocator(org.glassfish.hk2.api.ServiceLocator parentLocator)
      Creates a new ServiceLocator instance from static ServiceLocatorFactory and adds the provided parent locator if the instance is not null.
      Parameters:
      parentLocator - parent locator, can be null.
      Returns:
      new instance of injection manager.
    • resolveServiceLocatorParent

      private static org.glassfish.hk2.api.ServiceLocator resolveServiceLocatorParent(Object parent)
    • assertParentLocatorType

      private static void assertParentLocatorType(Object parent)
      Checks if the parent is null then must be an instance of ServiceLocator or InjectionManager.
      Parameters:
      parent - object represented by ServiceLocator or HK2InjectionManager.
    • getServiceLocator

      public org.glassfish.hk2.api.ServiceLocator getServiceLocator()
    • isRegistrable

      public boolean isRegistrable(Class<?> clazz)
      Description copied from interface: InjectionManager
      Tests whether the provided clazz can be registered by the implementation of the InjectionManager.
      Specified by:
      isRegistrable in interface InjectionManager
      Parameters:
      clazz - type that is tested whether is registrable by the implementation of InjectionManager.
      Returns:
      true if the InjectionManager is able to register this type.
    • getAllServiceHolders

      public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers)
      Description copied from interface: InjectionManager
      Gets all services from this injection manager that implements this contract or has this implementation along with information about the service which can be kept by ServiceHolder.
      Specified by:
      getAllServiceHolders in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contract - May not be null, and is the contract or concrete implementation to get the best instance of.
      qualifiers - The set of qualifiers that must match this service definition.
      Returns:
      An instance of the contract or impl along with other information. May return null if there is no provider that provides the given implementation or contract.
    • getInstance

      public <T> T getInstance(Class<T> clazz, Annotation... annotations)
      Description copied from interface: InjectionManager
      Gets the best service from this injection manager that implements this contract or has this implementation.

      Use this method only if other information is not needed otherwise use, otherwise use InjectionManager.getAllServiceHolders(Class, Annotation...).

      Specified by:
      getInstance in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      clazz - May not be null, and is the contract or concrete implementation to get the best instance of.
      annotations - The set of qualifiers that must match this service definition.
      Returns:
      An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
    • getInstance

      public <T> T getInstance(Type clazz)
      Description copied from interface: InjectionManager
      Gets the best service from this injection manager that implements this contract or has this implementation.

      Use this method only if other information is not needed otherwise use, otherwise use InjectionManager.getAllServiceHolders(Class, Annotation...).

      Specified by:
      getInstance in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      clazz - May not be null, and is the contract or concrete implementation to get the best instance of.
      Returns:
      An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
    • getInstance

      public Object getInstance(ForeignDescriptor foreignDescriptor)
      Description copied from interface: InjectionManager
      Gets the service instance according to ForeignDescriptor which is specific to the underlying DI provider.
      Specified by:
      getInstance in interface InjectionManager
      Parameters:
      foreignDescriptor - DI specific descriptor.
      Returns:
      service instance according to foreign descriptor.
    • getInstance

      public <T> T getInstance(Class<T> clazz)
      Description copied from interface: InjectionManager
      Gets the best service from this injection manager that implements this contract or has this implementation.

      Use this method only if other information is not needed otherwise use, otherwise use InjectionManager.getAllServiceHolders(Class, Annotation...).

      Specified by:
      getInstance in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      clazz - May not be null, and is the contract or concrete implementation to get the best instance of.
      Returns:
      An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
    • getInstance

      public <T> T getInstance(Class<T> clazz, String classAnalyzer)
      Description copied from interface: InjectionManager
      Gets the best service from this injection manager that implements this contract or has this implementation.

      Use this method only if other information is not needed otherwise use, otherwise use InjectionManager.getAllServiceHolders(Class, Annotation...).

      Specified by:
      getInstance in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      clazz - May not be null, and is the contract or concrete implementation to get the best instance of.
      classAnalyzer - -------
      Returns:
      An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
    • getAllInstances

      public <T> List<T> getAllInstances(Type clazz)
      Description copied from interface: InjectionManager
      Gets all services from this injection manager that implement this contract or have this implementation.

      Use this method only if other information is not needed otherwise use, otherwise use InjectionManager.getAllServiceHolders(Class, Annotation...).

      Specified by:
      getAllInstances in interface InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      clazz - May not be null, and is the contract or concrete implementation to get the best instance of.
      Returns:
      A list of services implementing this contract or concrete implementation. May not return null, but may return an empty list
    • preDestroy

      public void preDestroy(Object preDestroyMe)
      Description copied from interface: InjectionManager
      Analyzes the given object and call the preDestroy method. The object given will not be managed by bean manager.
      Specified by:
      preDestroy in interface InjectionManager
      Parameters:
      preDestroyMe - The object to preDestroy
    • shutdown

      public void shutdown()
      Description copied from interface: InjectionManager
      Shuts down the entire InjectionManager and the underlying DI provider.

      Shutdown phase is dedicated to make some final cleaning steps regarding underlying DI provider.

      Specified by:
      shutdown in interface InjectionManager
    • createAndInitialize

      public <U> U createAndInitialize(Class<U> clazz)
      Description copied from interface: InjectionManager
      Creates, injects and post-constructs an object with the given class. This is equivalent to calling the create-class method followed by the inject-class method followed by the post-construct method.

      The object created is not managed by the injection manager.

      Specified by:
      createAndInitialize in interface InjectionManager
      Parameters:
      clazz - The non-null class to create this object from;
      Returns:
      An instance of the object that has been created, injected and post constructed.
    • createForeignDescriptor

      public ForeignDescriptor createForeignDescriptor(Binding binding)
      Description copied from interface: InjectionManager
      Creates and registers the descriptor in the underlying DI provider and returns ForeignDescriptor that is specific descriptor for the underlying DI provider.
      Specified by:
      createForeignDescriptor in interface InjectionManager
      Parameters:
      binding - jersey descriptor.
      Returns:
      specific foreign descriptor of the underlying DI provider.
    • inject

      public void inject(Object injectMe)
      Description copied from interface: InjectionManager
      Analyzes the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2
      Specified by:
      inject in interface InjectionManager
      Parameters:
      injectMe - The object to be analyzed and injected into
    • inject

      public void inject(Object injectMe, String classAnalyzer)
      Description copied from interface: InjectionManager
      This will analyze the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2
      Specified by:
      inject in interface InjectionManager
      Parameters:
      injectMe - The object to be analyzed and injected into
    • createAndTranslateForeignDescriptor

      private ForeignDescriptor createAndTranslateForeignDescriptor(Binding binding)