Class DelayedHk2InjectionManager

java.lang.Object
org.glassfish.jersey.inject.hk2.DelayedHk2InjectionManager
All Implemented Interfaces:
InjectionManager

public class DelayedHk2InjectionManager extends Object
Implementation of InjectionManager that is able to delay service's registration and injection to completeRegistration() phase. During the Jersey bootstrap just keep the bindings and other operation for a later use.
Author:
Petr Bouda
  • Method Details

    • register

      public void register(Binding binding)
      Description copied from interface: InjectionManager
      Registers one bean represented using fields in the provided descriptor. The final bean can be direct bean or factory object which will create the bean at the time of injection. InjectionManager is able to register a bean represented by a class or direct instance.
      Parameters:
      binding - one descriptor.
      See Also:
    • register

      public void register(Iterable<Binding> bindings)
      Description copied from interface: InjectionManager
      Registers a collection of beans represented using fields in the provided descriptors. The final bean can be direct bean or factory object which will create the bean at the time of injection. InjectionManager is able to register a bean represented by a class or direct instance.
      Parameters:
      bindings - collection of descriptors.
      See Also:
    • register

      public void register(Binder binder)
      Description copied from interface: InjectionManager
      Registers beans which are included in Binder. Binder can contains all descriptors extending Binding or other binders which are installed together in tree-structure. This method will get all descriptors bound in the given binder and register them in the order how the binders are installed together. In the tree structure, the deeper on the left side will be processed first.
      Parameters:
      binder - collection of descriptors.
      See Also:
    • register

      public void register(Object provider) throws IllegalArgumentException
      Description copied from interface: InjectionManager
      Registers a provider. An implementation of the InjectionManager should test whether the type of the object can be registered using the method InjectionManager.isRegistrable(Class). Then a caller has an certainty that the instance of the tested class can be registered in InjectionManager. If InjectionManager is not able to register the provider then IllegalArgumentException is thrown.
      Parameters:
      provider - object that can be registered in InjectionManager.
      Throws:
      IllegalArgumentException - provider cannot be registered.
    • completeRegistration

      public void completeRegistration() throws IllegalStateException
      Description copied from interface: InjectionManager
      Completes InjectionManager and the underlying DI provider. All registered components are bound to injection manager and after an invocation of this method all components are available using e.g. InjectionManager.getInstance(Class).
      Throws:
      IllegalStateException
    • getServiceLocator

      public 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
    • isShutdown

      public boolean isShutdown()
      Description copied from interface: InjectionManager
      Returns true when the InjectionManager has been shutdown, false otherwise.
      Specified by:
      isShutdown in interface InjectionManager
      Returns:
      Whether the InjectionManager has been shutdown.
    • create

      public <U> U create(Class<U> clazz)
      Description copied from interface: InjectionManager
      Creates an object with the given class.

      The object created is not managed by the injection manager.

      Specified by:
      create in interface InjectionManager
      Parameters:
      clazz - The non-null class to create this object from;
      Returns:
      An instance of the object that has been created.
    • 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