1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,19 +50,21 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
50
50
public List <Object > getInterceptorsAndDynamicInterceptionAdvice (
51
51
Advised config , Method method , Class <?> targetClass ) {
52
52
53
- // This is somewhat tricky... we have to process introductions first,
53
+ // This is somewhat tricky... We have to process introductions first,
54
54
// but we need to preserve order in the ultimate list.
55
55
List <Object > interceptorList = new ArrayList <Object >(config .getAdvisors ().length );
56
- boolean hasIntroductions = hasMatchingIntroductions (config , targetClass );
56
+ Class <?> actualClass = (targetClass != null ? targetClass : method .getDeclaringClass ());
57
+ boolean hasIntroductions = hasMatchingIntroductions (config , actualClass );
57
58
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry .getInstance ();
59
+
58
60
for (Advisor advisor : config .getAdvisors ()) {
59
61
if (advisor instanceof PointcutAdvisor ) {
60
62
// Add it conditionally.
61
63
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor ) advisor ;
62
- if (config .isPreFiltered () || pointcutAdvisor .getPointcut ().getClassFilter ().matches (targetClass )) {
64
+ if (config .isPreFiltered () || pointcutAdvisor .getPointcut ().getClassFilter ().matches (actualClass )) {
63
65
MethodInterceptor [] interceptors = registry .getInterceptors (advisor );
64
66
MethodMatcher mm = pointcutAdvisor .getPointcut ().getMethodMatcher ();
65
- if (MethodMatchers .matches (mm , method , targetClass , hasIntroductions )) {
67
+ if (MethodMatchers .matches (mm , method , actualClass , hasIntroductions )) {
66
68
if (mm .isRuntime ()) {
67
69
// Creating a new object instance in the getInterceptors() method
68
70
// isn't a problem as we normally cache created chains.
@@ -78,7 +80,7 @@ public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
78
80
}
79
81
else if (advisor instanceof IntroductionAdvisor ) {
80
82
IntroductionAdvisor ia = (IntroductionAdvisor ) advisor ;
81
- if (config .isPreFiltered () || ia .getClassFilter ().matches (targetClass )) {
83
+ if (config .isPreFiltered () || ia .getClassFilter ().matches (actualClass )) {
82
84
Interceptor [] interceptors = registry .getInterceptors (advisor );
83
85
interceptorList .addAll (Arrays .asList (interceptors ));
84
86
}
@@ -88,18 +90,19 @@ else if (advisor instanceof IntroductionAdvisor) {
88
90
interceptorList .addAll (Arrays .asList (interceptors ));
89
91
}
90
92
}
93
+
91
94
return interceptorList ;
92
95
}
93
96
94
97
/**
95
98
* Determine whether the Advisors contain matching introductions.
96
99
*/
97
- private static boolean hasMatchingIntroductions (Advised config , Class <?> targetClass ) {
100
+ private static boolean hasMatchingIntroductions (Advised config , Class <?> actualClass ) {
98
101
for (int i = 0 ; i < config .getAdvisors ().length ; i ++) {
99
102
Advisor advisor = config .getAdvisors ()[i ];
100
103
if (advisor instanceof IntroductionAdvisor ) {
101
104
IntroductionAdvisor ia = (IntroductionAdvisor ) advisor ;
102
- if (ia .getClassFilter ().matches (targetClass )) {
105
+ if (ia .getClassFilter ().matches (actualClass )) {
103
106
return true ;
104
107
}
105
108
}
0 commit comments