KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > fakepeer > FakePeerInvocationHandler


1 /*
2  * FakePeerInvocationHandler.java
3  *
4  * Created on September 9, 2005, 12:48 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.form.fakepeer;
11
12 import java.lang.reflect.InvocationHandler JavaDoc;
13 import java.lang.reflect.Method JavaDoc;
14 import org.openide.ErrorManager;
15
16 /**
17  *
18  * An {@link InvocationHandler} used for dynamic interface implementation
19  * in {@link FakePeerSupport}.
20  *
21  * @author Tomas Stupka
22  */

23 public class FakePeerInvocationHandler implements InvocationHandler JavaDoc {
24     
25     private final FakeComponentPeer comp;
26     
27     /**
28      *
29      */

30     public FakePeerInvocationHandler (FakeComponentPeer comp) {
31         this.comp = comp;
32     }
33     
34     /**
35      * @see InvocationHandler#invoke(Object proxy, Method method, Object[] args)
36      */

37     public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args)
38        throws Throwable JavaDoc {
39        
40         try {
41             
42             Class JavaDoc[] parameters = method.getParameterTypes();
43             Method JavaDoc thisMethod = comp.getClass().getMethod(method.getName(), parameters);
44             return thisMethod.invoke(comp, args);
45             
46             /*
47              * jdk 1.6 redefines the requestFocus() method in PeerComponent with a new parameter
48              * which is from a new type, unknown in previous jdk releases (<1.6), so we cannot
49              * just reimplement the method in FakePeerComponent.
50              *
51              * In case we should in future get a NoSuchMethodException, because of
52              * invoking the requestFocus() method with the jdk1.6 signature, we can implement
53              * here a special routine which return a proper value to the caller... .
54              *
55              */

56             
57         } catch (Exception JavaDoc e) {
58             ErrorManager.getDefault().notify(e);
59             throw e;
60         }
61         
62     }
63     
64 }
65
Popular Tags