Search in sources :

Example 1 with BeanDefinitionRegistrar

use of cn.taketoday.context.loader.BeanDefinitionRegistrar in project today-framework by TAKETODAY.

the class HandlerMethodRegistry method getInterceptors.

/**
 * Get {@link HandlerInterceptor} objects
 *
 * @param interceptors
 *            {@link HandlerInterceptor} class
 * @return Array of {@link HandlerInterceptor} objects
 */
public HandlerInterceptor[] getInterceptors(Class<? extends HandlerInterceptor>[] interceptors) {
    if (ObjectUtils.isEmpty(interceptors)) {
        return HandlerInterceptor.EMPTY_ARRAY;
    }
    int i = 0;
    HandlerInterceptor[] ret = new HandlerInterceptor[interceptors.length];
    BeanDefinitionRegistrar registrar = obtainApplicationContext().unwrap(BeanDefinitionRegistrar.class);
    for (Class<? extends HandlerInterceptor> interceptor : interceptors) {
        if (!registry.containsBeanDefinition(interceptor, true)) {
            try {
                registrar.registerBean(interceptor);
            } catch (BeanDefinitionStoreException e) {
                throw new ConfigurationException("Interceptor: [" + interceptor.getName() + "] register error", e);
            }
        }
        HandlerInterceptor instance = this.beanFactory.getBean(interceptor);
        Assert.state(instance != null, "Can't get target interceptor bean");
        ret[i++] = instance;
    }
    return ret;
}
Also used : HandlerInterceptor(cn.taketoday.web.interceptor.HandlerInterceptor) BeanDefinitionStoreException(cn.taketoday.beans.factory.BeanDefinitionStoreException) ConfigurationException(cn.taketoday.core.ConfigurationException) BeanDefinitionRegistrar(cn.taketoday.context.loader.BeanDefinitionRegistrar)

Aggregations

BeanDefinitionStoreException (cn.taketoday.beans.factory.BeanDefinitionStoreException)1 BeanDefinitionRegistrar (cn.taketoday.context.loader.BeanDefinitionRegistrar)1 ConfigurationException (cn.taketoday.core.ConfigurationException)1 HandlerInterceptor (cn.taketoday.web.interceptor.HandlerInterceptor)1