Index: modules/logging/src/main/java/java/util/logging/LogManager.java =================================================================== --- modules/logging/src/main/java/java/util/logging/LogManager.java (revision 499728) +++ modules/logging/src/main/java/java/util/logging/LogManager.java (working copy) @@ -29,8 +29,16 @@ import java.util.Collection; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; import java.util.Properties; +import java.util.Set; import java.util.StringTokenizer; +import java.lang.management.ManagementFactory; +import java.lang.reflect.Method; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.ObjectInstance; +import javax.management.MalformedObjectNameException; import org.apache.harmony.logging.internal.nls.Messages; @@ -154,9 +162,36 @@ */ public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; //$NON-NLS-1$ + /** + * Get the LoggingMXBean instance + * + * @return the LoggingMXBean instance + */ public static LoggingMXBean getLoggingMXBean() { - // logging.0=This method is not currently implemented. - throw new AssertionError(Messages.getString("logging.0")); //$NON-NLS-1$ + try { + ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME); + MBeanServer platformBeanServer = ManagementFactory.getPlatformMBeanServer(); + Set loggingMXBeanSet = platformBeanServer.queryMBeans(loggingMXBeanName, null); + + if(loggingMXBeanSet.size() != 1) { + // logging.21=There Can Be Only One logging MX bean. + throw new AssertionError(Messages.getString("logging.21")); + } + + Iterator i = loggingMXBeanSet.iterator(); + ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next(); + String lmxbcn = loggingMXBeanOI.getClassName(); + Class lmxbc = Class.forName(lmxbcn); + Method giMethod = lmxbc.getDeclaredMethod("getInstance"); + giMethod.setAccessible(true); + LoggingMXBean lmxb = (LoggingMXBean) giMethod.invoke(null, new Object[] {}); + + return lmxb; + } catch (Exception e) { + e.printStackTrace(); + } + // logging.22=Exception occurred while getting the logging MX bean. + throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$ } /* * ------------------------------------------------------------------- Index: modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties =================================================================== --- modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties (revision 499728) +++ modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties (working copy) @@ -35,6 +35,8 @@ logging.1F=Exception - {0} logging.2=The OutputStream parameter is null logging.20=Loading class "{0}" failed +logging.21=There Can Be Only One logging MX bean. +logging.22=Exception occurred while getting the logging MX bean. logging.3=The Formatter parameter is null. logging.4=The 'level' parameter is null. logging.5=Different version - {0}.{1}