@Contract public interface ServiceLocator
Services can be looked up from this instance
Modifier and Type | Method and Description |
---|---|
<T> T |
create(java.lang.Class<T> createMe)
This method will analyze the given class, and create it if can.
|
<T> T |
create(java.lang.Class<T> createMe,
java.lang.String strategy)
This method will analyze the given class, and create it if can.
|
<U> U |
createAndInitialize(java.lang.Class<U> createMe)
This method creates, injects and post-constructs an object with the given
class.
|
<U> U |
createAndInitialize(java.lang.Class<U> createMe,
java.lang.String strategy)
This method creates, injects and post-constructs an object with the given
class.
|
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(java.lang.annotation.Annotation qualifier,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
<T> java.util.List<ServiceHandle<T>> |
getAllServiceHandles(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(Filter searchCriteria)
Gets a list of
ServiceHandle whose ActiveDescriptor s match
the supplied filter. |
java.util.List<ServiceHandle<?>> |
getAllServiceHandles(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a list of
ServiceHandle that can be used to get and destroy services
associated with descriptors that match the provided criteria |
<T> java.util.List<T> |
getAllServices(java.lang.annotation.Annotation qualifier,
java.lang.annotation.Annotation... qualifiers)
Gets the all the services from this locator that has the given
qualifier or qualifiers
|
<T> java.util.List<T> |
getAllServices(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the all the services from this locator that implements
this contract or has this implementation
|
java.util.List<?> |
getAllServices(Filter searchCriteria)
Gets the all the services from this locator that matches the
Filter |
<T> java.util.List<T> |
getAllServices(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the all the services from this locator that implements
this contract or has this implementation
|
ActiveDescriptor<?> |
getBestDescriptor(Filter filter)
Gets the descriptor that best matches this filter, taking ranking
and service id into account
|
java.lang.String |
getDefaultClassAnalyzerName()
Gets the name of the default class analyzer service
|
java.util.List<ActiveDescriptor<?>> |
getDescriptors(Filter filter)
Gets the list of descriptors that match the given filter
|
ActiveDescriptor<?> |
getInjecteeDescriptor(Injectee injectee)
This method will first find a descriptor for this injectee, and then
reify that descriptor.
|
long |
getLocatorId()
This returns the unique locator ID for this locator.
|
java.lang.String |
getName()
Returns the name of this ServiceLocator
|
<T> T |
getService(ActiveDescriptor<T> activeDescriptor,
ServiceHandle<?> root)
Deprecated.
|
<T> T |
getService(ActiveDescriptor<T> activeDescriptor,
ServiceHandle<?> root,
Injectee injectee)
This method should be called by code resolving injectee's on behalf of some
root service, usually by an implementation of
InjectionResolver.resolve(Injectee, ServiceHandle) . |
<T> T |
getService(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation
|
<T> T |
getService(java.lang.Class<T> contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation and has the given
name
|
<T> T |
getService(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation
|
<T> T |
getService(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets the best service from this locator that implements
this contract or has this implementation and has the given
name
|
<T> ServiceHandle<T> |
getServiceHandle(ActiveDescriptor<T> activeDescriptor)
Gets a
ServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor . |
<T> ServiceHandle<T> |
getServiceHandle(ActiveDescriptor<T> activeDescriptor,
Injectee injectee)
Gets a
ServiceHandle that can be used to get and destroy the service
described by the ActiveDescriptor . |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.Class<T> contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.Class<T> contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.reflect.Type contractOrImpl,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
<T> ServiceHandle<T> |
getServiceHandle(java.lang.reflect.Type contractOrImpl,
java.lang.String name,
java.lang.annotation.Annotation... qualifiers)
Gets a
ServiceHandle that can be used to get and destroy the
service that best matches the given criteria |
ServiceLocatorState |
getState()
Returns the current state of this service locator.
|
void |
inject(java.lang.Object injectMe)
This will analyze the given object and inject into its fields and methods.
|
void |
inject(java.lang.Object injectMe,
java.lang.String strategy)
This will analyze the given object and inject into its fields and methods.
|
void |
postConstruct(java.lang.Object postConstructMe)
This will analyze the given object and call the postConstruct method.
|
void |
postConstruct(java.lang.Object postConstructMe,
java.lang.String strategy)
This will analyze the given object and call the postConstruct method.
|
void |
preDestroy(java.lang.Object preDestroyMe)
This will analyze the given object and call the preDestroy method.
|
void |
preDestroy(java.lang.Object preDestroyMe,
java.lang.String strategy)
This will analyze the given object and call the preDestroy method.
|
ActiveDescriptor<?> |
reifyDescriptor(Descriptor descriptor)
Converts a descriptor to an ActiveDescriptor.
|
ActiveDescriptor<?> |
reifyDescriptor(Descriptor descriptor,
Injectee injectee)
Converts a descriptor to an ActiveDescriptor.
|
void |
setDefaultClassAnalyzerName(java.lang.String defaultClassAnalyzer)
Sets the name of the default class analyzer that should be used for all
Descriptor s that return null as their class analyzer. |
void |
shutdown()
This method will shutdown every service associated with this ServiceLocator.
|
<T> T getService(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> T getService(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> T getService(java.lang.Class<T> contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofname
- May be null (to indicate any name is ok), and is the name of the
implementation to be returnedqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> T getService(java.lang.reflect.Type contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofname
- May be null (to indicate any name is ok), and is the name of the
implementation to be returnedqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> java.util.List<T> getAllServices(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> java.util.List<T> getAllServices(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the service is not important
contractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> java.util.List<T> getAllServices(java.lang.annotation.Annotation qualifier, java.lang.annotation.Annotation... qualifiers) throws MultiException
Use this method only if destroying the services is not important
qualifier
- May not be null, and is a qualifier that must
match the service definitionqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.util.List<?> getAllServices(Filter searchCriteria) throws MultiException
Filter
Use this method only if destroying the service is not important
This method should also be used with care to avoid classloading a large number of services
searchCriteria
- The returned service will match the Filter
(in other words, searchCriteria.matches returns true). May not
be nullMultiException
- if there was an error during service creation<T> ServiceHandle<T> getServiceHandle(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy the
service that best matches the given criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> ServiceHandle<T> getServiceHandle(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy the
service that best matches the given criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creation<T> ServiceHandle<T> getServiceHandle(java.lang.Class<T> contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy the
service that best matches the given criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofname
- The name to use to further qualify the search (may be null,
indicating that any name will match)qualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.lang.IllegalArgumentException
- if contractOrImpl is null<T> ServiceHandle<T> getServiceHandle(java.lang.reflect.Type contractOrImpl, java.lang.String name, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy the
service that best matches the given criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofname
- The name to use to further qualify the search (may be null,
indicating that any name will match)qualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.lang.IllegalArgumentException
- if contractOrImpl is null<T> java.util.List<ServiceHandle<T>> getAllServiceHandles(java.lang.Class<T> contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy services
associated with descriptors that match the provided criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.lang.IllegalArgumentException
- if contractOrImpl is nulljava.util.List<ServiceHandle<?>> getAllServiceHandles(java.lang.reflect.Type contractOrImpl, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy services
associated with descriptors that match the provided criteriacontractOrImpl
- May not be null, and is the contract
or concrete implementation to get the best instance ofqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.lang.IllegalArgumentException
- if contractOrImpl is nulljava.util.List<ServiceHandle<?>> getAllServiceHandles(java.lang.annotation.Annotation qualifier, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceHandle
that can be used to get and destroy services
associated with descriptors that match the provided criteriaqualifier
- May not be null, and is a qualifier that must
match the service definitionqualifiers
- The set of qualifiers that must match this service
definitionMultiException
- if there was an error during service creationjava.lang.IllegalArgumentException
- if contractOrImpl is nulljava.util.List<ServiceHandle<?>> getAllServiceHandles(Filter searchCriteria) throws MultiException
ServiceHandle
whose ActiveDescriptor
s match
the supplied filter. The returned ServiceHandle
s may be used to
get or destroy the services associated with the matching descriptorssearchCriteria
- A filter to use when determining which descriptors should applyMultiException
- if there was an error during service handle creationjava.util.List<ActiveDescriptor<?>> getDescriptors(Filter filter)
filter
- A filter to use when determining which services should applyActiveDescriptor<?> getBestDescriptor(Filter filter)
filter
- The non-null filter to use to retrieve the best descriptorActiveDescriptor<?> reifyDescriptor(Descriptor descriptor, Injectee injectee) throws MultiException
descriptor
- The descriptor to convert, may not be nullinjectee
- The injectee on behalf of whom this descriptor is being injected. May
be null if the injectee is unknownHK2Loader
MultiException
- if there were errors when loading or analyzing the classActiveDescriptor<?> reifyDescriptor(Descriptor descriptor) throws MultiException
descriptor
- The descriptor to convert, may not be nullHK2Loader
MultiException
- if there were errors when loading or analyzing the classActiveDescriptor<?> getInjecteeDescriptor(Injectee injectee) throws MultiException
This method is responsible for using the available JustInTimeResolver
to add in new descriptors should the descriptor for the given Injectee
not be found initially
injectee
- the injection point for whom to find the ActiveDescriptorMultiException
- if there were errors when loading or analyzing the class<T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException
ServiceHandle
that can be used to get and destroy the service
described by the ActiveDescriptor
. The injectee may be used to discover
the proper classloader to use when attempting to reify the ActiveDescriptor
activeDescriptor
- The descriptor for which to create a ServiceHandle
.
May not be nullinjectee
- The injectee on behalf of whom this service is being injected. May
be null if the injectee is unknownServiceHandle
that may be used to create or destroy the service
associated with this ActiveDescriptor
MultiException
- if there was an error during service handle creation<T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor) throws MultiException
ServiceHandle
that can be used to get and destroy the service
described by the ActiveDescriptor
.activeDescriptor
- The descriptor for which to create a ServiceHandle
.
May not be nullServiceHandle
that may be used to create or destroy the service
associated with this ActiveDescriptor
MultiException
- if there was an error during service handle creation@Deprecated <T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root) throws MultiException
getService(ActiveDescriptor, ServiceHandle, Injectee)
InjectionResolver.resolve(Injectee, ServiceHandle)
. In
this way the objects associated with the root object can be destroyed in the proper sequenceactiveDescriptor
- The descriptor whose service to createroot
- The ultimate parent of this service creation. May be nullMultiException
- if there was an error during service creation<T> T getService(ActiveDescriptor<T> activeDescriptor, ServiceHandle<?> root, Injectee injectee) throws MultiException
InjectionResolver.resolve(Injectee, ServiceHandle)
. In
this way the objects associated with the root object can be destroyed in the proper sequenceactiveDescriptor
- The descriptor whose service to createroot
- The ultimate parent of this service creation. May be nullinjectee
- The injectee passed into the InjectionResolver.resolve(Injectee, ServiceHandle)
if known,
null otherwiseMultiException
- if there was an error during service creationjava.lang.String getDefaultClassAnalyzerName()
void setDefaultClassAnalyzerName(java.lang.String defaultClassAnalyzer)
Descriptor
s that return null as their class analyzer. If null is given
then the default class analyzer name of ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME
will be useddefaultClassAnalyzer
- The possibly null name of the default class
analyzer (the class analyzer that will be used if a descriptor has not
explicitly set the name of its class analyzer)java.lang.String getName()
long getLocatorId()
void shutdown()
ServiceLocatorState getState()
<T> T create(java.lang.Class<T> createMe)
createMe
- The class to create, may not be null<T> T create(java.lang.Class<T> createMe, java.lang.String strategy)
createMe
- The class to create, may not be nullstrategy
- The name of the ClassAnalyzer
that should be used. If
null the default analyzer will be usedvoid inject(java.lang.Object injectMe)
injectMe
- The object to be analyzed and injected intovoid inject(java.lang.Object injectMe, java.lang.String strategy)
injectMe
- The object to be analyzed and injected intostrategy
- The name of the ClassAnalyzer
that should be used. If
null the default analyzer will be usedvoid postConstruct(java.lang.Object postConstructMe)
postConstructMe
- The object to postConstructvoid postConstruct(java.lang.Object postConstructMe, java.lang.String strategy)
postConstructMe
- The object to postConstructstrategy
- The name of the ClassAnalyzer
that should be used. If
null the default analyzer will be usedvoid preDestroy(java.lang.Object preDestroyMe)
preDestroyMe
- The object to preDestroyvoid preDestroy(java.lang.Object preDestroyMe, java.lang.String strategy)
preDestroyMe
- The object to preDestroystrategy
- The name of the ClassAnalyzer
that should be used. If
null the default analyzer will be used<U> U createAndInitialize(java.lang.Class<U> createMe)
create(Class)
method followed by the inject(Object)
method followed
by the postConstruct(Object)
method.
The object created is not managed by the locator.
createMe
- The non-null class to create this object fromMultiException
- if there was an error when creating or initializing the object<U> U createAndInitialize(java.lang.Class<U> createMe, java.lang.String strategy)
create(Class)
method followed by the inject(Object)
method followed
by the postConstruct(Object)
method.
The object created is not managed by the locator.
createMe
- The non-null class to create this object fromstrategy
- The name of the ClassAnalyzer
that should be used. If
null the default analyzer will be usedMultiException
- if there was an error when creating or initializing the objectCopyright © 2013 Oracle Corporation. All Rights Reserved.