protected <T extends Executable, I extends Interceptor, F> List<I> getInterceptors(
T interceptee,
IterableProvider<? extends F> factoryProviders,
Class<F> interceptorType,
InterceptorFactory<F, T, Annotation, I> interceptorProvider
) {
List<I> interceptors = Lists.newArrayList();
factoryProviders.handleIterator().forEach(handle -> {
// Make sure descriptor is fully reified
ActiveDescriptor<?> descriptor = handle.getActiveDescriptor();
if (!descriptor.isReified()) {
descriptor = locator.reifyDescriptor(descriptor);
}
// Check the type of annotation supported by the factory
for (Type contract : descriptor.getContractTypes()) {
if (ReflectionHelper.getRawClass(contract) == interceptorType) {
Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ReflectionHelper.getRawClass(
ReflectionHelper.getFirstTypeArgument(contract));
// Might be Object.class if getRawClass found an unbound type variable or wildcard
if (!Annotation.class.isAssignableFrom(annotationClass)) {
log.warn("Unable to determine annotation binder from contract type {}", annotationClass);
return;
}
Annotation ann = interceptee.getAnnotation(annotationClass);
if (ann == null) {
ann = interceptee.getDeclaringClass().getAnnotation(annotationClass);
}
if (ann != null) {
// Create the factory and produce an interceptor
F factory = handle.getService();
I interceptor = interceptorProvider.apply(factory, interceptee, ann);
if (interceptor != null) {
interceptors.add(interceptor);
}
}
return;
}
}
});
return interceptors;
}
AnnotationInterceptionService.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:dropwizard-hk2
作者:
评论列表
文章目录