org.glassfish.jersey.internal.inject
Class Providers

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

public class Providers
extends 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), Miroslav Fuksa (miroslav.fuksa at oracle.com)

Method Summary
static boolean checkProviderRuntime(Class<?> component, ContractProvider model, RuntimeType runtimeConstraint, boolean scanned, boolean isResource)
          Check the component whether it is appropriate correctly configured for client or server runtime.
static
<T> org.glassfish.hk2.api.Factory<T>
factoryOf(T instance)
          Wrap an instance into a HK2 service factory.
static
<T> Iterable<T>
getAllProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract)
          Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.
static
<T> Iterable<T>
getAllProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract, Comparator<T> comparator)
          Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container ordered based on the given comparator.
static
<T> Iterable<T>
getAllProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract, RankedComparator<T> comparator)
          Get the sorted iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.
static
<T> Iterable<RankedProvider<T>>
getAllRankedProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract)
          Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.
static
<T> Set<T>
getCustomProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract)
          Get the set of all custom providers registered for the given service provider contract in the underlying HK2 service locator container.
static Set<Class<?>> getProviderContracts(Class<?> clazz)
          Returns provider contracts recognized by Jersey that are implemented by the clazz.
static
<T> Set<T>
getProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract)
          Get the set of default providers registered for the given service provider contract in the underlying HK2 service locator container.
static
<T> SortedSet<T>
getProviders(org.glassfish.hk2.api.ServiceLocator locator, Class<T> contract, Comparator<T> comparator)
          Get the set of all providers registered for the given service provider contract in the underlying HK2 locator container.
static boolean isJaxRsProvider(Class<?> clazz)
          Returns true if given component class is a JAX-RS provider.
static boolean isProvider(Class<?> clazz)
          Returns true if the given component class is a provider (implements specific interfaces).
static boolean isSupportedContract(Class<?> type)
          Check if the given Java type is a Jersey-supported contract.
static
<T> Iterable<T>
sortRankedProviders(RankedComparator<T> comparator, Iterable<RankedProvider<T>>... providerIterables)
          Sorts given providers with ranked comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

factoryOf

public static <T> org.glassfish.hk2.api.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.

getProviders

public static <T> Set<T> getProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                      Class<T> contract)
Get the set of default providers registered for the given service provider contract in the underlying HK2 service locator container.

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

getCustomProviders

public static <T> Set<T> getCustomProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                            Class<T> contract)
Get the set of all custom providers registered for the given service provider contract in the underlying HK2 service locator container.

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

getAllProviders

public static <T> Iterable<T> getAllProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                              Class<T> contract)
Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.

Type Parameters:
T - service provider contract Java type.
Parameters:
locator - underlying HK2 service locator.
contract - service provider contract.
Returns:
iterable of all available service provider instances for the contract. Return value is never null.

getAllRankedProviders

public static <T> Iterable<RankedProvider<T>> getAllRankedProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                                                    Class<T> contract)
Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.

Type Parameters:
T - service provider contract Java type.
Parameters:
locator - underlying HK2 service locator.
contract - service provider contract.
Returns:
iterable of all available ranked service providers for the contract. Return value is never null.

sortRankedProviders

public static <T> Iterable<T> sortRankedProviders(RankedComparator<T> comparator,
                                                  Iterable<RankedProvider<T>>... providerIterables)
Sorts given providers with ranked comparator.

Type Parameters:
T - service provider contract Java type.
Parameters:
comparator - comparator to sort the providers with.
providerIterables - providers to be sorted.
Returns:
sorted iterable instance containing given providers. Return value is never null.

getAllProviders

public static <T> Iterable<T> getAllProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                              Class<T> contract,
                                              RankedComparator<T> comparator)
Get the sorted iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container.

Type Parameters:
T - service provider contract Java type.
Parameters:
locator - underlying HK2 service locator.
contract - service provider contract.
comparator - comparator to sort the providers with.
Returns:
set of all available ranked service providers for the contract. Return value is never null.

getAllProviders

public static <T> Iterable<T> getAllProviders(org.glassfish.hk2.api.ServiceLocator locator,
                                              Class<T> contract,
                                              Comparator<T> comparator)
Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlying HK2 service locator container ordered based on the given comparator.

Type Parameters:
T - service provider contract Java type.
Parameters:
locator - underlying HK2 service locator.
contract - service provider contract.
comparator - comparator to be used for sorting the returned providers.
Returns:
set of all available service provider instances for the contract ordered using the given comparator.

getProviders

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

Type Parameters:
T - service provider contract Java type.
Parameters:
locator - underlying HK2 service locator.
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.

getProviderContracts

public static Set<Class<?>> getProviderContracts(Class<?> clazz)
Returns provider contracts recognized by Jersey that are implemented by the clazz. Recognized provider contracts include all JAX-RS providers as well as all Jersey SPI components annotated with @Contract annotation.

Parameters:
clazz - class to extract the provider interfaces from.
Returns:
set of provider contracts implemented by the given class.

checkProviderRuntime

public static boolean checkProviderRuntime(Class<?> component,
                                           ContractProvider model,
                                           RuntimeType runtimeConstraint,
                                           boolean scanned,
                                           boolean isResource)
Check the component whether it is appropriate correctly configured for client or server runtime. If a problem occurs a warning is logged and if the component is not usable at all in the current runtime false is returned. For classes found during component scanning (scanned=true) certain warnings are completely ignored (e.g. components constrained to the client runtime and found by server-side class path scanning will be silently ignored and no warning will be logged).

Parameters:
component - the class of the component being checked.
model - model of the component.
runtimeConstraint - current runtime (client or server).
scanned - false if the component type has been registered explicitly; true if the class has been discovered during any form of component scanning.
isResource - true if the component is also a resource class.
Returns:
true if component is acceptable for use in the given runtime type, false otherwise.

isSupportedContract

public static boolean isSupportedContract(Class<?> type)
Check if the given Java type is a Jersey-supported contract.

Parameters:
type - contract type.
Returns:
true if given type is a Jersey-supported contract, false otherwise.

isProvider

public static boolean isProvider(Class<?> clazz)
Returns true if the given component class is a provider (implements specific interfaces). See getProviderContracts(java.lang.Class).

Parameters:
clazz - class to test.
Returns:
true if the class is provider, false otherwise.

isJaxRsProvider

public static boolean isJaxRsProvider(Class<?> clazz)
Returns true if given component class is a JAX-RS provider.

Parameters:
clazz - class to check.
Returns:
true if the class is a JAX-RS provider, false otherwise.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.