Class AbstractHk2InjectionManager
- java.lang.Object
-
- org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager
-
- All Implemented Interfaces:
InjectionManager
- Direct Known Subclasses:
DelayedHk2InjectionManager
,ImmediateHk2InjectionManager
abstract class AbstractHk2InjectionManager extends java.lang.Object implements InjectionManager
Abstract class dedicated to implementations ofInjectionManager
providing several convenient methods.
-
-
Constructor Summary
Constructors Constructor Description AbstractHk2InjectionManager(java.lang.Object parent)
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
assertParentLocatorType(java.lang.Object parent)
Checks if the parent is null then must be an instance ofServiceLocator
orInjectionManager
.<U> U
createAndInitialize(java.lang.Class<U> clazz)
Creates, injects and post-constructs an object with the given class.private ForeignDescriptor
createAndTranslateForeignDescriptor(Binding binding)
ForeignDescriptor
createForeignDescriptor(Binding binding)
Creates and registers the descriptor in the underlying DI provider and returnsForeignDescriptor
that is specific descriptor for the underlying DI provider.private static org.glassfish.hk2.api.ServiceLocator
createLocator(org.glassfish.hk2.api.ServiceLocator parentLocator)
Creates a newServiceLocator
instance from staticServiceLocatorFactory
and adds the provided parent locator if the instance is not null.<T> java.util.List<T>
getAllInstances(java.lang.reflect.Type clazz)
Gets all services from this injection manager that implement this contract or have this implementation.<T> java.util.List<ServiceHolder<T>>
getAllServiceHolders(java.lang.Class<T> contract, java.lang.annotation.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 byServiceHolder
.<T> T
getInstance(java.lang.Class<T> clazz)
Gets the best service from this injection manager that implements this contract or has this implementation.<T> T
getInstance(java.lang.Class<T> clazz, java.lang.annotation.Annotation... annotations)
Gets the best service from this injection manager that implements this contract or has this implementation.<T> T
getInstance(java.lang.Class<T> clazz, java.lang.String classAnalyzer)
Gets the best service from this injection manager that implements this contract or has this implementation.<T> T
getInstance(java.lang.reflect.Type clazz)
Gets the best service from this injection manager that implements this contract or has this implementation.java.lang.Object
getInstance(ForeignDescriptor foreignDescriptor)
Gets the service instance according toForeignDescriptor
which is specific to the underlying DI provider.org.glassfish.hk2.api.ServiceLocator
getServiceLocator()
void
inject(java.lang.Object injectMe)
Analyzes the given object and inject into its fields and methods.void
inject(java.lang.Object injectMe, java.lang.String classAnalyzer)
This will analyze the given object and inject into its fields and methods.boolean
isRegistrable(java.lang.Class<?> clazz)
Tests whether the providedclazz
can be registered by the implementation of theInjectionManager
.void
preDestroy(java.lang.Object preDestroyMe)
Analyzes the given object and call the preDestroy method.private static org.glassfish.hk2.api.ServiceLocator
resolveServiceLocatorParent(java.lang.Object parent)
void
shutdown()
Shuts down the entireInjectionManager
and the underlying DI provider.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.glassfish.jersey.internal.inject.InjectionManager
completeRegistration, register, register, register, register
-
-
-
-
Constructor Detail
-
AbstractHk2InjectionManager
AbstractHk2InjectionManager(java.lang.Object parent)
Private constructor.- Parameters:
parent
- parent of typeInjectionManager
orServiceLocator
.
-
-
Method Detail
-
createLocator
private static org.glassfish.hk2.api.ServiceLocator createLocator(org.glassfish.hk2.api.ServiceLocator parentLocator)
Creates a newServiceLocator
instance from staticServiceLocatorFactory
and adds the provided parent locator if the instance is not null.- Parameters:
parentLocator
- parent locator, can benull
.- Returns:
- new instance of injection manager.
-
resolveServiceLocatorParent
private static org.glassfish.hk2.api.ServiceLocator resolveServiceLocatorParent(java.lang.Object parent)
-
assertParentLocatorType
private static void assertParentLocatorType(java.lang.Object parent)
Checks if the parent is null then must be an instance ofServiceLocator
orInjectionManager
.- Parameters:
parent
- object represented byServiceLocator
orHK2InjectionManager
.
-
getServiceLocator
public org.glassfish.hk2.api.ServiceLocator getServiceLocator()
-
isRegistrable
public boolean isRegistrable(java.lang.Class<?> clazz)
Description copied from interface:InjectionManager
Tests whether the providedclazz
can be registered by the implementation of theInjectionManager
.- Specified by:
isRegistrable
in interfaceInjectionManager
- Parameters:
clazz
- type that is tested whether is registrable by the implementation ofInjectionManager
.- Returns:
true
if theInjectionManager
is able to register this type.
-
getAllServiceHolders
public <T> java.util.List<ServiceHolder<T>> getAllServiceHolders(java.lang.Class<T> contract, java.lang.annotation.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 byServiceHolder
.- Specified by:
getAllServiceHolders
in interfaceInjectionManager
- 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(java.lang.Class<T> clazz, java.lang.annotation.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 interfaceInjectionManager
- 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(java.lang.reflect.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 interfaceInjectionManager
- 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 java.lang.Object getInstance(ForeignDescriptor foreignDescriptor)
Description copied from interface:InjectionManager
Gets the service instance according toForeignDescriptor
which is specific to the underlying DI provider.- Specified by:
getInstance
in interfaceInjectionManager
- Parameters:
foreignDescriptor
- DI specific descriptor.- Returns:
- service instance according to foreign descriptor.
-
getInstance
public <T> T getInstance(java.lang.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 interfaceInjectionManager
- 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(java.lang.Class<T> clazz, java.lang.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 interfaceInjectionManager
- 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> java.util.List<T> getAllInstances(java.lang.reflect.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 interfaceInjectionManager
- 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(java.lang.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 interfaceInjectionManager
- Parameters:
preDestroyMe
- The object to preDestroy
-
shutdown
public void shutdown()
Description copied from interface:InjectionManager
Shuts down the entireInjectionManager
and the underlying DI provider.Shutdown phase is dedicated to make some final cleaning steps regarding underlying DI provider.
- Specified by:
shutdown
in interfaceInjectionManager
-
createAndInitialize
public <U> U createAndInitialize(java.lang.Class<U> clazz)
Description copied from interface:InjectionManager
Creates, injects and post-constructs an object with the given class. This is equivalent to calling thecreate-class
method followed by theinject-class
method followed by thepost-construct
method.The object created is not managed by the injection manager.
- Specified by:
createAndInitialize
in interfaceInjectionManager
- 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 returnsForeignDescriptor
that is specific descriptor for the underlying DI provider.- Specified by:
createForeignDescriptor
in interfaceInjectionManager
- Parameters:
binding
- jersey descriptor.- Returns:
- specific foreign descriptor of the underlying DI provider.
-
inject
public void inject(java.lang.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 interfaceInjectionManager
- Parameters:
injectMe
- The object to be analyzed and injected into
-
inject
public void inject(java.lang.Object injectMe, java.lang.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 interfaceInjectionManager
- Parameters:
injectMe
- The object to be analyzed and injected into
-
createAndTranslateForeignDescriptor
private ForeignDescriptor createAndTranslateForeignDescriptor(Binding binding)
-
-