KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.mc4j.console.swing.SwingUtility;
20 import org.mc4j.console.util.ConnectionInfoAction;
21
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.MBeanServerConnection 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 /**
30  *
31  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
32  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
33  */

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

55         Class JavaDoc serverClass = MBeanServerConnection JavaDoc.class; // this.remoteServer.getClass();
56

57         Method JavaDoc method = serverClass.getMethod(m.getName(),m.getParameterTypes());
58
59         // TODO CSC: should all IOExceptions been catched here and thrown as an MC4JIOException (RuntimeException)
60
// to avoid the occurence of an UndeclaredThrowableExcpetion???
61
return method.invoke(this.remoteServer, args);
62     }
63
64     public static MBeanServer JavaDoc buildServerProxy(Object JavaDoc server) {
65
66         Object JavaDoc proxy =
67             Proxy.newProxyInstance(
68                 JMXRemotingMBeanServerProxy.class.getClassLoader(),
69                 JMXRemotingMBeanServerProxy.INTERFACES,
70                 new JMXRemotingMBeanServerProxy((MBeanServerConnection JavaDoc) server));
71
72         return (MBeanServer JavaDoc) proxy;
73     }
74 }
75
Popular Tags