use of org.jboss.resteasy.util.FeatureContextDelegate in project resteasy by resteasy.
the class ResteasyProviderFactoryImpl method processProviderInstanceContracts.
private void processProviderInstanceContracts(Object provider, Map<Class<?>, Integer> contracts, Integer priorityOverride, boolean builtIn, Map<Class<?>, Integer> newContracts) {
clientHelper.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
serverHelper.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
if (Utils.isA(provider, ParamConverterProvider.class, contracts)) {
injectProperties(provider);
int priority = Utils.getPriority(priorityOverride, contracts, ParamConverterProvider.class, provider.getClass());
copyParamConvertsIfNeeded();
sortedParamConverterProviders.add(new ExtSortedKey<>(null, (ParamConverterProvider) provider, provider.getClass(), priority, builtIn));
newContracts.put(ParamConverterProvider.class, priority);
}
if (Utils.isA(provider, ContextResolver.class, contracts)) {
try {
int priority = Utils.getPriority(priorityOverride, contracts, ContextResolver.class, provider.getClass());
addContextResolver((ContextResolver) provider, priority, provider.getClass(), false);
newContracts.put(ContextResolver.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextResolver(), e);
}
}
if (Utils.isA(provider, ContextInjector.class, contracts)) {
try {
addContextInjector((ContextInjector) provider, provider.getClass());
int priority = Utils.getPriority(priorityOverride, contracts, ContextInjector.class, provider.getClass());
newContracts.put(ContextInjector.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextInjector(), e);
}
}
if (Utils.isA(provider, InjectorFactory.class, contracts)) {
this.injectorFactory = (InjectorFactory) provider;
newContracts.put(InjectorFactory.class, 0);
}
if (Utils.isA(provider, Feature.class, contracts)) {
Feature feature = (Feature) provider;
Utils.injectProperties(this, provider.getClass(), provider);
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getClass().getAnnotation(ConstrainedTo.class);
if (constrainedTo == null || constrainedTo.value() == getRuntimeType()) {
if (feature.configure(new FeatureContextDelegate(this))) {
enabledFeatures.add(feature);
}
}
int priority = Utils.getPriority(priorityOverride, contracts, Feature.class, provider.getClass());
newContracts.put(Feature.class, priority);
}
if (Utils.isA(provider, ResourceClassProcessor.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ResourceClassProcessor.class, provider.getClass());
addResourceClassProcessor((ResourceClassProcessor) provider, priority);
newContracts.put(ResourceClassProcessor.class, priority);
}
if (Utils.isA(provider, HeaderDelegate.class, contracts)) {
Type[] headerTypes = Types.getActualTypeArgumentsOfAnInterface(provider.getClass(), HeaderDelegate.class);
if (headerTypes.length == 0) {
LogMessages.LOGGER.cannotRegisterheaderDelegate(provider.getClass());
} else {
Class<?> headerClass = Types.getRawType(headerTypes[0]);
addHeaderDelegate(headerClass, (HeaderDelegate) provider);
}
}
if (Utils.isA(provider, ThreadContext.class, contracts)) {
ResteasyContext.computeIfAbsent(ThreadContexts.class, ThreadContexts::new).add((ThreadContext<?>) provider);
}
}
Aggregations