1 16 17 package org.springframework.aop.framework; 18 19 import java.lang.reflect.Method ; 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 import java.util.List ; 23 24 import org.aopalliance.intercept.Interceptor; 25 import org.aopalliance.intercept.MethodInterceptor; 26 27 import org.springframework.aop.Advisor; 28 import org.springframework.aop.IntroductionAdvisor; 29 import org.springframework.aop.MethodMatcher; 30 import org.springframework.aop.PointcutAdvisor; 31 import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry; 32 import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry; 33 import org.springframework.aop.support.MethodMatchers; 34 35 45 public class DefaultAdvisorChainFactory implements AdvisorChainFactory { 46 47 public List getInterceptorsAndDynamicInterceptionAdvice( 48 Advised config, Object proxy, Method method, Class targetClass) { 49 50 List interceptorList = new ArrayList (config.getAdvisors().length); 53 boolean hasIntroductions = hasMatchingIntroductions(config, targetClass); 54 AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance(); 55 Advisor[] advisors = config.getAdvisors(); 56 for (int i = 0; i < advisors.length; i++) { 57 Advisor advisor = advisors[i]; 58 if (advisor instanceof PointcutAdvisor) { 59 PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; 61 if (pointcutAdvisor.getPointcut().getClassFilter().matches(targetClass)) { 62 MethodInterceptor[] interceptors = registry.getInterceptors(advisor); 63 MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); 64 if (MethodMatchers.matches(mm, method, targetClass, hasIntroductions)) { 65 if (mm.isRuntime()) { 66 for (int j = 0; j < interceptors.length; j++) { 69 interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptors[j], mm)); 70 } 71 } 72 else { 73 interceptorList.addAll(Arrays.asList(interceptors)); 74 } 75 } 76 } 77 } 78 else if (advisor instanceof IntroductionAdvisor) { 79 IntroductionAdvisor ia = (IntroductionAdvisor) advisor; 80 if (ia.getClassFilter().matches(targetClass)) { 81 Interceptor[] interceptors = registry.getInterceptors(advisor); 82 interceptorList.addAll(Arrays.asList(interceptors)); 83 } 84 } 85 } 86 return interceptorList; 87 } 88 89 92 private static boolean hasMatchingIntroductions(Advised config, Class targetClass) { 93 for (int i = 0; i < config.getAdvisors().length; i++) { 94 Advisor advisor = config.getAdvisors()[i]; 95 if (advisor instanceof IntroductionAdvisor) { 96 IntroductionAdvisor ia = (IntroductionAdvisor) advisor; 97 if (ia.getClassFilter().matches(targetClass)) { 98 return true; 99 } 100 } 101 } 102 return false; 103 } 104 105 } 106 | Popular Tags |