equal
deleted
inserted
replaced
72 import javax.management.openmbean.OpenType; |
72 import javax.management.openmbean.OpenType; |
73 import javax.management.openmbean.SimpleType; |
73 import javax.management.openmbean.SimpleType; |
74 import javax.management.openmbean.TabularData; |
74 import javax.management.openmbean.TabularData; |
75 import javax.management.openmbean.TabularDataSupport; |
75 import javax.management.openmbean.TabularDataSupport; |
76 import javax.management.openmbean.TabularType; |
76 import javax.management.openmbean.TabularType; |
|
77 import sun.reflect.misc.MethodUtil; |
|
78 import sun.reflect.misc.ReflectUtil; |
77 |
79 |
78 /** |
80 /** |
79 * <p>A converter between Java types and the limited set of classes |
81 * <p>A converter between Java types and the limited set of classes |
80 * defined by Open MBeans.</p> |
82 * defined by Open MBeans.</p> |
81 * |
83 * |
297 throw new OpenDataException("Cannot map type: " + objType); |
299 throw new OpenDataException("Cannot map type: " + objType); |
298 } |
300 } |
299 |
301 |
300 private static <T extends Enum<T>> MXBeanMapping |
302 private static <T extends Enum<T>> MXBeanMapping |
301 makeEnumMapping(Class<?> enumClass, Class<T> fake) { |
303 makeEnumMapping(Class<?> enumClass, Class<T> fake) { |
|
304 ReflectUtil.checkPackageAccess(enumClass); |
302 return new EnumMapping<T>(Util.<Class<T>>cast(enumClass)); |
305 return new EnumMapping<T>(Util.<Class<T>>cast(enumClass)); |
303 } |
306 } |
304 |
307 |
305 /* Make the converter for an array type, or a collection such as |
308 /* Make the converter for an array type, or a collection such as |
306 * List<String> or Set<Integer>. We never see one-dimensional |
309 * List<String> or Set<Integer>. We never see one-dimensional |
421 // an item in the computed CompositeType. |
424 // an item in the computed CompositeType. |
422 final boolean gcInfoHack = |
425 final boolean gcInfoHack = |
423 (c.getName().equals("com.sun.management.GcInfo") && |
426 (c.getName().equals("com.sun.management.GcInfo") && |
424 c.getClassLoader() == null); |
427 c.getClassLoader() == null); |
425 |
428 |
|
429 ReflectUtil.checkPackageAccess(c); |
426 final List<Method> methods = |
430 final List<Method> methods = |
427 MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods())); |
431 MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods())); |
428 final SortedMap<String,Method> getterMap = newSortedMap(); |
432 final SortedMap<String,Method> getterMap = newSortedMap(); |
429 |
433 |
430 /* Select public methods that look like "T getX()" or "boolean |
434 /* Select public methods that look like "T getX()" or "boolean |
826 return null; |
830 return null; |
827 |
831 |
828 Object[] values = new Object[getters.length]; |
832 Object[] values = new Object[getters.length]; |
829 for (int i = 0; i < getters.length; i++) { |
833 for (int i = 0; i < getters.length; i++) { |
830 try { |
834 try { |
831 Object got = getters[i].invoke(value, (Object[]) null); |
835 Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); |
832 values[i] = getterMappings[i].toOpenValue(got); |
836 values[i] = getterMappings[i].toOpenValue(got); |
833 } catch (Exception e) { |
837 } catch (Exception e) { |
834 throw openDataException("Error calling getter for " + |
838 throw openDataException("Error calling getter for " + |
835 itemNames[i] + ": " + e, e); |
839 itemNames[i] + ": " + e, e); |
836 } |
840 } |
1009 final Object fromCompositeData(CompositeData cd, |
1013 final Object fromCompositeData(CompositeData cd, |
1010 String[] itemNames, |
1014 String[] itemNames, |
1011 MXBeanMapping[] converters) |
1015 MXBeanMapping[] converters) |
1012 throws InvalidObjectException { |
1016 throws InvalidObjectException { |
1013 try { |
1017 try { |
1014 return fromMethod.invoke(null, cd); |
1018 return MethodUtil.invoke(fromMethod, null, new Object[] {cd}); |
1015 } catch (Exception e) { |
1019 } catch (Exception e) { |
1016 final String msg = "Failed to invoke from(CompositeData)"; |
1020 final String msg = "Failed to invoke from(CompositeData)"; |
1017 throw invalidObjectException(msg, e); |
1021 throw invalidObjectException(msg, e); |
1018 } |
1022 } |
1019 } |
1023 } |
1105 String[] itemNames, |
1109 String[] itemNames, |
1106 MXBeanMapping[] converters) |
1110 MXBeanMapping[] converters) |
1107 throws InvalidObjectException { |
1111 throws InvalidObjectException { |
1108 Object o; |
1112 Object o; |
1109 try { |
1113 try { |
1110 o = getTargetClass().newInstance(); |
1114 final Class<?> targetClass = getTargetClass(); |
|
1115 ReflectUtil.checkPackageAccess(targetClass); |
|
1116 o = targetClass.newInstance(); |
1111 for (int i = 0; i < itemNames.length; i++) { |
1117 for (int i = 0; i < itemNames.length; i++) { |
1112 if (cd.containsKey(itemNames[i])) { |
1118 if (cd.containsKey(itemNames[i])) { |
1113 Object openItem = cd.get(itemNames[i]); |
1119 Object openItem = cd.get(itemNames[i]); |
1114 Object javaItem = |
1120 Object javaItem = |
1115 converters[i].fromOpenValue(openItem); |
1121 converters[i].fromOpenValue(openItem); |
1116 setters[i].invoke(o, javaItem); |
1122 MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); |
1117 } |
1123 } |
1118 } |
1124 } |
1119 } catch (Exception e) { |
1125 } catch (Exception e) { |
1120 throw invalidObjectException(e); |
1126 throw invalidObjectException(e); |
1121 } |
1127 } |
1361 if (index >= 0) |
1367 if (index >= 0) |
1362 params[index] = javaItem; |
1368 params[index] = javaItem; |
1363 } |
1369 } |
1364 |
1370 |
1365 try { |
1371 try { |
|
1372 ReflectUtil.checkPackageAccess(max.constructor.getDeclaringClass()); |
1366 return max.constructor.newInstance(params); |
1373 return max.constructor.newInstance(params); |
1367 } catch (Exception e) { |
1374 } catch (Exception e) { |
1368 final String msg = |
1375 final String msg = |
1369 "Exception constructing " + getTargetClass().getName(); |
1376 "Exception constructing " + getTargetClass().getName(); |
1370 throw invalidObjectException(msg, e); |
1377 throw invalidObjectException(msg, e); |