This patch adds MXBean support to the fromJava translator (possible now that javax.management.JMX is present). It also corrects a typo so that translation is actually used... and squashes a bug in StandardMBean where the causal hierarchy is broken for a reflected exception.
Changelog: 2007-04-01 Andrew John Hughes <[EMAIL PROTECTED]> * gnu/javax/management/Translator.java: (fromJava(Object[],Method)): Use the array from the parameter not the newly created one... (fromJava(Object, Type)): Support MXBeans. * javax/management/JMX.java: (newMXBeanProxy(MBeanServerConnection,ObjectName,Class)): Call newMXBeanProxy rather than newMBeanProxy. * javax/management/StandardMBean.java: (setAttribute(Attribute)): Use InvocationTargetException as cause. -- Andrew :-) Escape the Java Trap with GNU Classpath! http://www.gnu.org/philosophy/java-trap.html public class gcj extends Freedom implements Java { ... }
Index: gnu/javax/management/Translator.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/javax/management/Translator.java,v retrieving revision 1.2 diff -u -3 -p -u -r1.2 Translator.java --- gnu/javax/management/Translator.java 5 Mar 2007 23:19:44 -0000 1.2 +++ gnu/javax/management/Translator.java 1 Apr 2007 16:26:57 -0000 @@ -39,6 +39,7 @@ package gnu.javax.management; import java.lang.reflect.Array; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; @@ -49,6 +50,9 @@ import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; +import javax.management.JMX; +import javax.management.MBeanServerInvocationHandler; + import javax.management.openmbean.ArrayType; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; @@ -88,7 +92,7 @@ public final class Translator Type[] gtypes = method.getGenericParameterTypes(); Object[] otypes = new Object[jtypes.length]; for (int a = 0; a < jtypes.length; ++a) - jtypes[a] = fromJava(otypes[a], (Class<?>) gtypes[a]); + otypes[a] = fromJava(jtypes[a], (Class<?>) gtypes[a]); return otypes; } @@ -210,7 +214,28 @@ public final class Translator } return data; } - /* FIXME: Handle MXBean and other types */ + if (JMX.isMXBeanInterface(jclass)) + { + try + { + MBeanServerInvocationHandler ih = (MBeanServerInvocationHandler) + Proxy.getInvocationHandler(jtype); + return ih.getObjectName(); + } + catch (IllegalArgumentException e) + { + throw new IllegalArgumentException("For a MXBean to be translated " + + "to an open type, it must be a " + + "proxy.", e); + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("For a MXBean to be translated " + + "to an open type, it must have a " + + "MBeanServerInvocationHandler.", e); + } + } + /* FIXME: Handle other types */ throw new IllegalArgumentException("The type, " + jtype + ", is not convertible."); } Index: javax/management/JMX.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/management/JMX.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 JMX.java --- javax/management/JMX.java 5 Mar 2007 00:22:41 -0000 1.1 +++ javax/management/JMX.java 1 Apr 2007 16:26:58 -0000 @@ -298,7 +298,7 @@ public class JMX public static <T> T newMXBeanProxy(MBeanServerConnection conn, ObjectName name, Class<T> iface) { - return newMBeanProxy(conn, name, iface, false); + return newMXBeanProxy(conn, name, iface, false); } /** Index: javax/management/StandardMBean.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/management/StandardMBean.java,v retrieving revision 1.9 diff -u -3 -p -u -r1.9 StandardMBean.java --- javax/management/StandardMBean.java 28 Mar 2007 21:49:21 -0000 1.9 +++ javax/management/StandardMBean.java 1 Apr 2007 16:26:58 -0000 @@ -874,8 +874,8 @@ public class StandardMBean } catch (InvocationTargetException e) { - throw new MBeanException((Exception) e.getCause(), "The getter of " - + name + " threw an exception"); + throw new MBeanException(e, "The getter of " + name + + " threw an exception"); } }
signature.asc
Description: Digital signature