Class CdiSeInjectionManager

java.lang.Object
org.glassfish.jersey.inject.cdi.se.CdiSeInjectionManager
All Implemented Interfaces:
org.glassfish.jersey.internal.inject.InjectionManager

public class CdiSeInjectionManager extends Object implements org.glassfish.jersey.internal.inject.InjectionManager
Implementation of InjectionManager that starts CDI SE container, scans all users bean according to beans.xml file and register Jersey's internal beans using SeBeanRegisterExtension extension.
Author:
Petr Bouda
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Completes InjectionManager and the underlying DI provider.
    <T> T
    create(Class<T> createMe)
    Creates an object with the given class.
    <T> T
    Creates, injects and post-constructs an object with the given class.
    org.glassfish.jersey.internal.inject.ForeignDescriptor
    createForeignDescriptor(org.glassfish.jersey.internal.inject.Binding binding)
    Creates and registers the descriptor in the underlying DI provider and returns ForeignDescriptor that is specific descriptor for the underlying DI provider.
    <T> List<T>
    getAllInstances(Type contractOrImpl)
    Gets all services from this injection manager that implement this contract or have this implementation.
    <T> List<org.glassfish.jersey.internal.inject.ServiceHolder<T>>
    getAllServiceHolders(Class<T> contractOrImpl, Annotation... qualifiers)
    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.
    jakarta.enterprise.inject.spi.BeanManager
     
    protected org.glassfish.jersey.internal.inject.AbstractBinder
     
    jakarta.enterprise.inject.se.SeContainer
     
    <T> T
    getInstance(Class<T> contractOrImpl)
    Gets the best service from this injection manager that implements this contract or has this implementation.
    <T> T
    getInstance(Class<T> contractOrImpl, Annotation... qualifiers)
    Gets the best service from this injection manager that implements this contract or has this implementation.
    <T> T
    getInstance(Class<T> contractOrImpl, String classAnalyzer)
    Gets the best service from this injection manager that implements this contract or has this implementation.
    <T> T
    getInstance(Type contractOrImpl)
    Gets the best service from this injection manager that implements this contract or has this implementation.
    getInstance(org.glassfish.jersey.internal.inject.ForeignDescriptor foreignDescriptor)
    Gets the service instance according to ForeignDescriptor which is specific to the underlying DI provider.
    void
    inject(Object instance)
    Analyzes the given object and inject into its fields and methods.
    void
    inject(Object injectMe, String classAnalyzer)
    This will analyze the given object and inject into its fields and methods.
    boolean
    isRegistrable(Class<?> clazz)
    Tests whether the provided clazz can be registered by the implementation of the InjectionManager.
    boolean
    Returns true when the InjectionManager has been shutdown, false otherwise.
    void
    preDestroy(Object preDestroyMe)
    Analyzes the given object and call the preDestroy method.
    void
    register(Iterable<org.glassfish.jersey.internal.inject.Binding> bindings)
    Registers a collection of beans represented using fields in the provided descriptors.
    void
    register(Object provider)
    Registers a provider.
    void
    register(org.glassfish.jersey.internal.inject.Binder binder)
    Registers beans which are included in Binder.
    void
    register(org.glassfish.jersey.internal.inject.Binding binding)
    Registers one bean represented using fields in the provided descriptor.
    void
    setBeanManager(jakarta.enterprise.inject.spi.BeanManager beanManager)
     
    void
    setContainer(jakarta.enterprise.inject.se.SeContainer container)
     
    void
    Shuts down the entire InjectionManager and the underlying DI provider.

    Methods inherited from class java.lang.Object

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

    • CdiSeInjectionManager

      public CdiSeInjectionManager()
  • Method Details

    • register

      public void register(org.glassfish.jersey.internal.inject.Binding binding)
      Description copied from interface: org.glassfish.jersey.internal.inject.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.
      Specified by:
      register in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      binding - one descriptor.
      See Also:
      • ClassBinding
      • InstanceBinding
      • SupplierClassBinding
      • SupplierInstanceBinding
    • register

      public void register(Iterable<org.glassfish.jersey.internal.inject.Binding> bindings)
      Description copied from interface: org.glassfish.jersey.internal.inject.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.
      Specified by:
      register in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      bindings - collection of descriptors.
      See Also:
      • ClassBinding
      • InstanceBinding
      • SupplierClassBinding
      • SupplierInstanceBinding
    • register

      public void register(org.glassfish.jersey.internal.inject.Binder binder)
      Description copied from interface: org.glassfish.jersey.internal.inject.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.
      Specified by:
      register in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      binder - collection of descriptors.
      See Also:
      • ClassBinding
      • InstanceBinding
      • SupplierClassBinding
      • SupplierInstanceBinding
    • register

      public void register(Object provider) throws IllegalArgumentException
      Description copied from interface: org.glassfish.jersey.internal.inject.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.
      Specified by:
      register in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      provider - object that can be registered in InjectionManager.
      Throws:
      IllegalArgumentException - provider cannot be registered.
    • isRegistrable

      public boolean isRegistrable(Class<?> clazz)
      Description copied from interface: org.glassfish.jersey.internal.inject.InjectionManager
      Tests whether the provided clazz can be registered by the implementation of the InjectionManager.
      Specified by:
      isRegistrable in interface org.glassfish.jersey.internal.inject.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.
    • createAndInitialize

      public <T> T createAndInitialize(Class<T> createMe)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      createMe - The non-null class to create this object from;
      Returns:
      An instance of the object that has been created, injected and post constructed.
    • create

      public <T> T create(Class<T> createMe)
      Description copied from interface: org.glassfish.jersey.internal.inject.InjectionManager
      Creates an object with the given class.

      The object created is not managed by the injection manager.

      Specified by:
      create in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      createMe - The non-null class to create this object from;
      Returns:
      An instance of the object that has been created.
    • getAllServiceHolders

      public <T> List<org.glassfish.jersey.internal.inject.ServiceHolder<T>> getAllServiceHolders(Class<T> contractOrImpl, Annotation... qualifiers)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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> contractOrImpl, Annotation... qualifiers)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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. May return null if there is no provider that provides the given implementation or contract.
    • getInstance

      public <T> T getInstance(Class<T> contractOrImpl)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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(Type contractOrImpl)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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(org.glassfish.jersey.internal.inject.ForeignDescriptor foreignDescriptor)
      Description copied from interface: org.glassfish.jersey.internal.inject.InjectionManager
      Gets the service instance according to ForeignDescriptor which is specific to the underlying DI provider.
      Specified by:
      getInstance in interface org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      foreignDescriptor - DI specific descriptor.
      Returns:
      service instance according to foreign descriptor.
    • createForeignDescriptor

      public org.glassfish.jersey.internal.inject.ForeignDescriptor createForeignDescriptor(org.glassfish.jersey.internal.inject.Binding binding)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      binding - jersey descriptor.
      Returns:
      specific foreign descriptor of the underlying DI provider.
    • getAllInstances

      public <T> List<T> getAllInstances(Type contractOrImpl)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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
    • inject

      public void inject(Object instance)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      instance - The object to be analyzed and injected into
    • preDestroy

      public void preDestroy(Object preDestroyMe)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      preDestroyMe - The object to preDestroy
    • completeRegistration

      public void completeRegistration() throws IllegalStateException
      Description copied from interface: org.glassfish.jersey.internal.inject.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).
      Specified by:
      completeRegistration in interface org.glassfish.jersey.internal.inject.InjectionManager
      Throws:
      IllegalStateException
    • getBindings

      protected org.glassfish.jersey.internal.inject.AbstractBinder getBindings()
    • getContainer

      public jakarta.enterprise.inject.se.SeContainer getContainer()
    • setContainer

      public void setContainer(jakarta.enterprise.inject.se.SeContainer container)
    • getBeanManager

      public jakarta.enterprise.inject.spi.BeanManager getBeanManager()
    • setBeanManager

      public void setBeanManager(jakarta.enterprise.inject.spi.BeanManager beanManager)
    • shutdown

      public void shutdown()
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
    • isShutdown

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

      public void inject(Object injectMe, String classAnalyzer)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Parameters:
      injectMe - The object to be analyzed and injected into
    • getInstance

      public <T> T getInstance(Class<T> contractOrImpl, String classAnalyzer)
      Description copied from interface: org.glassfish.jersey.internal.inject.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 org.glassfish.jersey.internal.inject.InjectionManager
      Type Parameters:
      T - Instance type.
      Parameters:
      contractOrImpl - 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.