This overrides some methods in StandardMBean for the lang.management beans so they return open types. Also contains a few bug fixes.
Changelog:
2006-08-05 Andrew John Hughes <[EMAIL PROTECTED]>
* gnu/java/lang/management/BeanImpl.java:
(cacheMBeanInfo(MBeanInfo)): Override given MBeanInfo
with open variant.
(getCachedMBeanInfo()): Return open variant.
(getMBeanInfo()): Likewise.
(getTypeFromClass(Class)): Implemented.
(translateSignature(MBeanParameterInfo)): Likewise.
(translate(String)): Likewise.
* javax/management/StandardMBean.java:
(getMBeanInfo()): Return attribute names with capital letters,
as in docs for java.lang.management.ManagementFactory, and
ensure descriptions are not "".
* javax/management/openmbean/OpenMBeanConstructorInfoSupport.java,
* javax/management/openmbean/OpenMBeanInfoSupport.java,
* javax/management/openmbean/OpenMBeanOperationInfoSupport.java:
(toString()): Use Arrays.toString().
* javax/management/openmbean/OpenMBeanParameterInfoSupport.java:
(OpenMBeanParameterInfoSupport(String, String, OpenType)):
Set open type here rather than in other constructors.
--
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/java/lang/management/BeanImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/lang/management/BeanImpl.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 BeanImpl.java
--- gnu/java/lang/management/BeanImpl.java 29 Jul 2006 14:05:59 -0000
1.2
+++ gnu/java/lang/management/BeanImpl.java 5 Aug 2006 18:01:07 -0000
@@ -39,9 +39,40 @@ package gnu.java.lang.management;
import java.lang.management.ManagementPermission;
+import java.lang.reflect.Method;
+import java.lang.reflect.TypeVariable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MBeanInfo;
import javax.management.NotCompliantMBeanException;
import javax.management.StandardMBean;
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
+import javax.management.openmbean.OpenMBeanConstructorInfo;
+import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
+import javax.management.openmbean.OpenMBeanInfo;
+import javax.management.openmbean.OpenMBeanInfoSupport;
+import javax.management.openmbean.OpenMBeanOperationInfo;
+import javax.management.openmbean.OpenMBeanOperationInfoSupport;
+import javax.management.openmbean.OpenMBeanParameterInfo;
+import javax.management.openmbean.OpenMBeanParameterInfoSupport;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularType;
+
/**
* A common superclass for bean implementations.
*
@@ -51,7 +82,12 @@ import javax.management.StandardMBean;
public class BeanImpl
extends StandardMBean
{
-
+
+ /**
+ * Cached open bean information.
+ */
+ private OpenMBeanInfo openInfo;
+
/**
* Constructs a new <code>BeanImpl</code>.
*
@@ -67,6 +103,71 @@ public class BeanImpl
super(iface);
}
+ protected void cacheMBeanInfo(MBeanInfo info)
+ {
+ if (info == null)
+ return;
+ try
+ {
+ MBeanAttributeInfo[] oldA = info.getAttributes();
+ OpenMBeanAttributeInfo[] attribs =
+ new OpenMBeanAttributeInfoSupport[oldA.length];
+ for (int a = 0; a < oldA.length; ++a)
+ {
+ OpenMBeanParameterInfo param = translate(oldA[a].getType());
+ if (param.getMinValue() == null)
+ {
+ Object[] lv;
+ if (param.getLegalValues() == null)
+ lv = null;
+ else
+ lv = param.getLegalValues().toArray();
+ attribs[a] = new
OpenMBeanAttributeInfoSupport(oldA[a].getName(),
+
oldA[a].getDescription(),
+
param.getOpenType(),
+
oldA[a].isReadable(),
+
oldA[a].isWritable(),
+ oldA[a].isIs(),
+
param.getDefaultValue(),
+ lv);
+ }
+ else
+ attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
+
oldA[a].getDescription(),
+
param.getOpenType(),
+
oldA[a].isReadable(),
+
oldA[a].isWritable(),
+ oldA[a].isIs(),
+
param.getDefaultValue(),
+
param.getMinValue(),
+
param.getMaxValue());
+ }
+ MBeanConstructorInfo[] oldC = info.getConstructors();
+ OpenMBeanConstructorInfo[] cons = new
OpenMBeanConstructorInfoSupport[oldC.length];
+ for (int a = 0; a < oldC.length; ++a)
+ cons[a] =
+ new OpenMBeanConstructorInfoSupport(oldC[a].getName(),
+ oldC[a].getDescription(),
+
translateSignature(oldC[a].getSignature()));
+ MBeanOperationInfo[] oldO = info.getOperations();
+ OpenMBeanOperationInfo[] ops = new
OpenMBeanOperationInfoSupport[oldO.length];
+ for (int a = 0; a < oldO.length; ++a)
+ ops[a] =
+ new OpenMBeanOperationInfoSupport(oldO[a].getName(),
+ oldO[a].getDescription(),
+
translateSignature(oldO[a].getSignature()),
+
translate(oldO[a].getReturnType()).getOpenType(),
+ oldO[a].getImpact());
+ openInfo = new OpenMBeanInfoSupport(info.getClassName(),
info.getDescription(),
+ attribs, cons, ops,
info.getNotifications());
+ }
+ catch (OpenDataException e)
+ {
+ throw (InternalError) (new InternalError("A problem occurred creating
the open type " +
+ "descriptors.").initCause(e));
+ }
+ }
+
protected void checkMonitorPermissions()
{
SecurityManager sm = System.getSecurityManager();
@@ -81,4 +182,219 @@ public class BeanImpl
sm.checkPermission(new ManagementPermission("control"));
}
+ protected MBeanInfo getCachedMBeanInfo()
+ {
+ return (MBeanInfo) openInfo;
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ super.getMBeanInfo();
+ return getCachedMBeanInfo();
+ }
+
+ private OpenType getTypeFromClass(Class c)
+ throws OpenDataException
+ {
+ return translate(c.getName()).getOpenType();
+ }
+
+ private OpenMBeanParameterInfo[] translateSignature(MBeanParameterInfo[]
oldS)
+ throws OpenDataException
+ {
+ OpenMBeanParameterInfo[] sig = new
OpenMBeanParameterInfoSupport[oldS.length];
+ for (int a = 0; a < oldS.length; ++a)
+ {
+ OpenMBeanParameterInfo param = translate(oldS[a].getType());
+ if (param.getMinValue() == null)
+ {
+ Object[] lv;
+ if (param.getLegalValues() == null)
+ lv = null;
+ else
+ lv = param.getLegalValues().toArray();
+ sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
+ oldS[a].getDescription(),
+ param.getOpenType(),
+ param.getDefaultValue(),
+ lv);
+ }
+ else
+ sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
+ oldS[a].getDescription(),
+ param.getOpenType(),
+ param.getDefaultValue(),
+ param.getMinValue(),
+ param.getMaxValue());
+ }
+ return sig;
+ }
+
+ private OpenMBeanParameterInfo translate(String type)
+ throws OpenDataException
+ {
+ if (type.equals("boolean") || type.equals(Boolean.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.BOOLEAN,
+ null,
+ new Object[] {
+ Boolean.TRUE,
+ Boolean.FALSE
+ });
+ if (type.equals("byte") || type.equals(Byte.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.BYTE,
+ null,
+ Byte.valueOf(Byte.MIN_VALUE),
+ Byte.valueOf(Byte.MAX_VALUE));
+ if (type.equals("char") || type.equals(Character.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.CHARACTER,
+ null,
+
Character.valueOf(Character.MIN_VALUE),
+
Character.valueOf(Character.MAX_VALUE));
+ if (type.equals("double") || type.equals(Double.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.DOUBLE,
+ null,
+ Double.valueOf(Double.MIN_VALUE),
+
Double.valueOf(Double.MAX_VALUE));
+ if (type.equals("float") || type.equals(Float.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.FLOAT,
+ null,
+ Float.valueOf(Float.MIN_VALUE),
+ Float.valueOf(Float.MAX_VALUE));
+ if (type.equals("int") || type.equals(Integer.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.INTEGER,
+ null,
+
Integer.valueOf(Integer.MIN_VALUE),
+
Integer.valueOf(Integer.MAX_VALUE));
+ if (type.equals("long") || type.equals(Long.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.LONG,
+ null,
+ Long.valueOf(Long.MIN_VALUE),
+ Long.valueOf(Long.MAX_VALUE));
+ if (type.equals("short") || type.equals(Short.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.SHORT,
+ null,
+ Short.valueOf(Short.MIN_VALUE),
+ Short.valueOf(Short.MAX_VALUE));
+ if (type.equals(String.class.getName()))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.STRING);
+ if (type.equals("void"))
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.VOID);
+ Class c;
+ try
+ {
+ c = Class.forName(type);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new InternalError("The class for a type used in a management bean
" +
+ "could not be loaded.");
+ }
+ if (c.isEnum())
+ {
+ Object[] values = c.getEnumConstants();
+ String[] names = new String[values.length];
+ for (int a = 0; a < values.length; ++a)
+ names[a] = values[a].toString();
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ SimpleType.STRING,
+ null,
+ (Object[]) names);
+ }
+ try
+ {
+ c.getMethod("from", new Class[] { CompositeData.class });
+ Method[] methods = c.getMethods();
+ List names = new ArrayList();
+ List types = new ArrayList();
+ for (int a = 0; a < methods.length; ++a)
+ {
+ String name = methods[a].getName();
+ if (name.startsWith("get"))
+ {
+ names.add(name.substring(3));
+ types.add(getTypeFromClass(methods[a].getReturnType()));
+ }
+ }
+ String[] fields = (String[]) names.toArray();
+ CompositeType ctype = new CompositeType(c.getName(), c.getName(),
+ fields, fields,
+ (OpenType[]) types.toArray());
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ ctype);
+ }
+ catch (NoSuchMethodException e)
+ {
+ /* Ignored; we expect this if this isn't a from(CompositeData) class */
+ }
+ if (Map.class.isAssignableFrom(c))
+ {
+ OpenType k = SimpleType.VOID;
+ OpenType v = SimpleType.VOID;
+ TypeVariable[] vars = c.getTypeParameters();
+ for (int a = 0; a < vars.length; ++a)
+ {
+ if (vars[a].getName().equals("K"))
+ k = getTypeFromClass((Class) vars[a].getGenericDeclaration());
+ if (vars[a].getName().equals("V"))
+ v = getTypeFromClass((Class) vars[a].getGenericDeclaration());
+ }
+ CompositeType ctype = new CompositeType(Map.class.getName(),
Map.class.getName(),
+ new String[] { "key", "value" },
+ new String[] { "Map key", "Map
value"},
+ new OpenType[] { k, v});
+ TabularType ttype = new TabularType(c.getName(), c.getName(), ctype,
+ new String[] { "key" });
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ ttype);
+ }
+ if (List.class.isAssignableFrom(c))
+ {
+ OpenType e = SimpleType.VOID;
+ TypeVariable[] vars = c.getTypeParameters();
+ for (int a = 0; a < vars.length; ++a)
+ {
+ if (vars[a].getName().equals("E"))
+ e = getTypeFromClass((Class) vars[a].getGenericDeclaration());
+ }
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ new ArrayType(1, e)
+ );
+ }
+ if (c.isArray())
+ {
+ int depth;
+ for (depth = 0; c.getName().charAt(depth) == '['; ++depth);
+ OpenType ot = getTypeFromClass(c.getComponentType());
+ return new OpenMBeanParameterInfoSupport("TransParam",
+ "Translated parameter",
+ new ArrayType(depth, ot)
+ );
+ }
+ throw new InternalError("The type used does not have an open type
translation.");
+ }
+
}
Index: javax/management/StandardMBean.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/management/StandardMBean.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 StandardMBean.java
--- javax/management/StandardMBean.java 5 Aug 2006 12:25:51 -0000 1.3
+++ javax/management/StandardMBean.java 5 Aug 2006 18:01:08 -0000
@@ -205,17 +205,13 @@ public class StandardMBean
Method getter;
try
{
- getter = iface.getMethod("get" +
- name.substring(0, 1).toUpperCase() +
- name.substring(1), null);
+ getter = iface.getMethod("get" + name, null);
}
catch (NoSuchMethodException e)
{
try
{
- getter = iface.getMethod("is" +
- name.substring(0, 1).toUpperCase() +
- name.substring(1), null);
+ getter = iface.getMethod("is" + name, null);
}
catch (NoSuchMethodException ex)
{
@@ -564,11 +560,9 @@ public class StandardMBean
Method[] amethods;
String attrib;
if (name.startsWith("is"))
- attrib = name.substring(2,3).toLowerCase()
- + name.substring(3);
+ attrib = name.substring(2);
else
- attrib = name.substring(3,4).toLowerCase()
- + name.substring(4);
+ attrib = name.substring(3);
if (attributes.containsKey(attrib))
amethods = (Method[]) attributes.get(attrib);
else
@@ -583,8 +577,7 @@ public class StandardMBean
methods[a].getParameterTypes().length == 1)
{
Method[] amethods;
- String attrib = name.substring(3,4).toLowerCase()
- + name.substring(4);
+ String attrib = name.substring(3);
if (attributes.containsKey(attrib))
amethods = (Method[]) attributes.get(attrib);
else
@@ -595,7 +588,8 @@ public class StandardMBean
amethods[1] = methods[a];
}
else
- operations.add(new MBeanOperationInfo("", methods[a]));
+ operations.add(new MBeanOperationInfo(methods[a].getName(),
+ methods[a]));
}
List attribs = new ArrayList(attributes.size());
Iterator it = attributes.entrySet().iterator();
@@ -605,7 +599,8 @@ public class StandardMBean
Method[] amethods = (Method[]) entry.getValue();
try
{
- attribs.add(new MBeanAttributeInfo((String) entry.getKey(), "",
+ attribs.add(new MBeanAttributeInfo((String) entry.getKey(),
+ (String) entry.getKey(),
amethods[0], amethods[1]));
}
catch (IntrospectionException e)
@@ -632,7 +627,8 @@ public class StandardMBean
MBeanConstructorInfo[] cinfo = new MBeanConstructorInfo[cons.length];
for (int a = 0; a < cinfo.length; ++a)
{
- MBeanConstructorInfo oldInfo = new MBeanConstructorInfo("", cons[a]);
+ MBeanConstructorInfo oldInfo = new
MBeanConstructorInfo(cons[a].getName(),
+ cons[a]);
String desc = getDescription(oldInfo);
MBeanParameterInfo[] params = oldInfo.getSignature();
MBeanParameterInfo[] pinfo = new MBeanParameterInfo[params.length];
@@ -665,8 +661,8 @@ public class StandardMBean
oinfo[a] = new MBeanOperationInfo(oldInfo.getName(), desc, pinfo,
oldInfo.getReturnType(), impact);
}
- info = new MBeanInfo(impl.getClass().getName(), "", ainfo, cinfo,
- oinfo, null);
+ info = new MBeanInfo(impl.getClass().getName(), impl.getClass().getName(),
+ ainfo, cinfo, oinfo, null);
String cname = getClassName(info);
String desc = getDescription(info);
info = new MBeanInfo(cname, desc, ainfo, cinfo, oinfo, null);
Index: javax/management/openmbean/OpenMBeanConstructorInfoSupport.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 OpenMBeanConstructorInfoSupport.java
--- javax/management/openmbean/OpenMBeanConstructorInfoSupport.java 2 Aug
2006 21:38:08 -0000 1.1
+++ javax/management/openmbean/OpenMBeanConstructorInfoSupport.java 5 Aug
2006 18:01:08 -0000
@@ -166,7 +166,7 @@ public class OpenMBeanConstructorInfoSup
if (string == null)
string = getClass().getName()
+ "[name=" + getName()
- + ",signature=" + getSignature()
+ + ",signature=" + Arrays.toString(getSignature())
+ "]";
return string;
}
Index: javax/management/openmbean/OpenMBeanInfoSupport.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/OpenMBeanInfoSupport.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 OpenMBeanInfoSupport.java
--- javax/management/openmbean/OpenMBeanInfoSupport.java 2 Aug 2006
21:38:08 -0000 1.1
+++ javax/management/openmbean/OpenMBeanInfoSupport.java 5 Aug 2006
18:01:08 -0000
@@ -180,10 +180,10 @@ public class OpenMBeanInfoSupport
if (string == null)
string = getClass().getName()
+ "[className=" + getClassName()
- + ",attributes=" + getAttributes()
- + ",constructors=" + getConstructors()
- + ",notifications=" + getNotifications()
- + ",operations=" + getOperations()
+ + ",attributes=" + Arrays.toString(getAttributes())
+ + ",constructors=" + Arrays.toString(getConstructors())
+ + ",notifications=" + Arrays.toString(getNotifications())
+ + ",operations=" + Arrays.toString(getOperations())
+ "]";
return string;
}
Index: javax/management/openmbean/OpenMBeanOperationInfoSupport.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/OpenMBeanOperationInfoSupport.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 OpenMBeanOperationInfoSupport.java
--- javax/management/openmbean/OpenMBeanOperationInfoSupport.java 2 Aug
2006 21:38:08 -0000 1.1
+++ javax/management/openmbean/OpenMBeanOperationInfoSupport.java 5 Aug
2006 18:01:08 -0000
@@ -229,7 +229,7 @@ public class OpenMBeanOperationInfoSuppo
}
string = getClass().getName()
+ "[name=" + getName()
- + ",signature=" + getSignature()
+ + ",signature=" + Arrays.toString(getSignature())
+ ",returnOpenType=" + returnOpenType
+ ",impact=" + impactString
+ "]";
Index: javax/management/openmbean/OpenMBeanParameterInfoSupport.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/OpenMBeanParameterInfoSupport.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 OpenMBeanParameterInfoSupport.java
--- javax/management/openmbean/OpenMBeanParameterInfoSupport.java 2 Aug
2006 21:38:08 -0000 1.3
+++ javax/management/openmbean/OpenMBeanParameterInfoSupport.java 5 Aug
2006 18:01:08 -0000
@@ -123,6 +123,7 @@ public class OpenMBeanParameterInfoSuppo
if (desc.length() == 0)
throw new IllegalArgumentException("The description may not be the " +
"empty string.");
+ openType = type;
}
/**
@@ -221,7 +222,6 @@ public class OpenMBeanParameterInfoSuppo
throw new OpenDataException("The default value is greater than the " +
"maximum.");
- openType = type;
this.defaultValue = defaultValue;
minValue = minimumValue;
maxValue = maximumValue;
@@ -295,7 +295,6 @@ public class OpenMBeanParameterInfoSuppo
"of legal values.");
this.legalValues = Collections.unmodifiableSet(lv);
}
- openType = type;
this.defaultValue = defaultValue;
}
signature.asc
Description: Digital signature
