KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > jmx > server > mx4j > RemoteMBeanServerProxy


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.jmx.server.mx4j;
19
20 import java.lang.reflect.Method JavaDoc;
21 import java.lang.reflect.Proxy JavaDoc;
22
23 import javax.management.MBeanServer JavaDoc;
24
25 import org.sape.carbon.core.util.reflection.GenericProxy;
26
27 import mx4j.connector.RemoteMBeanServer;
28
29 /**
30  * Dynamic proxy for a RemoteMBeanServer.
31  *
32  * Copyright 2002 Sapient
33  * @since carbon 1.0
34  * @author Greg Hinkle, June 2002
35  * @version $Revision: 1.5 $($Author: dvoet $ / $Date: 2003/05/05 21:21:31 $)
36  */

37 public class RemoteMBeanServerProxy extends GenericProxy {
38     /**
39      * Holds the server being proxied.
40      */

41     private RemoteMBeanServer remoteServer;
42
43     /**
44      * Interfaces being applied tot he proxy.
45      */

46     private static final Class JavaDoc[] INTERFACES = {MBeanServer JavaDoc.class};
47
48     /**
49      * Creates a new instance of RemoteMBeanServerProxy.
50      *
51      * @param remoteServer the remote server to proxy
52      */

53     public RemoteMBeanServerProxy(RemoteMBeanServer remoteServer) {
54         this.remoteServer = remoteServer;
55     }
56
57     /**
58      * Handles invokation of methods.
59      *
60      * @param proxy proxy being invoked
61      * @param m method being invoked
62      * @param args arguments passed to the method
63      * @return the result of the invocation
64      * @throws Throwable indicates an error in the invocation
65      */

66     protected Object JavaDoc handleInvoke(
67         Object JavaDoc proxy, Method JavaDoc m, Object JavaDoc[] args)
68     throws Throwable JavaDoc {
69
70         Class JavaDoc serverClass =
71             RemoteMBeanServer.class; // this.remoteServer.getClass();
72

73         Method JavaDoc method =
74             serverClass.getMethod(m.getName(), m.getParameterTypes());
75
76         return method.invoke(this.remoteServer, args);
77     }
78
79     /**
80      * Builds a dynamic proxy around the RemoteMBeanServer.
81      *
82      * @param server server to build the proxy around
83      * @return the proxied server
84      */

85     public static MBeanServer JavaDoc buildServerProxy(RemoteMBeanServer server) {
86         Object JavaDoc proxy =
87             Proxy.newProxyInstance(
88                 RemoteMBeanServerProxy.class.getClassLoader(),
89                 RemoteMBeanServerProxy.INTERFACES,
90                 new RemoteMBeanServerProxy(server));
91
92         return (MBeanServer JavaDoc) proxy;
93     }
94 }
95
Popular Tags