abstract class AbstractHk2InjectionManager extends java.lang.Object implements InjectionManager
InjectionManager
providing several convenient methods.Modifier and Type | Field and Description |
---|---|
private static org.glassfish.hk2.api.ServiceLocatorFactory |
factory |
private org.glassfish.hk2.api.ServiceLocator |
locator |
private static java.util.logging.Logger |
LOGGER |
Constructor and Description |
---|
AbstractHk2InjectionManager(java.lang.Object parent)
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
private static void |
assertParentLocatorType(java.lang.Object parent)
Checks if the parent is null then must be an instance of
ServiceLocator or InjectionManager . |
<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 returns
ForeignDescriptor 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 new
ServiceLocator instance from static ServiceLocatorFactory 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 by
ServiceHolder . |
<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.
|
java.lang.Object |
getInstance(ForeignDescriptor foreignDescriptor)
Gets the service instance according to
ForeignDescriptor which is specific to the underlying DI provider. |
<T> T |
getInstance(java.lang.reflect.Type clazz)
Gets the best service from this injection manager that implements this contract or has this implementation.
|
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 provided
clazz can be registered by the implementation of the InjectionManager . |
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 entire
InjectionManager and the underlying DI provider. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
completeRegistration, register, register, register, register
private static final java.util.logging.Logger LOGGER
private static final org.glassfish.hk2.api.ServiceLocatorFactory factory
private org.glassfish.hk2.api.ServiceLocator locator
AbstractHk2InjectionManager(java.lang.Object parent)
parent
- parent of type InjectionManager
or ServiceLocator
.private static org.glassfish.hk2.api.ServiceLocator createLocator(org.glassfish.hk2.api.ServiceLocator parentLocator)
ServiceLocator
instance from static ServiceLocatorFactory
and adds the provided parent
locator if the instance is not null.parentLocator
- parent locator, can be null
.private static org.glassfish.hk2.api.ServiceLocator resolveServiceLocatorParent(java.lang.Object parent)
private static void assertParentLocatorType(java.lang.Object parent)
ServiceLocator
or InjectionManager
.parent
- object represented by ServiceLocator
or HK2InjectionManager
.public org.glassfish.hk2.api.ServiceLocator getServiceLocator()
public boolean isRegistrable(java.lang.Class<?> clazz)
InjectionManager
clazz
can be registered by the implementation of the InjectionManager
.isRegistrable
in interface InjectionManager
clazz
- type that is tested whether is registrable by the implementation of InjectionManager
.true
if the InjectionManager
is able to register this type.public <T> java.util.List<ServiceHolder<T>> getAllServiceHolders(java.lang.Class<T> contract, java.lang.annotation.Annotation... qualifiers)
InjectionManager
ServiceHolder
.getAllServiceHolders
in interface InjectionManager
T
- Instance type.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.public <T> T getInstance(java.lang.Class<T> clazz, java.lang.annotation.Annotation... annotations)
InjectionManager
Use this method only if other information is not needed otherwise use, otherwise use
InjectionManager.getAllServiceHolders(Class, Annotation...)
.
getInstance
in interface InjectionManager
T
- Instance type.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.public <T> T getInstance(java.lang.reflect.Type clazz)
InjectionManager
Use this method only if other information is not needed otherwise use, otherwise use
InjectionManager.getAllServiceHolders(Class, Annotation...)
.
getInstance
in interface InjectionManager
T
- Instance type.clazz
- May not be null, and is the contract or concrete implementation to get the best instance of.public java.lang.Object getInstance(ForeignDescriptor foreignDescriptor)
InjectionManager
ForeignDescriptor
which is specific to the underlying DI provider.getInstance
in interface InjectionManager
foreignDescriptor
- DI specific descriptor.public <T> T getInstance(java.lang.Class<T> clazz)
InjectionManager
Use this method only if other information is not needed otherwise use, otherwise use
InjectionManager.getAllServiceHolders(Class, Annotation...)
.
getInstance
in interface InjectionManager
T
- Instance type.clazz
- May not be null, and is the contract or concrete implementation to get the best instance of.public <T> T getInstance(java.lang.Class<T> clazz, java.lang.String classAnalyzer)
InjectionManager
Use this method only if other information is not needed otherwise use, otherwise use
InjectionManager.getAllServiceHolders(Class, Annotation...)
.
getInstance
in interface InjectionManager
T
- Instance type.clazz
- May not be null, and is the contract or concrete implementation to get the best instance of.classAnalyzer
- -------public <T> java.util.List<T> getAllInstances(java.lang.reflect.Type clazz)
InjectionManager
Use this method only if other information is not needed otherwise use, otherwise use
InjectionManager.getAllServiceHolders(Class, Annotation...)
.
getAllInstances
in interface InjectionManager
T
- Instance type.clazz
- May not be null, and is the contract or concrete implementation to get the best instance of.public void preDestroy(java.lang.Object preDestroyMe)
InjectionManager
preDestroy
in interface InjectionManager
preDestroyMe
- The object to preDestroypublic void shutdown()
InjectionManager
InjectionManager
and the underlying DI provider.
Shutdown phase is dedicated to make some final cleaning steps regarding underlying DI provider.
shutdown
in interface InjectionManager
public <U> U createAndInitialize(java.lang.Class<U> clazz)
InjectionManager
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.
createAndInitialize
in interface InjectionManager
clazz
- The non-null class to create this object from;public ForeignDescriptor createForeignDescriptor(Binding binding)
InjectionManager
ForeignDescriptor
that is specific
descriptor for the underlying DI provider.createForeignDescriptor
in interface InjectionManager
binding
- jersey descriptor.public void inject(java.lang.Object injectMe)
InjectionManager
inject
in interface InjectionManager
injectMe
- The object to be analyzed and injected intopublic void inject(java.lang.Object injectMe, java.lang.String classAnalyzer)
InjectionManager
inject
in interface InjectionManager
injectMe
- The object to be analyzed and injected intoprivate ForeignDescriptor createAndTranslateForeignDescriptor(Binding binding)