use of cn.taketoday.web.annotation.Interceptor in project today-framework by TAKETODAY.
the class HandlerMethodRegistry method getInterceptors.
/**
* Get list of intercepters.
*
* @param controllerClass controller class
* @param action method
* @return List of {@link HandlerInterceptor} objects
*/
protected List<HandlerInterceptor> getInterceptors(Class<?> controllerClass, Method action) {
ArrayList<HandlerInterceptor> ret = new ArrayList<>();
Set<Interceptor> controllerInterceptors = AnnotatedElementUtils.getAllMergedAnnotations(controllerClass, Interceptor.class);
// get interceptor on class
if (CollectionUtils.isNotEmpty(controllerInterceptors)) {
for (Interceptor controllerInterceptor : controllerInterceptors) {
Collections.addAll(ret, getInterceptors(controllerInterceptor.value()));
}
}
// HandlerInterceptor on a method
Set<Interceptor> actionInterceptors = AnnotatedElementUtils.getAllMergedAnnotations(action, Interceptor.class);
if (CollectionUtils.isNotEmpty(actionInterceptors)) {
ApplicationContext beanFactory = obtainApplicationContext();
for (Interceptor actionInterceptor : actionInterceptors) {
Collections.addAll(ret, getInterceptors(actionInterceptor.value()));
// exclude interceptors
for (Class<? extends HandlerInterceptor> interceptor : actionInterceptor.exclude()) {
ret.remove(beanFactory.getBean(interceptor));
}
}
}
return ret;
}
Aggregations