org.glassfish.jersey.internal.inject
Class Providers

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

public class Providers
extends java.lang.Object

Utility class providing a set of utility methods for easier and more type-safe interaction with HK2 injection layer.

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

Method Summary
static
<T> org.glassfish.hk2.Factory<T>
asFactory(org.glassfish.hk2.Provider<T> provider)
          Wrap HK2 service provider into a HK2 service factory.
static java.lang.String contractStringFor(java.lang.Class<?> rawType, java.lang.reflect.Type... types)
          Build a string definition for a generic contract.
static
<T> org.glassfish.hk2.Factory<T>
factoryOf(T instance)
          Wrap an instance into a HK2 service factory.
static
<T> T
getContract(org.glassfish.hk2.Services services, java.lang.String contract)
          Get a typed service instance for a contract specified as a string.
static
<T> org.glassfish.hk2.Factory<T>
getFactory(org.glassfish.hk2.Services services, java.lang.String contract)
          Get a typed HK2 service factory for a contract specified as string.
static
<T> org.glassfish.hk2.Provider<T>
getProvider(org.glassfish.hk2.Services services, java.lang.String contract)
          Get a typed HK2 service provider for a contract specified as string.
static
<T> java.util.Set<T>
getProviderFactories(org.glassfish.hk2.Services services, java.lang.Class<T> contract)
          Get the set of HK2 factories for all providers registered for the given service provider contract in the underlying HK2 services container.
static
<T> java.util.Set<T>
getProviders(org.glassfish.hk2.Services services, java.lang.Class<T> contract)
          Get the set of all providers registered for the given service provider contract in the underlying HK2 services container.
static
<T> java.util.SortedSet<T>
getProviders(org.glassfish.hk2.Services services, java.lang.Class<T> contract, java.util.Comparator<T> comparator)
          Get the set of all providers registered for the given service provider contract in the underlying HK2 services container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asFactory

public static <T> org.glassfish.hk2.Factory<T> asFactory(org.glassfish.hk2.Provider<T> provider)
Wrap HK2 service provider into a HK2 service factory.

Type Parameters:
T - Java type if the contract produced by the provider and factory.
Parameters:
provider - HK2 service provider to be wrapped.
Returns:
HK2 service factory wrapping the HK2 service provider.

factoryOf

public static <T> org.glassfish.hk2.Factory<T> factoryOf(T instance)
Wrap an instance into a HK2 service factory.

Type Parameters:
T - Java type if the contract produced by the provider and factory.
Parameters:
instance - instance to be wrapped into (and provided by) the factory.
Returns:
HK2 service factory wrapping and providing the instance.

contractStringFor

public static java.lang.String contractStringFor(java.lang.Class<?> rawType,
                                                 java.lang.reflect.Type... types)
Build a string definition for a generic contract.

Parameters:
rawType - raw generic type.
types - actual generic type arguments.
Returns:
string definition for a generic contract.

getContract

public static <T> T getContract(org.glassfish.hk2.Services services,
                                java.lang.String contract)
Get a typed service instance for a contract specified as a string.

Type Parameters:
T - expected contract type.
Parameters:
services - HK2 services.
contract - string definition of the contract Java type.
Returns:
typed service instance for the contract.

getProvider

public static <T> org.glassfish.hk2.Provider<T> getProvider(org.glassfish.hk2.Services services,
                                                            java.lang.String contract)
Get a typed HK2 service provider for a contract specified as string.

Type Parameters:
T - expected contract type.
Parameters:
services - HK2 services.
contract - string definition of the contract Java type.
Returns:
typed HK2 service provider for the contract.

getFactory

public static <T> org.glassfish.hk2.Factory<T> getFactory(org.glassfish.hk2.Services services,
                                                          java.lang.String contract)
Get a typed HK2 service factory for a contract specified as string.

Type Parameters:
T - expected contract type.
Parameters:
services - HK2 services.
contract - string definition of the contract Java type.
Returns:
typed HK2 service factory for the contract.

getProviders

public static <T> java.util.Set<T> getProviders(org.glassfish.hk2.Services services,
                                                java.lang.Class<T> contract)
Get the set of all providers registered for the given service provider contract in the underlying HK2 services container.

Type Parameters:
T - service provider contract Java type.
Parameters:
services - underlying HK2 services container.
contract - service provider contract.
Returns:
set of all available service provider instances for the contract.

getProviders

public static <T> java.util.SortedSet<T> getProviders(org.glassfish.hk2.Services services,
                                                      java.lang.Class<T> contract,
                                                      java.util.Comparator<T> comparator)
Get the set of all providers registered for the given service provider contract in the underlying HK2 services container.

Type Parameters:
T - service provider contract Java type.
Parameters:
services - underlying HK2 services container.
contract - service provider contract.
comparator - contract comparator used for ordering contracts in the set.
Returns:
set of all available service provider instances for the contract.

getProviderFactories

public static <T> java.util.Set<T> getProviderFactories(org.glassfish.hk2.Services services,
                                                        java.lang.Class<T> contract)
Get the set of HK2 factories for all providers registered for the given service provider contract in the underlying HK2 services container.

Type Parameters:
T - service provider contract Java type.
Parameters:
services - underlying HK2 services container.
contract - service provider contract.
Returns:
set of factories for all available service provider instances for the contract.


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