KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > connection > proxy > Mx4jMBeanServerProxy


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.connection.proxy;
18
19 import mx4j.connector.RemoteMBeanServer;
20 import org.mc4j.console.swing.SwingUtility;
21 import org.mc4j.console.util.ConnectionInfoAction;
22
23 import javax.management.MBeanServer JavaDoc;
24 import java.lang.reflect.InvocationHandler JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.lang.reflect.Proxy JavaDoc;
27
28 /**
29  * Proxies calls to a remote Mx4j JRMP server connect MBeanServer. This
30  * allows you to treat a remote RemoteMBeanServer as a regular local
31  * MBeanServer.
32  *
33  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
34  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
35  */

36 public class Mx4jMBeanServerProxy implements InvocationHandler JavaDoc {
37
38     private RemoteMBeanServer remoteServer;
39
40     private static final Class JavaDoc[] INTERFACES = { MBeanServer.class };
41
42
43     /** Creates a new instance of RemoteMBeanServerProxy */
44     public Mx4jMBeanServerProxy(RemoteMBeanServer remoteServer) {
45         this.remoteServer = remoteServer;
46     }
47
48     public Object JavaDoc invoke(
49         final Object JavaDoc proxy,
50         final Method JavaDoc m,
51         final Object JavaDoc[] args)
52     throws Throwable JavaDoc {
53
54         SwingUtility.eventThreadAlert();
55
56 // ConnectionInfoAction.addHit();
57

58         Class JavaDoc serverClass = RemoteMBeanServer.class; // this.remoteServer.getClass();
59

60         Method JavaDoc method = serverClass.getMethod(m.getName(),m.getParameterTypes());
61
62         return method.invoke(this.remoteServer, args);
63     }
64     
65     public static MBeanServer buildServerProxy(RemoteMBeanServer server) {
66
67         Object JavaDoc proxy =
68             Proxy.newProxyInstance(
69                 Mx4jMBeanServerProxy.class.getClassLoader(),
70                 Mx4jMBeanServerProxy.INTERFACES,
71                 new Mx4jMBeanServerProxy(server));
72
73         return (MBeanServer) proxy;
74     }
75
76
77 }
78
Popular Tags