|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ProxyLoggingInvocationHandler.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.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 |
* An invocation handler used by {@link org.apache.hivemind.examples.impl.ProxyLoggingInterceptorFactory}.
|
|
26 |
* Logs all method invocations, return values and exceptions. Note that, unlike the real
|
|
27 |
* LoggingInterceptor, <code>toString()</code> will just pass through to the inner service object
|
|
28 |
* (typically, the core service implementation).
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
*/
|
|
32 |
public class ProxyLoggingInvocationHandler implements InvocationHandler |
|
33 |
{ |
|
34 |
private Log _log;
|
|
35 |
private Object _inner;
|
|
36 |
|
|
37 | 0 |
public ProxyLoggingInvocationHandler(Log log, Object inner)
|
38 |
{ |
|
39 | 0 |
_log = log; |
40 | 0 |
_inner = inner; |
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(_inner, 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 |
} |
|
76 |
|
|