public abstract class ServiceLocatorUtilities
extends java.lang.Object
ServiceLocator
.Constructor and Description |
---|
ServiceLocatorUtilities() |
Modifier and Type | Method and Description |
---|---|
static <T> ActiveDescriptor<T> |
addOneConstant(ServiceLocator locator,
java.lang.Object constant)
This method adds one existing object to the given service locator.
|
static <T> ActiveDescriptor<T> |
addOneConstant(ServiceLocator locator,
java.lang.Object constant,
java.lang.String name,
java.lang.reflect.Type... contracts)
This method adds one existing object to the given service locator.
|
static <T> ActiveDescriptor<T> |
addOneDescriptor(ServiceLocator locator,
Descriptor descriptor)
It is very often the case that one wishes to add a single descriptor to
a service locator.
|
static <T> ActiveDescriptor<T> |
addOneDescriptor(ServiceLocator locator,
Descriptor descriptor,
boolean requiresDeepCopy)
It is very often the case that one wishes to add a single descriptor to
a service locator.
|
static ServiceLocator |
bind(Binder... binders)
This method will create or find a ServiceLocator with the name "default" and
bind all of the binders given together in a single config transaction.
|
static void |
bind(ServiceLocator locator,
Binder... binders)
This method will bind all of the binders given together in a
single config transaction.
|
static ServiceLocator |
bind(java.lang.String name,
Binder... binders)
This method will create or find a ServiceLocator with the given name and
bind all of the binders given together in a single config transaction.
|
static DynamicConfiguration |
createDynamicConfiguration(ServiceLocator locator)
This method returns a
DynamicConfiguration for use with adding
and removing services to the given ServiceLocator . |
static void |
enablePerThreadScope(ServiceLocator locator)
This method will add the ability to use the
PerThread scope to
the given locator. |
static <T> ActiveDescriptor<T> |
findOneDescriptor(ServiceLocator locator,
Descriptor descriptor)
Finds a descriptor in the given service locator.
|
static <T> T |
findOrCreateService(ServiceLocator locator,
java.lang.Class<T> type,
java.lang.annotation.Annotation... qualifiers)
This method will first attempt to find a service corresponding to the type and qualifiers
passed in to the method, and if one is found simply returns it.
|
static java.lang.String |
getOneMetadataField(Descriptor d,
java.lang.String field)
Gets one value from a metadata field from the given descriptor
|
static java.lang.String |
getOneMetadataField(ServiceHandle<?> h,
java.lang.String field)
Gets one value from a metadata field from the given service handle
|
static <T> T |
getService(ServiceLocator locator,
Descriptor descriptor)
Returns the service in this service locator given the current descriptor.
|
static <T> T |
getService(ServiceLocator locator,
java.lang.String className)
Returns the best service matching the passed in fully qualified
class name of the service
|
static void |
removeFilter(ServiceLocator locator,
Filter filter)
Removes all the descriptors from the given locator that match the
given filter
|
static void |
removeOneDescriptor(ServiceLocator locator,
Descriptor descriptor)
This method will attempt to remove descriptors matching the passed in descriptor from
the given locator.
|
public static void enablePerThreadScope(ServiceLocator locator)
PerThread
scope to
the given locator. If the locator already has a Context
implementation
that handles the PerThread
scope this method does nothing.locator
- The non-null locator to enable the PerThread scope onMultiException
- if there were errors when committing the servicepublic static void bind(ServiceLocator locator, Binder... binders)
locator
- The non-null locator to use for the configuration actionbinders
- The non-null list of binders to be added to the locatorMultiException
- if any error was encountered while binding servicespublic static ServiceLocator bind(java.lang.String name, Binder... binders)
name
- The non-null name of the locator to use for the configuration actionbinders
- The non-null list of binders to be added to the locatorMultiException
- if any error was encountered while binding servicespublic static ServiceLocator bind(Binder... binders)
binders
- The non-null list of binders to be added to the locatorMultiException
- if any error was encountered while binding servicespublic static <T> ActiveDescriptor<T> addOneConstant(ServiceLocator locator, java.lang.Object constant)
BuilderHelper.createConstantDescriptor(Object)
method.locator
- The non-null locator to add this descriptor toconstant
- The non-null constant to add to the service locatorpublic static <T> ActiveDescriptor<T> addOneConstant(ServiceLocator locator, java.lang.Object constant, java.lang.String name, java.lang.reflect.Type... contracts)
BuilderHelper.createConstantDescriptor(Object)
method.locator
- The non-null locator to add this descriptor toconstant
- The non-null constant to add to the service locatorname
- The name this descriptor should take (may be null)contracts
- The full set of contracts this descriptor should takepublic static <T> ActiveDescriptor<T> addOneDescriptor(ServiceLocator locator, Descriptor descriptor)
ActiveDescriptor
and is reified, it will be added as an
ActiveDescriptor
. Otherwise it will be bound as a Descriptor
.
A deep copy will be made of the descriptor passed inlocator
- The non-null locator to add this descriptor todescriptor
- The non-null descriptor to add to this locatorMultiException
- On a commit failurepublic static <T> ActiveDescriptor<T> addOneDescriptor(ServiceLocator locator, Descriptor descriptor, boolean requiresDeepCopy)
ActiveDescriptor
and is reified, it will be added as an
ActiveDescriptor
. Otherwise it will be bound as a Descriptor
.locator
- The non-null locator to add this descriptor todescriptor
- The non-null descriptor to add to this locatorrequiresDeepCopy
- If true a deep copy will be made of the
key. If false then the Descriptor will be used as is, and it
is the responsibility of the caller to ensure that the fields
of the Descriptor never change (with the exception of any
writeable fields, such as ranking)MultiException
- On a commit failurepublic static <T> ActiveDescriptor<T> findOneDescriptor(ServiceLocator locator, Descriptor descriptor)
locator
- The non-null locator in which to find the descriptordescriptor
- The non-null descriptor to search forpublic static void removeOneDescriptor(ServiceLocator locator, Descriptor descriptor)
DescriptorImpl.equals(Object)
method
will be removed from the locator. Note that if more than one descriptor matches they
will all be removed. Hence more than one descriptor may be removed by this method.locator
- The non-null locator to remove the descriptor fromdescriptor
- The non-null descriptor to remove from the locatorpublic static void removeFilter(ServiceLocator locator, Filter filter)
locator
- The non-null locator to remove the descriptors fromfilter
- The non-null filter which will determine what descriptors to removepublic static <T> T getService(ServiceLocator locator, java.lang.String className)
locator
- The locator to find the service inclassName
- The fully qualified class name of the servicepublic static <T> T getService(ServiceLocator locator, Descriptor descriptor)
locator
- The non-null locator in which to get the service associated with
this descriptordescriptor
- The non-null descriptor to find the corresponding service forpublic static DynamicConfiguration createDynamicConfiguration(ServiceLocator locator) throws java.lang.IllegalStateException
DynamicConfiguration
for use with adding
and removing services to the given ServiceLocator
.locator
- A non-null locator to get a DynamicConfiguration forjava.lang.IllegalStateException
- If there was an error retrieving the
DynamicConfigurationService
for this locatorpublic static <T> T findOrCreateService(ServiceLocator locator, java.lang.Class<T> type, java.lang.annotation.Annotation... qualifiers) throws MultiException
ServiceLocator.createAndInitialize(Class)
on
the class (ignoring the qualifiers) in order to create an instance of the service.locator
- The service locator to search for the service withtype
- The non-null type of object to either find or createqualifiers
- The set of qualifiers that should be associated with the serviceMultiException
- On a failure from any of the underlying operationspublic static java.lang.String getOneMetadataField(Descriptor d, java.lang.String field)
d
- The non-null descriptor from which to get the first value in the given fieldfield
- The non-null field to get the first value ofpublic static java.lang.String getOneMetadataField(ServiceHandle<?> h, java.lang.String field)
h
- The non-null service handle from which to get the first value in the given fieldfield
- The non-null field to get the first value ofCopyright © 2013 Oracle Corporation. All Rights Reserved.