Search in sources :

Example 1 with PointcutAdvisor

use of org.springframework.aop.PointcutAdvisor in project spring-framework by spring-projects.

the class DefaultAdvisorChainFactory method getInterceptorsAndDynamicInterceptionAdvice.

@Override
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, Class<?> targetClass) {
    // This is somewhat tricky... We have to process introductions first,
    // but we need to preserve order in the ultimate list.
    List<Object> interceptorList = new ArrayList<>(config.getAdvisors().length);
    Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
    boolean hasIntroductions = hasMatchingIntroductions(config, actualClass);
    AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
    for (Advisor advisor : config.getAdvisors()) {
        if (advisor instanceof PointcutAdvisor) {
            // Add it conditionally.
            PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
            if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
                MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
                MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
                if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
                    if (mm.isRuntime()) {
                        // isn't a problem as we normally cache created chains.
                        for (MethodInterceptor interceptor : interceptors) {
                            interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
                        }
                    } else {
                        interceptorList.addAll(Arrays.asList(interceptors));
                    }
                }
            }
        } else if (advisor instanceof IntroductionAdvisor) {
            IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
            if (config.isPreFiltered() || ia.getClassFilter().matches(actualClass)) {
                Interceptor[] interceptors = registry.getInterceptors(advisor);
                interceptorList.addAll(Arrays.asList(interceptors));
            }
        } else {
            Interceptor[] interceptors = registry.getInterceptors(advisor);
            interceptorList.addAll(Arrays.asList(interceptors));
        }
    }
    return interceptorList;
}
Also used : PointcutAdvisor(org.springframework.aop.PointcutAdvisor) IntroductionAdvisor(org.springframework.aop.IntroductionAdvisor) ArrayList(java.util.ArrayList) PointcutAdvisor(org.springframework.aop.PointcutAdvisor) IntroductionAdvisor(org.springframework.aop.IntroductionAdvisor) Advisor(org.springframework.aop.Advisor) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) GlobalAdvisorAdapterRegistry(org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry) AdvisorAdapterRegistry(org.springframework.aop.framework.adapter.AdvisorAdapterRegistry) MethodMatcher(org.springframework.aop.MethodMatcher)

Aggregations

ArrayList (java.util.ArrayList)1 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)1 Advisor (org.springframework.aop.Advisor)1 IntroductionAdvisor (org.springframework.aop.IntroductionAdvisor)1 MethodMatcher (org.springframework.aop.MethodMatcher)1 PointcutAdvisor (org.springframework.aop.PointcutAdvisor)1 AdvisorAdapterRegistry (org.springframework.aop.framework.adapter.AdvisorAdapterRegistry)1 GlobalAdvisorAdapterRegistry (org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry)1