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

1 package hudson.util.jna;
2
3 import java.lang.reflect.InvocationHandler;
4 import java.lang.reflect.Method;
5 import java.lang.reflect.Proxy;
6
7 /**
8 * {@link InvocationHandler} that reports the same exception over and over again when methods are invoked
9 * on the interface.
10 *
11 * This is convenient to remember why the initialization of the real JNA proxy failed.
12 *
13 * @author Kohsuke Kawaguchi
14 * @since 1.487
15 * @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7199848">Related bug report against JDK</a>
16 */
17 public class InitializationErrorInvocationHandler implements InvocationHandler {
18 private final Throwable cause;
19
20 private InitializationErrorInvocationHandler(Throwable cause) {
21 this.cause = cause;
22 }
23
24 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
25 if (method.getDeclaringClass()==Object.class)
26 return method.invoke(this,args);
27
28 throw new UnsupportedOperationException("Failed to link the library: "+method.getDeclaringClass(), cause);
29 }
30
31 public static <T> T create(Class<T> type, Throwable cause) {
32 return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InitializationErrorInvocationHandler(cause)));
33 }
34 }
35