|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package net.sf.crispy.proxy; |
|
6 |
| |
|
7 |
| import java.lang.reflect.Method; |
|
8 |
| |
|
9 |
| import net.sf.crispy.Executor; |
|
10 |
| import net.sf.crispy.InterceptorContext; |
|
11 |
| import net.sf.crispy.InterceptorHandler; |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| public final class InvocationHandler { |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
845
| public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs,
|
|
42 |
| Object pvElseObject, final InterceptorHandler pvInterceptorHandler) throws Exception { |
|
43 |
845
| Object ret = null;
|
|
44 |
845
| InterceptorContext lvInterceptorContext = new InterceptorContext(pvDynamicProxy, pvMethod, pvArgs, pvElseObject);
|
|
45 |
| |
|
46 |
845
| if (pvInterceptorHandler == null) {
|
|
47 |
1
| throw new IllegalArgumentException ("The InvocationHandler has no InterceptorHandler (is null)!");
|
|
48 |
| } |
|
49 |
| |
|
50 |
| |
|
51 |
844
| InterceptorContext lvInterceptorContextModify = pvInterceptorHandler.fireBeforeModifyInvocation(lvInterceptorContext);
|
|
52 |
844
| boolean lvInterruptInvocationModifier = lvInterceptorContextModify.getInterruptInvocation();
|
|
53 |
| |
|
54 |
844
| Method lvNewMethod = lvInterceptorContextModify.getMethod();
|
|
55 |
844
| Object lvNewArgs[] = lvInterceptorContextModify.getArgs();
|
|
56 |
844
| Object lvNewElseObject = lvInterceptorContextModify.getElseObject();
|
|
57 |
844
| DynamicProxy lvNewDynamicProxy = lvInterceptorContextModify.getDynamicProxy();
|
|
58 |
| |
|
59 |
| |
|
60 |
844
| boolean lvInterruptInvocationInterceptor = pvInterceptorHandler.fireBeforeMethodInvocation(lvInterceptorContext);
|
|
61 |
844
| try {
|
|
62 |
844
| boolean lvInterruptInvocation = false;
|
|
63 |
844
| if ((lvInterruptInvocationModifier == true) || (lvInterruptInvocationInterceptor == true)) {
|
|
64 |
7
| lvInterruptInvocation = true;
|
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
844
| if (lvInterruptInvocation == true) {
|
|
69 |
7
| ret = lvInterceptorContext.getResult();
|
|
70 |
7
| if (ret instanceof Exception) {
|
|
71 |
1
| throw (Exception) ret;
|
|
72 |
| } |
|
73 |
| } else { |
|
74 |
| |
|
75 |
837
| Executor lvExecutor = lvNewDynamicProxy.getExecutor();
|
|
76 |
837
| if (lvExecutor == null) {
|
|
77 |
480
| ret = lvNewDynamicProxy.invokeIfExecutorIsNull(pvProxy, lvNewMethod, lvNewArgs, lvNewElseObject);
|
|
78 |
| } else { |
|
79 |
357
| ret = lvExecutor.execute(lvNewDynamicProxy.getProxyClass(), lvNewDynamicProxy.getProxyObject(), lvNewMethod, lvNewArgs);
|
|
80 |
| } |
|
81 |
| |
|
82 |
| } |
|
83 |
| |
|
84 |
| } catch (Exception e) { |
|
85 |
33
| pvInterceptorHandler.fireOnError(e);
|
|
86 |
33
| throw e;
|
|
87 |
| } |
|
88 |
| finally { |
|
89 |
844
| lvInterceptorContext.setResult(ret);
|
|
90 |
| |
|
91 |
844
| InterceptorContext lvInterceptorContext2 = pvInterceptorHandler.fireAfterModifyInvocation(lvInterceptorContext);
|
|
92 |
844
| ret = lvInterceptorContext2.getResult();
|
|
93 |
| |
|
94 |
844
| pvInterceptorHandler.fireAfterMethodInvocation(lvInterceptorContext);
|
|
95 |
| } |
|
96 |
810
| return ret;
|
|
97 |
| } |
|
98 |
| |
|
99 |
1
| public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs, Object pvElseObject) throws Exception {
|
|
100 |
1
| return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, pvElseObject, new InterceptorHandler());
|
|
101 |
| } |
|
102 |
| |
|
103 |
842
| public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs, InterceptorHandler pvInterceptorHandler) throws Exception {
|
|
104 |
842
| return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, null, pvInterceptorHandler);
|
|
105 |
| } |
|
106 |
| |
|
107 |
2
| public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
|
|
108 |
2
| return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, null, new InterceptorHandler());
|
|
109 |
| } |
|
110 |
| |
|
111 |
| } |