Class AbstractHk2InjectionManager
- All Implemented Interfaces:
InjectionManager
- Direct Known Subclasses:
DelayedHk2InjectionManager,ImmediateHk2InjectionManager
InjectionManager providing several convenient methods.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidassertParentLocatorType(Object parent) Checks if the parent is null then must be an instance ofServiceLocatororInjectionManager.<U> UcreateAndInitialize(Class<U> clazz) Creates, injects and post-constructs an object with the given class.private ForeignDescriptorcreateForeignDescriptor(Binding binding) Creates and registers the descriptor in the underlying DI provider and returnsForeignDescriptorthat is specific descriptor for the underlying DI provider.private static org.glassfish.hk2.api.ServiceLocatorcreateLocator(org.glassfish.hk2.api.ServiceLocator parentLocator) Creates a newServiceLocatorinstance from staticServiceLocatorFactoryand adds the provided parent locator if the instance is not null.<T> List<T> getAllInstances(Type clazz) Gets all services from this injection manager that implement this contract or have this implementation.<T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, 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> TgetInstance(Class<T> clazz) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Class<T> clazz, Annotation... annotations) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Class<T> clazz, String classAnalyzer) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Type clazz) Gets the best service from this injection manager that implements this contract or has this implementation.getInstance(ForeignDescriptor foreignDescriptor) Gets the service instance according toForeignDescriptorwhich is specific to the underlying DI provider.org.glassfish.hk2.api.ServiceLocatorvoidAnalyzes the given object and inject into its fields and methods.voidThis will analyze the given object and inject into its fields and methods.booleanisRegistrable(Class<?> clazz) Tests whether the providedclazzcan be registered by the implementation of theInjectionManager.voidpreDestroy(Object preDestroyMe) Analyzes the given object and call the preDestroy method.private static org.glassfish.hk2.api.ServiceLocatorresolveServiceLocatorParent(Object parent) voidshutdown()Shuts down the entireInjectionManagerand the underlying DI provider.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.glassfish.jersey.internal.inject.InjectionManager
completeRegistration, register, register, register, register
-
Field Details
-
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 typeInjectionManagerorServiceLocator.
-
-
Method Details
-
createLocator
private static org.glassfish.hk2.api.ServiceLocator createLocator(org.glassfish.hk2.api.ServiceLocator parentLocator) Creates a newServiceLocatorinstance from staticServiceLocatorFactoryand adds the provided parent locator if the instance is not null.- Parameters:
parentLocator- parent locator, can benull.- Returns:
- new instance of injection manager.
-
resolveServiceLocatorParent
-
assertParentLocatorType
Checks if the parent is null then must be an instance ofServiceLocatororInjectionManager.- Parameters:
parent- object represented byServiceLocatororHK2InjectionManager.
-
getServiceLocator
public org.glassfish.hk2.api.ServiceLocator getServiceLocator() -
isRegistrable
Description copied from interface:InjectionManagerTests whether the providedclazzcan be registered by the implementation of theInjectionManager.- Specified by:
isRegistrablein interfaceInjectionManager- Parameters:
clazz- type that is tested whether is registrable by the implementation ofInjectionManager.- Returns:
trueif theInjectionManageris able to register this type.
-
getAllServiceHolders
Description copied from interface:InjectionManagerGets 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:
getAllServiceHoldersin 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
Description copied from interface:InjectionManagerGets 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:
getInstancein 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
Description copied from interface:InjectionManagerGets 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:
getInstancein 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
Description copied from interface:InjectionManagerGets the service instance according toForeignDescriptorwhich is specific to the underlying DI provider.- Specified by:
getInstancein interfaceInjectionManager- Parameters:
foreignDescriptor- DI specific descriptor.- Returns:
- service instance according to foreign descriptor.
-
getInstance
Description copied from interface:InjectionManagerGets 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:
getInstancein 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
Description copied from interface:InjectionManagerGets 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:
getInstancein 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
Description copied from interface:InjectionManagerGets 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:
getAllInstancesin 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
Description copied from interface:InjectionManagerAnalyzes the given object and call the preDestroy method. The object given will not be managed by bean manager.- Specified by:
preDestroyin interfaceInjectionManager- Parameters:
preDestroyMe- The object to preDestroy
-
shutdown
public void shutdown()Description copied from interface:InjectionManagerShuts down the entireInjectionManagerand the underlying DI provider.Shutdown phase is dedicated to make some final cleaning steps regarding underlying DI provider.
- Specified by:
shutdownin interfaceInjectionManager
-
createAndInitialize
Description copied from interface:InjectionManagerCreates, injects and post-constructs an object with the given class. This is equivalent to calling thecreate-classmethod followed by theinject-classmethod followed by thepost-constructmethod.The object created is not managed by the injection manager.
- Specified by:
createAndInitializein 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
Description copied from interface:InjectionManagerCreates and registers the descriptor in the underlying DI provider and returnsForeignDescriptorthat is specific descriptor for the underlying DI provider.- Specified by:
createForeignDescriptorin interfaceInjectionManager- Parameters:
binding- jersey descriptor.- Returns:
- specific foreign descriptor of the underlying DI provider.
-
inject
Description copied from interface:InjectionManagerAnalyzes the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2- Specified by:
injectin interfaceInjectionManager- Parameters:
injectMe- The object to be analyzed and injected into
-
inject
Description copied from interface:InjectionManagerThis 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:
injectin interfaceInjectionManager- Parameters:
injectMe- The object to be analyzed and injected into
-
createAndTranslateForeignDescriptor
-