private static void check(String what, MBeanNotificationInfo[] mbnis) { System.out.print(what + ": checking notification info: "); if (mbnis.length == 0) { System.out.println("NONE (suspicious)"); suspicious.add(what); return; } // Each MBeanNotificationInfo.getName() should be an existent // Java class that is Notification or a subclass of it for (int j = 0; j < mbnis.length; j++) { String notifClassName = mbnis[j].getName(); Class notifClass; try { notifClass = Class.forName(notifClassName); } catch (Exception e) { System.out.print("FAILED(" + notifClassName + ": " + e + ") "); failed.add(what); continue; } if (!Notification.class.isAssignableFrom(notifClass)) { System.out.print("FAILED(" + notifClassName + ": not a Notification) "); failed.add(what); continue; } System.out.print("OK(" + notifClassName + ") "); } System.out.println(); }
private static void scanDir(File dir, String prefix, Set<String> names) throws Exception { File[] files = dir.listFiles(); if (files == null) return; for (int i = 0; i < files.length; i++) { File f = files[i]; String name = f.getName(); String p = (prefix.equals("")) ? name : prefix + "." + name; if (f.isDirectory()) scanDir(f, p, names); else if (name.endsWith(".class")) { p = p.substring(0, p.length() - 6); names.add(p); } } }
private static Set<String> findStandardMBeansFromJar(URL codeBase) throws Exception { InputStream is = codeBase.openStream(); JarInputStream jis = new JarInputStream(is); Set<String> names = new TreeSet<String>(); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { String name = entry.getName(); if (!name.endsWith(".class")) continue; name = name.substring(0, name.length() - 6); name = name.replace('/', '.'); names.add(name); } return names; }
private static String[] findStandardMBeans(URL codeBase) throws Exception { Set<String> names; if (codeBase.getProtocol().equalsIgnoreCase("file") && codeBase.toString().endsWith("/")) names = findStandardMBeansFromDir(codeBase); else names = findStandardMBeansFromJar(codeBase); Set<String> standardMBeanNames = new TreeSet<String>(); for (String name : names) { if (name.endsWith("MBean")) { String prefix = name.substring(0, name.length() - 5); if (names.contains(prefix)) standardMBeanNames.add(prefix); } } return standardMBeanNames.toArray(new String[0]); }