org.glassfish.jersey.internal.inject
Class Injections

java.lang.Object
  extended by org.glassfish.jersey.internal.inject.Injections

public class Injections
extends Object

HK2 injection binding utility methods.

Author:
Tom Beerbower, Marek Potociar (marek.potociar at oracle.com)

Constructor Summary
Injections()
           
 
Method Summary
static void addBinding(BindingBuilder<?> builder, DynamicConfiguration configuration)
          Add a binding represented by the binding builder to the HK2 dynamic configuration.
static void addBinding(BindingBuilder<?> builder, DynamicConfiguration configuration, HK2Loader defaultLoader)
          Add a binding represented by the binding builder to the HK2 dynamic configuration.
static ServiceLocator createLocator(Binder... binders)
          Create an unnamed ServiceLocator.
static ServiceLocator createLocator(ServiceLocator parent, Binder... binders)
          Create an unnamed, parented ServiceLocator.
static ServiceLocator createLocator(String name, Binder... binders)
          Create a ServiceLocator.
static ServiceLocator createLocator(String name, ServiceLocator parent, Binder... binders)
          Create a ServiceLocator.
static DynamicConfiguration getConfiguration(ServiceLocator locator)
          Get service locator dynamic configuration.
static
<T> T
getOrCreate(ServiceLocator serviceLocator, Class<T> clazz)
          Get the class by contract or create and inject a new instance.
static
<T> ServiceBindingBuilder<T>
newBinder(Class<T> serviceType)
          Get a new class-based service binding builder.
static
<T> ScopedBindingBuilder<T>
newBinder(T service)
          Get a new instance-based service binding builder.
static
<T> ServiceBindingBuilder<T>
newFactoryBinder(Class<? extends Factory<T>> factoryType)
          Get a new factory class-based service binding builder.
static
<T> ServiceBindingBuilder<T>
newFactoryBinder(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope)
          Get a new factory class-based service binding builder.
static
<T> ServiceBindingBuilder<T>
newFactoryBinder(Factory<T> factory)
          Get a new factory instance-based service binding builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Injections

public Injections()
Method Detail

getConfiguration

public static DynamicConfiguration getConfiguration(ServiceLocator locator)
Get service locator dynamic configuration.

Parameters:
locator - HK2 service locator.
Returns:
dynamic configuration for a given service locator.

createLocator

public static ServiceLocator createLocator(String name,
                                           ServiceLocator parent,
                                           Binder... binders)
Create a ServiceLocator. In case the name is not specified, the locator will be unnamed.

Parameters:
name - The name of this service locator. Passing a null name will result in a newly created service locator with a generated name.
parent - The parent of this ServiceLocator. Services can be found in the parent (and all grand-parents). May be null. if the returned ServiceLocator should not be parented.
binders - custom the HK2 binders.
Returns:
a service locator with all the bindings.

createLocator

public static ServiceLocator createLocator(String name,
                                           Binder... binders)
Create a ServiceLocator. In case the name is not specified, the locator will be unnamed.

Parameters:
name - The name of this service locator. Passing a null name will result in a newly created service locator with a generated name.
binders - custom the HK2 binders.
Returns:
a service locator with all the bindings.

createLocator

public static ServiceLocator createLocator(ServiceLocator parent,
                                           Binder... binders)
Create an unnamed, parented ServiceLocator. In case the parent service locator is not specified, the locator will not be parented.

Parameters:
parent - The parent of this ServiceLocator. Services can be found in the parent (and all grand-parents). May be null. if the returned ServiceLocator should not be parented.
binders - custom the HK2 binders.
Returns:
a service locator with all the bindings.

createLocator

public static ServiceLocator createLocator(Binder... binders)
Create an unnamed ServiceLocator.

Parameters:
binders - custom the HK2 binders.
Returns:
a service locator with all the bindings.

getOrCreate

public static <T> T getOrCreate(ServiceLocator serviceLocator,
                                Class<T> clazz)
Get the class by contract or create and inject a new instance.

Type Parameters:
T - instance type.
Parameters:
serviceLocator - HK2 service locator.
clazz - class of the instance to be provider.
Returns:
instance of the class either provided as a service or created and injected by HK2.

addBinding

public static void addBinding(BindingBuilder<?> builder,
                              DynamicConfiguration configuration)
Add a binding represented by the binding builder to the HK2 dynamic configuration.

Parameters:
builder - binding builder.
configuration - HK2 dynamic configuration.

addBinding

public static void addBinding(BindingBuilder<?> builder,
                              DynamicConfiguration configuration,
                              HK2Loader defaultLoader)
Add a binding represented by the binding builder to the HK2 dynamic configuration.

Parameters:
builder - binding builder.
configuration - HK2 dynamic configuration.
defaultLoader - default HK2 service loader that should be used to load the service class in case a custom loader has not been set.

newFactoryBinder

public static <T> ServiceBindingBuilder<T> newFactoryBinder(Class<? extends Factory<T>> factoryType,
                                                            Class<? extends Annotation> factoryScope)
Get a new factory class-based service binding builder.

Type Parameters:
T - service type.
Parameters:
factoryType - service factory class.
factoryScope - factory scope.
Returns:
initialized binding builder.

newFactoryBinder

public static <T> ServiceBindingBuilder<T> newFactoryBinder(Class<? extends Factory<T>> factoryType)
Get a new factory class-based service binding builder. The factory itself is bound in a per-lookup scope.

Type Parameters:
T - service type.
Parameters:
factoryType - service factory class.
Returns:
initialized binding builder.

newFactoryBinder

public static <T> ServiceBindingBuilder<T> newFactoryBinder(Factory<T> factory)
Get a new factory instance-based service binding builder.

Type Parameters:
T - service type.
Parameters:
factory - service instance.
Returns:
initialized binding builder.

newBinder

public static <T> ServiceBindingBuilder<T> newBinder(Class<T> serviceType)
Get a new class-based service binding builder. Does NOT bind the service type itself as a contract type.

Type Parameters:
T - service type.
Parameters:
serviceType - service class.
Returns:
initialized binding builder.

newBinder

public static <T> ScopedBindingBuilder<T> newBinder(T service)
Get a new instance-based service binding builder. The binding is naturally considered to be a singleton-scoped. Does NOT bind the service type itself as a contract type.

Type Parameters:
T - service type.
Parameters:
service - service instance.
Returns:
initialized binding builder.


Copyright © 2007-2013 Oracle Corporation. All Rights Reserved. Use is subject to license terms.