File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\util\InterceptingProxy.java.html

1 package hudson.util;
2
3 import java.lang.reflect.Method;
4 import java.lang.reflect.Proxy;
5 import java.lang.reflect.InvocationHandler;
6 import java.lang.reflect.InvocationTargetException;
7
8 /**
9 * Creates a proxy that traps every method call.
10 *
11 * @author Kohsuke Kawaguchi
12 */
13 public abstract class InterceptingProxy {
14 /**
15 * Intercepts every method call.
16 */
17 protected abstract Object call(Object o, Method m, Object[] args) throws Throwable;
18
19 public final <T> T wrap(Class<T> type, final T object) {
20 return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() {
21 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
22 try {
23 return call(object,method,args);
24 } catch (InvocationTargetException e) {
25 throw e.getTargetException();
26 }
27 }
28 }));
29 }
30 }
31