1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.proxy.interceptor;
19
20 import org.aopalliance.intercept.MethodInterceptor;
21 import org.aopalliance.intercept.MethodInvocation;
22 import org.apache.commons.proxy.Interceptor;
23 import org.apache.commons.proxy.Invocation;
24
25 import java.lang.reflect.AccessibleObject;
26 import java.lang.reflect.Method;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class MethodInterceptorAdapter implements Interceptor
42 {
43 private final MethodInterceptor methodInterceptor;
44
45 public MethodInterceptorAdapter( MethodInterceptor methodInterceptor )
46 {
47 this.methodInterceptor = methodInterceptor;
48 }
49
50 public Object intercept( Invocation invocation ) throws Throwable
51 {
52 return methodInterceptor.invoke( new MethodInvocationAdapter( invocation ) );
53 }
54
55 private static class MethodInvocationAdapter implements MethodInvocation
56 {
57 private final Invocation invocation;
58
59 public MethodInvocationAdapter( Invocation invocation )
60 {
61 this.invocation = invocation;
62 }
63
64 public Method getMethod()
65 {
66 return invocation.getMethod();
67 }
68
69 public Object[] getArguments()
70 {
71 return invocation.getArguments();
72 }
73
74 public Object proceed() throws Throwable
75 {
76 return invocation.proceed();
77 }
78
79 public Object getThis()
80 {
81 return invocation.getProxy();
82 }
83
84 public AccessibleObject getStaticPart()
85 {
86 return invocation.getMethod();
87 }
88 }
89 }