01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.proxy;
09:
10: import java.lang.reflect.InvocationHandler;
11: import java.lang.reflect.Method;
12: import javax.management.ObjectName;
13: import javax.management.MBeanServer;
14: import javax.management.MBeanException;
15: import javax.management.ReflectionException;
16:
17: /**
18: * InvocationHandler delegate the MBeanServer invoke the actually operation
19: *
20: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
21: */
22:
23: public class MBeanInvocationHandler implements InvocationHandler {
24: private MBeanServer server = null;
25: private ObjectName objectName = null;
26:
27: public MBeanInvocationHandler(MBeanServer server,
28: ObjectName objectName) {
29: this .server = server;
30: this .objectName = objectName;
31: }
32:
33: public Object invoke(Object proxy, Method method, Object[] args)
34: throws Throwable {
35: if (args == null)
36: args = new Object[0];
37: Class[] types = method.getParameterTypes();
38: String[] signature = new String[types.length];
39: for (int i = 0; i < types.length; i++) {
40: signature[i] = types[i].getName();
41: }
42: try {
43: return server.invoke(objectName, method.getName(), args,
44: signature);
45: } catch (MBeanException e) {
46: throw e.getTargetException();
47: } catch (ReflectionException e) {
48: throw e.getTargetException();
49: }
50: }
51:
52: }
|