01: /*
02: * $Id: JMXProxyHandler.java 674 2006-10-06 12:15:59Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.client.remote;
15:
16: import javax.management.MBeanServerConnection;
17: import javax.management.ObjectName;
18: import java.lang.reflect.InvocationHandler;
19: import java.lang.reflect.Method;
20: import java.lang.reflect.UndeclaredThrowableException;
21: import java.util.ArrayList;
22:
23: /**
24: * Proxy to a remote controller session bean.
25: */
26: class JMXProxyHandler implements InvocationHandler {
27: private MBeanServerConnection connection;
28: private ObjectName controllerName;
29:
30: JMXProxyHandler(MBeanServerConnection connection,
31: ObjectName controllerName) {
32: this .connection = connection;
33: this .controllerName = controllerName;
34: }
35:
36: public Object invoke(Object proxy, Method method, Object[] args)
37: throws Throwable {
38: String methodName = method.getName();
39: Class[] sigTypes = method.getParameterTypes();
40: ArrayList sigStrings = new ArrayList();
41: for (int s = 0; s < sigTypes.length; s++)
42: sigStrings.add(sigTypes[s].getName());
43: String[] sig = new String[sigTypes.length];
44: sigStrings.toArray(sig);
45: Object value = null;
46: try {
47: value = connection.invoke(controllerName, methodName, args,
48: sig);
49: } catch (UndeclaredThrowableException e) {
50: System.out.println("getUndeclaredThrowable: "
51: + e.getUndeclaredThrowable());
52: throw e.getUndeclaredThrowable();
53: }
54: return value;
55: }
56: }
|