MBeans { private static List<Object> getConvertedAttributes(List<String> mbeanAttributes) { initJRockitMBeansIfNeeded(); final List<Object> result = new ArrayList<Object>(); final List<MBeanServer> mBeanServers = getMBeanServers(); for (final String mbeansAttribute : mbeanAttributes) { final int lastIndexOfPoint = mbeansAttribute.lastIndexOf('.'); if (lastIndexOfPoint <= 0) { throw new IllegalArgumentException(mbeansAttribute); } final String name = mbeansAttribute.substring(0, lastIndexOfPoint); final String attribute = mbeansAttribute.substring(lastIndexOfPoint + 1); if ("password".equalsIgnoreCase(attribute)) { throw new IllegalArgumentException(name + '.' + attribute); } InstanceNotFoundException instanceNotFoundException = null; for (final MBeanServer mbeanServer : mBeanServers) { try { final MBeans mbeans = new MBeans(mbeanServer); final Object jmxValue = mbeans.convertValueIfNeeded( mbeans.getAttribute(new ObjectName(name), attribute)); result.add(jmxValue); instanceNotFoundException = null; break; } catch (final InstanceNotFoundException e) { instanceNotFoundException = e; continue; } catch (final JMException e) { throw new IllegalArgumentException(name + '.' + attribute, e); } } if (instanceNotFoundException != null) { throw new IllegalArgumentException(name + '.' + attribute, instanceNotFoundException); } } return result; } MBeans(); private  MBeans(MBeanServer mbeanServer); static List<MBeanNode> getAllMBeanNodes(); static String getConvertedAttributes(String jmxValueParameter); static MBeanServer getPlatformMBeanServer(); static final char ATTRIBUTES_SEPARATOR; }
@Test public void testGetConvertedAttribute() { final String firstMBean = mbeansList.get(0).toString(); final String message = "getConvertedAttributes"; assertNotNull(message, MBeans.getConvertedAttributes(firstMBean + ".maxThreads")); assertNotNull(message, MBeans .getConvertedAttributes(firstMBean + ".maxThreads|" + firstMBean + ".maxThreads")); assertNotNull(message, MBeans.getConvertedAttributes(firstMBean + ".intArrayAsInJRockit")); assertNotNull(message, MBeans.getConvertedAttributes(firstMBean + ".doubleArrayAsInJRockit")); try { MBeans.getConvertedAttributes("Catalina:type=instanceNotFound.maxThreads"); } catch (final IllegalArgumentException e) { assertNotNull("e", e); } try { MBeans.getConvertedAttributes("n'importe quoi.maxThreads"); } catch (final IllegalArgumentException e) { assertNotNull("e", e); } try { MBeans.getConvertedAttributes(firstMBean + ".Password"); } catch (final IllegalArgumentException e) { assertNotNull("e", e); } try { MBeans.getConvertedAttributes("noAttribute"); } catch (final IllegalArgumentException e) { assertNotNull("e", e); } }