Class Providers
java.lang.Object
org.glassfish.jersey.internal.inject.Providers
Utility class providing a set of utility methods for easier and more type-safe
interaction with an injection layer.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<Class<?>, Providers.ProviderRuntime> Map of all supported external (i.e.private static final Map<Class<?>, Providers.ProviderRuntime> Map of all standard JAX-RS providers and their run-time affinity.private static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckProviderRuntime(Class<?> component, ContractProvider model, javax.ws.rs.RuntimeType runtimeConstraint, boolean scanned, boolean isResource) Check thecomponentwhether it is appropriate correctly configured for client or serverruntime.private static voidcomputeProviderContracts(Class<?> clazz, Set<Class<?>> contracts) static voidensureContract(Class<?> contract, Class<?>... implementations) Ensure the supplied implementation classes implement the expected contract.private static booleanfindFirstProviderContract(Class<?> clazz) static <T> Iterable<T> getAllProviders(InjectionManager injectionManager, Class<T> contract) Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.static <T> Iterable<T> getAllProviders(InjectionManager injectionManager, Class<T> contract, Comparator<T> comparator) Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer ordered based on the givencomparator.static <T> Iterable<T> getAllProviders(InjectionManager injectionManager, Class<T> contract, RankedComparator<T> comparator) Get the sorted iterable of allproviders(custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.static <T> Iterable<RankedProvider<T>> getAllRankedProviders(InjectionManager injectionManager, Class<T> contract) Get the iterable of allproviders(custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.static <T> Iterable<T> getAllRankedSortedProviders(InjectionManager injectionManager, Class<T> contract) Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer and automatically sorted usingranked comparator.static <T> Collection<ServiceHolder<T>> getAllServiceHolders(InjectionManager injectionManager, Class<T> contract) Get collection of allServiceHolders bound for providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.private static javax.ws.rs.RuntimeTypegetContractConstraint(Class<?> clazz, javax.ws.rs.RuntimeType defaultConstraint) static <T> Set<T> getCustomProviders(InjectionManager injectionManager, Class<T> contract) Get the set of all custom providers registered for the given service provider contract in the underlyinginjection managercontainer.private static Map<Class<?>, Providers.ProviderRuntime> getImplementedContracts(Class<?> clazz) private static Map<Class<?>, Providers.ProviderRuntime> private static intgetPriority(Class<?> serviceClass) private static <T> Set<T> getProviderClasses(Collection<ServiceHolder<T>> providers) getProviderContracts(Class<?> clazz) Returns provider contracts recognized by Jersey that are implemented by theclazz.static <T> Set<T> getProviders(InjectionManager injectionManager, Class<T> contract) Get the set of default providers registered for the given service provider contract in the underlyinginjection managercontainer.private static <T> List<ServiceHolder<T>> getServiceHolders(InjectionManager bm, Class<T> contract, Annotation... qualifiers) private static <T> List<ServiceHolder<T>> getServiceHolders(InjectionManager injectionManager, Class<T> contract, Comparator<Class<?>> objectComparator, Annotation... qualifiers) private static <T> Tholder2service(ServiceHolder<T> holder) static booleanisJaxRsProvider(Class<?> clazz) Returnstrueif given component class is a JAX-RS provider.static booleanisProvider(Class<?> clazz) Returnstrueif the given component class is a provider (implements specific interfaces).static booleanisSupportedContract(Class<?> type) Check if the given Java type is a Jersey-supported contract.private static voidlogProviderSkipped(StringBuilder sb, Class<?> provider, boolean alsoResourceClass) static <T> Iterable<T> mergeAndSortRankedProviders(RankedComparator<T> comparator, Iterable<Iterable<RankedProvider<T>>> providerIterables) Merge and sort given providers withranked comparator.static <T> Iterable<T> sortRankedProviders(RankedComparator<T> comparator, Iterable<RankedProvider<T>> providers) Sort given providers withranked comparator.
-
Field Details
-
LOGGER
-
JAX_RS_PROVIDER_INTERFACE_WHITELIST
Map of all standard JAX-RS providers and their run-time affinity. -
EXTERNAL_PROVIDER_INTERFACE_WHITELIST
Map of all supported external (i.e. non-Jersey) contracts and their run-time affinity.
-
-
Constructor Details
-
Providers
private Providers()
-
-
Method Details
-
getJaxRsProviderInterfaces
-
getExternalProviderInterfaces
-
getProviders
Get the set of default providers registered for the given service provider contract in the underlyinginjection managercontainer.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.contract- service provider contract.- Returns:
- set of all available default service provider instances for the contract.
-
getCustomProviders
Get the set of all custom providers registered for the given service provider contract in the underlyinginjection managercontainer.Returned providers are sorted based on
Priority(lowerPriorityvalue is higher priority, seePriorities.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.contract- service provider contract.- Returns:
- set of all available service provider instances for the contract.
-
getAllProviders
Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.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(InjectionManager injectionManager, Class<T> contract) Get the iterable of allproviders(custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.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>> providers) Sort given providers withranked comparator.- Type Parameters:
T- service provider contract Java type.- Parameters:
comparator- comparator to sort the providers with.providers- providers to be sorted.- Returns:
- sorted
iterableinstance containing given providers. The returned value is nevernull.
-
getAllRankedSortedProviders
public static <T> Iterable<T> getAllRankedSortedProviders(InjectionManager injectionManager, Class<T> contract) Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer and automatically sorted usingranked comparator.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.contract- service provider contract.- Returns:
- iterable of all available service providers for the contract. Return value is never
null.
-
mergeAndSortRankedProviders
public static <T> Iterable<T> mergeAndSortRankedProviders(RankedComparator<T> comparator, Iterable<Iterable<RankedProvider<T>>> providerIterables) Merge and sort given providers withranked comparator.- Type Parameters:
T- service provider contract Java type.- Parameters:
comparator- comparator to sort the providers with.providerIterables- providers to be sorted.- Returns:
- merged and sorted
iterableinstance containing given providers. The returned value is nevernull.
-
getAllProviders
public static <T> Iterable<T> getAllProviders(InjectionManager injectionManager, Class<T> contract, RankedComparator<T> comparator) Get the sorted iterable of allproviders(custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.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.
-
getAllServiceHolders
public static <T> Collection<ServiceHolder<T>> getAllServiceHolders(InjectionManager injectionManager, Class<T> contract) Get collection of allServiceHolders bound for providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.contract- service provider contract.- Returns:
- set of all available service provider instances for the contract
-
getServiceHolders
private static <T> List<ServiceHolder<T>> getServiceHolders(InjectionManager bm, Class<T> contract, Annotation... qualifiers) -
getServiceHolders
private static <T> List<ServiceHolder<T>> getServiceHolders(InjectionManager injectionManager, Class<T> contract, Comparator<Class<?>> objectComparator, Annotation... qualifiers) -
isJaxRsProvider
Returnstrueif given component class is a JAX-RS provider.- Parameters:
clazz- class to check.- Returns:
trueif the class is a JAX-RS provider,falseotherwise.
-
getAllProviders
public static <T> Iterable<T> getAllProviders(InjectionManager injectionManager, Class<T> contract, Comparator<T> comparator) Get the iterable of all providers (custom and default) registered for the given service provider contract in the underlyinginjection managercontainer ordered based on the givencomparator.- Type Parameters:
T- service provider contract Java type.- Parameters:
injectionManager- underlying injection manager.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.
-
getProviderClasses
-
holder2service
-
getPriority
-
getProviderContracts
Returns provider contracts recognized by Jersey that are implemented by theclazz. Recognized provider contracts include all JAX-RS providers as well as all Jersey SPI components annotated with@Contractannotation.- Parameters:
clazz- class to extract the provider interfaces from.- Returns:
- set of provider contracts implemented by the given class.
-
computeProviderContracts
-
checkProviderRuntime
public static boolean checkProviderRuntime(Class<?> component, ContractProvider model, javax.ws.rs.RuntimeType runtimeConstraint, boolean scanned, boolean isResource) Check thecomponentwhether it is appropriate correctly configured for client or serverruntime.If a problem occurs a warning is logged and if the component is not usable at all in the current runtime
falseis returned. For classes found during component scanning (scanned=true) certain warnings are completely ignored (e.g. componentsconstrained tothe 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-falseif the component type has been registered explicitly;trueif the class has been discovered during any form of component scanning.isResource-trueif the component is also a resource class.- Returns:
trueif component is acceptable for use in the given runtime type,falseotherwise.
-
logProviderSkipped
private static void logProviderSkipped(StringBuilder sb, Class<?> provider, boolean alsoResourceClass) -
isSupportedContract
Check if the given Java type is a Jersey-supported contract.- Parameters:
type- contract type.- Returns:
trueif given type is a Jersey-supported contract,falseotherwise.
-
getContractConstraint
private static javax.ws.rs.RuntimeType getContractConstraint(Class<?> clazz, javax.ws.rs.RuntimeType defaultConstraint) -
getImplementedContracts
-
isProvider
Returnstrueif the given component class is a provider (implements specific interfaces). SeegetProviderContracts(Class).- Parameters:
clazz- class to test.- Returns:
trueif the class is provider,falseotherwise.
-
ensureContract
Ensure the supplied implementation classes implement the expected contract.- Parameters:
contract- contract that is expected to be implemented by the implementation classes.implementations- contract implementations.- Throws:
IllegalArgumentException- in case any of the implementation classes does not implement the expected contract.
-
findFirstProviderContract
-