Search in sources :

Example 1 with Interceptor

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;
}
Also used : WebApplicationContext(cn.taketoday.web.WebApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) HandlerInterceptor(cn.taketoday.web.interceptor.HandlerInterceptor) ArrayList(java.util.ArrayList) Interceptor(cn.taketoday.web.annotation.Interceptor) HandlerInterceptor(cn.taketoday.web.interceptor.HandlerInterceptor)

Aggregations

ApplicationContext (cn.taketoday.context.ApplicationContext)1 WebApplicationContext (cn.taketoday.web.WebApplicationContext)1 Interceptor (cn.taketoday.web.annotation.Interceptor)1 HandlerInterceptor (cn.taketoday.web.interceptor.HandlerInterceptor)1 ArrayList (java.util.ArrayList)1