1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.examples.impl; |
16 |
| |
17 |
| import java.lang.reflect.InvocationHandler; |
18 |
| import java.lang.reflect.InvocationTargetException; |
19 |
| import java.lang.reflect.Method; |
20 |
| |
21 |
| import org.apache.commons.logging.Log; |
22 |
| import org.apache.hivemind.service.impl.LoggingUtils; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class ProxyLoggingInvocationHandler implements InvocationHandler |
33 |
| { |
34 |
| private Log _log; |
35 |
| private Object _delegate; |
36 |
| |
37 |
0
| public ProxyLoggingInvocationHandler(Log log, Object delegate)
|
38 |
| { |
39 |
0
| _log = log;
|
40 |
0
| _delegate = delegate;
|
41 |
| } |
42 |
| |
43 |
0
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
|
44 |
| { |
45 |
0
| boolean debug = _log.isDebugEnabled();
|
46 |
| |
47 |
0
| if (debug)
|
48 |
0
| LoggingUtils.entry(_log, method.getName(), args);
|
49 |
| |
50 |
0
| try
|
51 |
| { |
52 |
0
| Object result = method.invoke(_delegate, args);
|
53 |
| |
54 |
0
| if (debug)
|
55 |
| { |
56 |
0
| if (method.getReturnType() == void.class)
|
57 |
0
| LoggingUtils.voidExit(_log, method.getName());
|
58 |
| else |
59 |
0
| LoggingUtils.exit(_log, method.getName(), result);
|
60 |
| } |
61 |
| |
62 |
0
| return result;
|
63 |
| } |
64 |
| catch (InvocationTargetException ex) |
65 |
| { |
66 |
0
| Throwable targetException = ex.getTargetException();
|
67 |
| |
68 |
0
| if (debug)
|
69 |
0
| LoggingUtils.exception(_log, method.getName(), targetException);
|
70 |
| |
71 |
0
| throw targetException;
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
| } |