|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -50,19 +50,21 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ |
|
|
|
public List<Object> getInterceptorsAndDynamicInterceptionAdvice( |
|
|
|
public List<Object> getInterceptorsAndDynamicInterceptionAdvice( |
|
|
|
Advised config, Method method, Class<?> targetClass) { |
|
|
|
Advised config, Method method, Class<?> targetClass) { |
|
|
|
|
|
|
|
|
|
|
|
// This is somewhat tricky... we have to process introductions first,
|
|
|
|
// This is somewhat tricky... We have to process introductions first,
|
|
|
|
// but we need to preserve order in the ultimate list.
|
|
|
|
// but we need to preserve order in the ultimate list.
|
|
|
|
List<Object> interceptorList = new ArrayList<Object>(config.getAdvisors().length); |
|
|
|
List<Object> interceptorList = new ArrayList<Object>(config.getAdvisors().length); |
|
|
|
boolean hasIntroductions = hasMatchingIntroductions(config, targetClass); |
|
|
|
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass()); |
|
|
|
|
|
|
|
boolean hasIntroductions = hasMatchingIntroductions(config, actualClass); |
|
|
|
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance(); |
|
|
|
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
for (Advisor advisor : config.getAdvisors()) { |
|
|
|
for (Advisor advisor : config.getAdvisors()) { |
|
|
|
if (advisor instanceof PointcutAdvisor) { |
|
|
|
if (advisor instanceof PointcutAdvisor) { |
|
|
|
// Add it conditionally.
|
|
|
|
// Add it conditionally.
|
|
|
|
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; |
|
|
|
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; |
|
|
|
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(targetClass)) { |
|
|
|
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) { |
|
|
|
MethodInterceptor[] interceptors = registry.getInterceptors(advisor); |
|
|
|
MethodInterceptor[] interceptors = registry.getInterceptors(advisor); |
|
|
|
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); |
|
|
|
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); |
|
|
|
if (MethodMatchers.matches(mm, method, targetClass, hasIntroductions)) { |
|
|
|
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) { |
|
|
|
if (mm.isRuntime()) { |
|
|
|
if (mm.isRuntime()) { |
|
|
|
// Creating a new object instance in the getInterceptors() method
|
|
|
|
// Creating a new object instance in the getInterceptors() method
|
|
|
|
// isn't a problem as we normally cache created chains.
|
|
|
|
// isn't a problem as we normally cache created chains.
|
|
|
|
@ -78,7 +80,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ |
|
|
|
} |
|
|
|
} |
|
|
|
else if (advisor instanceof IntroductionAdvisor) { |
|
|
|
else if (advisor instanceof IntroductionAdvisor) { |
|
|
|
IntroductionAdvisor ia = (IntroductionAdvisor) advisor; |
|
|
|
IntroductionAdvisor ia = (IntroductionAdvisor) advisor; |
|
|
|
if (config.isPreFiltered() || ia.getClassFilter().matches(targetClass)) { |
|
|
|
if (config.isPreFiltered() || ia.getClassFilter().matches(actualClass)) { |
|
|
|
Interceptor[] interceptors = registry.getInterceptors(advisor); |
|
|
|
Interceptor[] interceptors = registry.getInterceptors(advisor); |
|
|
|
interceptorList.addAll(Arrays.asList(interceptors)); |
|
|
|
interceptorList.addAll(Arrays.asList(interceptors)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -88,18 +90,19 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ |
|
|
|
interceptorList.addAll(Arrays.asList(interceptors)); |
|
|
|
interceptorList.addAll(Arrays.asList(interceptors)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return interceptorList; |
|
|
|
return interceptorList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine whether the Advisors contain matching introductions. |
|
|
|
* Determine whether the Advisors contain matching introductions. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static boolean hasMatchingIntroductions(Advised config, Class<?> targetClass) { |
|
|
|
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) { |
|
|
|
for (int i = 0; i < config.getAdvisors().length; i++) { |
|
|
|
for (int i = 0; i < config.getAdvisors().length; i++) { |
|
|
|
Advisor advisor = config.getAdvisors()[i]; |
|
|
|
Advisor advisor = config.getAdvisors()[i]; |
|
|
|
if (advisor instanceof IntroductionAdvisor) { |
|
|
|
if (advisor instanceof IntroductionAdvisor) { |
|
|
|
IntroductionAdvisor ia = (IntroductionAdvisor) advisor; |
|
|
|
IntroductionAdvisor ia = (IntroductionAdvisor) advisor; |
|
|
|
if (ia.getClassFilter().matches(targetClass)) { |
|
|
|
if (ia.getClassFilter().matches(actualClass)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|