1
1
package org .m1a2st .aop ;
2
2
3
3
import org .aopalliance .intercept .MethodInterceptor ;
4
+ import org .m1a2st .aop .framework .AdvisorChainFactory ;
5
+ import org .m1a2st .aop .framework .DefaultAdvisorChainFactory ;
6
+
7
+ import java .lang .reflect .Method ;
8
+ import java .util .ArrayList ;
9
+ import java .util .List ;
10
+ import java .util .Map ;
4
11
5
12
/**
6
13
* @Author m1a2st
@@ -14,6 +21,9 @@ public class AdvisedSupport {
14
21
private TargetSource targetSource ;
15
22
private MethodInterceptor methodInterceptor ;
16
23
private MethodMatcher methodMatcher ;
24
+ AdvisorChainFactory advisorChainFactory = new DefaultAdvisorChainFactory ();
25
+ private transient Map <Integer , List <Object >> methodCache ;
26
+ private List <Advisor > advisors = new ArrayList <>();
17
27
18
28
public TargetSource getTargetSource () {
19
29
return targetSource ;
@@ -31,6 +41,10 @@ public void setMethodInterceptor(MethodInterceptor methodInterceptor) {
31
41
this .methodInterceptor = methodInterceptor ;
32
42
}
33
43
44
+ public void addAdvisor (Advisor advisor ) {
45
+ advisors .add (advisor );
46
+ }
47
+
34
48
public MethodMatcher getMethodMatcher () {
35
49
return methodMatcher ;
36
50
}
@@ -46,4 +60,42 @@ public boolean isProxyTargetClass() {
46
60
public void setProxyTargetClass (boolean proxyTargetClass ) {
47
61
this .proxyTargetClass = proxyTargetClass ;
48
62
}
63
+
64
+ public Map <Integer , List <Object >> getMethodCache () {
65
+ return methodCache ;
66
+ }
67
+
68
+ public void setMethodCache (Map <Integer , List <Object >> methodCache ) {
69
+ this .methodCache = methodCache ;
70
+ }
71
+
72
+ public AdvisorChainFactory getAdvisorChainFactory () {
73
+ return advisorChainFactory ;
74
+ }
75
+
76
+ public void setAdvisorChainFactory (AdvisorChainFactory advisorChainFactory ) {
77
+ this .advisorChainFactory = advisorChainFactory ;
78
+ }
79
+
80
+ public List <Advisor > getAdvisors () {
81
+ return advisors ;
82
+ }
83
+
84
+ public void setAdvisors (List <Advisor > advisors ) {
85
+ this .advisors = advisors ;
86
+ }
87
+
88
+ /**
89
+ * 用来返回方法的攔截器鏈
90
+ */
91
+ public List <Object > getInterceptorsAndDynamicInterceptionAdvice (Method method , Class <?> targetClass ) {
92
+ Integer cacheKey = method .hashCode ();
93
+ List <Object > cached = this .methodCache .get (cacheKey );
94
+ if (cached == null ) {
95
+ cached = this .advisorChainFactory .getInterceptorsAndDynamicInterceptionAdvice (
96
+ this , method , targetClass );
97
+ this .methodCache .put (cacheKey , cached );
98
+ }
99
+ return cached ;
100
+ }
49
101
}
0 commit comments