org.glassfish.hk2.utilities
Class ServiceLocatorUtilities

java.lang.Object
  extended by org.glassfish.hk2.utilities.ServiceLocatorUtilities

public abstract class ServiceLocatorUtilities
extends Object

This is a set of useful utilities for working with ServiceLocator.

Author:
jwells

Constructor Summary
ServiceLocatorUtilities()
           
 
Method Summary
static ActiveDescriptor<?> addOneDescriptor(ServiceLocator locator, Descriptor descriptor)
          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(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 void enablePerThreadScope(ServiceLocator locator)
          This method will add the ability to use the PerThread scope to the given locator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceLocatorUtilities

public ServiceLocatorUtilities()
Method Detail

enablePerThreadScope

public static void enablePerThreadScope(ServiceLocator locator)
This method will add the ability to use the PerThread scope to the given locator. If the locator already has a Context implementation that handles the PerThread scope this method does nothing.

Parameters:
locator - The non-null locator to enable the PerThread scope on
Throws:
MultiException - if there were errors when committing the service

bind

public static void bind(ServiceLocator locator,
                        Binder... binders)
This method will bind all of the binders given together in a single config transaction.

Parameters:
locator - The non-null locator to use for the configuration action
binders - The non-null list of binders to be added to the locator
Throws:
MultiException - if any error was encountered while binding services

bind

public static ServiceLocator bind(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.

Parameters:
name - The non-null name of the locator to use for the configuration action
binders - The non-null list of binders to be added to the locator
Returns:
The service locator that was either found or created
Throws:
MultiException - if any error was encountered while binding services

bind

public 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.

Parameters:
binders - The non-null list of binders to be added to the locator
Returns:
The service locator that was either found or created
Throws:
MultiException - if any error was encountered while binding services

addOneDescriptor

public static ActiveDescriptor<?> addOneDescriptor(ServiceLocator locator,
                                                   Descriptor descriptor)
It is very often the case that one wishes to add a single descriptor to a service locator. This method adds that one descriptor. If the descriptor is an ActiveDescriptor and is reified, it will be added as an ActiveDescriptor. Otherwise it will be bound as a Descriptor.

Parameters:
locator - The non-null locator to add this descriptor to
descriptor - The non-null descriptor to add to this locator
Throws:
MultiException - On a commit failure


Copyright © 2013 Oracle Corporation. All Rights Reserved.