summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/java/lang/management/BeanImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/lang/management/BeanImpl.java')
-rw-r--r--libjava/classpath/gnu/java/lang/management/BeanImpl.java237
1 files changed, 43 insertions, 194 deletions
diff --git a/libjava/classpath/gnu/java/lang/management/BeanImpl.java b/libjava/classpath/gnu/java/lang/management/BeanImpl.java
index e5b47181273..59e79a550d3 100644
--- a/libjava/classpath/gnu/java/lang/management/BeanImpl.java
+++ b/libjava/classpath/gnu/java/lang/management/BeanImpl.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.java.lang.management;
+import gnu.javax.management.Translator;
+
import java.lang.management.ManagementPermission;
import java.lang.reflect.Array;
@@ -124,7 +126,7 @@ public class BeanImpl
new OpenMBeanAttributeInfoSupport[oldA.length];
for (int a = 0; a < oldA.length; ++a)
{
- OpenMBeanParameterInfo param = translate(oldA[a].getType());
+ OpenMBeanParameterInfo param = Translator.translate(oldA[a].getType());
if (param.getMinValue() == null)
{
Object[] lv;
@@ -134,7 +136,8 @@ public class BeanImpl
lv = param.getLegalValues().toArray();
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
- param.getOpenType(),
+ ((OpenType<Object>)
+ param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
@@ -144,13 +147,16 @@ public class BeanImpl
else
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
- param.getOpenType(),
+ ((OpenType<Object>)
+ param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
param.getDefaultValue(),
- param.getMinValue(),
- param.getMaxValue());
+ ((Comparable<Object>)
+ param.getMinValue()),
+ ((Comparable<Object>)
+ param.getMaxValue()));
}
MBeanConstructorInfo[] oldC = info.getConstructors();
OpenMBeanConstructorInfo[] cons = new OpenMBeanConstructorInfoSupport[oldC.length];
@@ -166,7 +172,7 @@ public class BeanImpl
new OpenMBeanOperationInfoSupport(oldO[a].getName(),
oldO[a].getDescription(),
translateSignature(oldO[a].getSignature()),
- translate(oldO[a].getReturnType()).getOpenType(),
+ Translator.translate(oldO[a].getReturnType()).getOpenType(),
oldO[a].getImpact());
openInfo = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(),
attribs, cons, ops, info.getNotifications());
@@ -201,32 +207,36 @@ public class BeanImpl
return ((Enum) value).name();
Class vClass = value.getClass();
if (vClass.isArray())
- return value;
+ vClass = vClass.getComponentType();
String cName = vClass.getName();
String[] allowedTypes = OpenType.ALLOWED_CLASSNAMES;
for (int a = 0; a < allowedTypes.length; ++a)
if (cName.equals(allowedTypes[a]))
return value;
- if (value instanceof List)
- {
- List l = (List) value;
- Class e = null;
- TypeVariable[] vars = vClass.getTypeParameters();
- for (int a = 0; a < vars.length; ++a)
- if (vars[a].getName().equals("E"))
- e = (Class) vars[a].getGenericDeclaration();
- if (e == null)
- e = Object.class;
- Object[] array = (Object[]) Array.newInstance(e, l.size());
- return l.toArray(array);
- }
OpenMBeanInfo info = (OpenMBeanInfo) getMBeanInfo();
- OpenMBeanAttributeInfo[] attribs =
- (OpenMBeanAttributeInfo[]) info.getAttributes();
+ MBeanAttributeInfo[] attribs =
+ (MBeanAttributeInfo[]) info.getAttributes();
OpenType type = null;
for (int a = 0; a < attribs.length; ++a)
- if (attribs[a].getName().equals("attribute"))
- type = attribs[a].getOpenType();
+ if (attribs[a].getName().equals(attribute))
+ type = ((OpenMBeanAttributeInfo) attribs[a]).getOpenType();
+ if (value instanceof List)
+ {
+ try
+ {
+ Class e =
+ Class.forName(((ArrayType) type).getElementOpenType().getClassName());
+ List l = (List) value;
+ Object[] array = (Object[]) Array.newInstance(e, l.size());
+ return l.toArray(array);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw (InternalError) (new InternalError("The class of the list " +
+ "element type could not " +
+ "be created").initCause(e));
+ }
+ }
if (value instanceof Map)
{
TabularType ttype = (TabularType) type;
@@ -319,19 +329,13 @@ public class BeanImpl
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());
+ OpenMBeanParameterInfo param = Translator.translate(oldS[a].getType());
if (param.getMinValue() == null)
{
Object[] lv;
@@ -341,179 +345,24 @@ public class BeanImpl
lv = param.getLegalValues().toArray();
sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
oldS[a].getDescription(),
- param.getOpenType(),
+ ((OpenType<Object>)
+ param.getOpenType()),
param.getDefaultValue(),
lv);
}
else
sig[a] = new OpenMBeanParameterInfoSupport(oldS[a].getName(),
oldS[a].getDescription(),
- param.getOpenType(),
+ ((OpenType<Object>)
+ param.getOpenType()),
param.getDefaultValue(),
- param.getMinValue(),
- param.getMaxValue());
+ ((Comparable<Object>)
+ param.getMinValue()),
+ ((Comparable<Object>)
+ 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);
- if (type.startsWith("java.util.Map"))
- {
- int lparam = type.indexOf("<");
- int comma = type.indexOf(",", lparam);
- int rparam = type.indexOf(">", comma);
- String key = type.substring(lparam + 1, comma).trim();
- OpenType k = translate(key).getOpenType();
- OpenType v = translate(type.substring(comma + 1, rparam).trim()).getOpenType();
- 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(key, key, ctype,
- new String[] { "key" });
- return new OpenMBeanParameterInfoSupport("TransParam",
- "Translated parameter",
- ttype);
- }
- if (type.startsWith("java.util.List"))
- {
- int lparam = type.indexOf("<");
- int rparam = type.indexOf(">");
- OpenType e = translate(type.substring(lparam + 1, rparam).trim()).getOpenType();
- return new OpenMBeanParameterInfoSupport("TransParam",
- "Translated parameter",
- new ArrayType(1, e)
- );
- }
- Class c;
- try
- {
- c = Class.forName(type);
- }
- catch (ClassNotFoundException e)
- {
- throw (InternalError)
- (new InternalError("The class for a type used in a management bean " +
- "could not be loaded.").initCause(e));
- }
- 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 (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.");
- }
}
OpenPOWER on IntegriCloud