KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.j2ee.Management JavaDoc;
25 import java.lang.reflect.InvocationHandler JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import java.lang.reflect.Proxy JavaDoc;
28
29
30 /**
31  *
32  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
33  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
34  */

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

56         Class JavaDoc serverClass = Management JavaDoc.class; // this.remoteServer.getClass();
57

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