This makes our management beans extend javax.management.StandardMBean,
so they are dynamically exposed.

Changelog:

2006-07-29  Andrew John Hughes  <[EMAIL PROTECTED]>
        
        * gnu/java/lang/management/BeanImpl.java:
        Extended javax.management.StandardMBean.
        * gnu/java/lang/management/ClassLoadingMXBeanImpl.java,
        * gnu/java/lang/management/CompilationMXBeanImpl.java,
        * gnu/java/lang/management/GarbageCollectorMXBeanImpl.java,
        * gnu/java/lang/management/MemoryMXBeanImpl.java,
        * gnu/java/lang/management/MemoryManagerMXBeanImpl.java,
        * gnu/java/lang/management/MemoryPoolMXBeanImpl.java,
        * gnu/java/lang/management/OperatingSystemMXBeanImpl.java,
        * gnu/java/lang/management/RuntimeMXBeanImpl.java,
        * gnu/java/lang/management/ThreadMXBeanImpl.java:
        Call the superclass with the appropriate class.
        * java/lang/management/ManagementFactory.java:
        (getOperatingSystemMXBean()): Catch exception from
        StandardMBean.
        (getRuntimeMXBean()): Likewise.
        (getClassLoadingMXBean()): Likewise.
        (getThreadMXBean()): Likewise.
        (getMemoryMXBean()): Likewise.
        (getCompilationMXBean()): Likewise.
        (getMemoryPoolMXBeans()): Likewise.
        (getMemoryManagerMXBeans()): Likewise.
        (getGarbageCollectorMXBeans()): Likewise.
        * javax/management/MBeanFeatureInfo.java:
        (hashCode()): Fixed to check for null values.

-- 
Andrew :-)

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: gnu/java/lang/management/BeanImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/lang/management/BeanImpl.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 BeanImpl.java
--- gnu/java/lang/management/BeanImpl.java      1 Jul 2006 11:37:59 -0000       
1.1
+++ gnu/java/lang/management/BeanImpl.java      29 Jul 2006 13:59:52 -0000
@@ -39,6 +39,9 @@ package gnu.java.lang.management;
 
 import java.lang.management.ManagementPermission;
 
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
 /**
  * A common superclass for bean implementations.
  *
@@ -46,7 +49,23 @@ import java.lang.management.ManagementPe
  * @since 1.5
  */
 public class BeanImpl
+  extends StandardMBean
 {
+ 
+  /**
+   * Constructs a new <code>BeanImpl</code>.
+   *
+   * @param iface the bean interface being implemented.
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  protected BeanImpl(Class iface)
+    throws NotCompliantMBeanException
+  {
+    super(iface);
+  }
 
   protected void checkMonitorPermissions()
   {
Index: gnu/java/lang/management/ClassLoadingMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/ClassLoadingMXBeanImpl.java,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 ClassLoadingMXBeanImpl.java
--- gnu/java/lang/management/ClassLoadingMXBeanImpl.java        2 Jul 2006 
17:29:10 -0000       1.4
+++ gnu/java/lang/management/ClassLoadingMXBeanImpl.java        29 Jul 2006 
13:59:52 -0000
@@ -39,6 +39,8 @@ package gnu.java.lang.management;
 
 import java.lang.management.ClassLoadingMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about the class loading 
  * behaviour of the current invocation of the virtual
@@ -53,6 +55,20 @@ public final class ClassLoadingMXBeanImp
   implements ClassLoadingMXBean
 {
 
+  /**
+   * Constructs a new <code>ClassLoadingMXBeanImpl</code>.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  public ClassLoadingMXBeanImpl()
+    throws NotCompliantMBeanException
+  {
+    super(ClassLoadingMXBean.class);
+  }
+
   public int getLoadedClassCount()
   {
     return VMClassLoadingMXBeanImpl.getLoadedClassCount();
Index: gnu/java/lang/management/CompilationMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/CompilationMXBeanImpl.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 CompilationMXBeanImpl.java
--- gnu/java/lang/management/CompilationMXBeanImpl.java 2 Jul 2006 20:32:43 
-0000       1.1
+++ gnu/java/lang/management/CompilationMXBeanImpl.java 29 Jul 2006 13:59:52 
-0000
@@ -41,6 +41,8 @@ import gnu.classpath.SystemProperties;
 
 import java.lang.management.CompilationMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about the JIT 
  * compiler of the virtual machine, if one exists.
@@ -67,6 +69,20 @@ public final class CompilationMXBeanImpl
   private static final String COMPILATION_TIME_SUPPORT = 
     "gnu.java.lang.management.CompilationTimeSupport";
 
+  /**
+   * Constructs a new <code>CompilationMXBeanImpl</code>.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  public CompilationMXBeanImpl()
+    throws NotCompliantMBeanException
+  {
+    super(CompilationMXBean.class);
+  }
+
   public String getName()
   {
     return SystemProperties.getProperty(COMPILER_NAME);
Index: gnu/java/lang/management/GarbageCollectorMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/GarbageCollectorMXBeanImpl.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 GarbageCollectorMXBeanImpl.java
--- gnu/java/lang/management/GarbageCollectorMXBeanImpl.java    5 Jul 2006 
21:44:08 -0000       1.1
+++ gnu/java/lang/management/GarbageCollectorMXBeanImpl.java    29 Jul 2006 
13:59:52 -0000
@@ -39,6 +39,8 @@ package gnu.java.lang.management;
 
 import java.lang.management.GarbageCollectorMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about one of the garbage 
  * collectors used by the current invocation of the
@@ -58,10 +60,15 @@ public final class GarbageCollectorMXBea
    * Constructs a new <code>GarbageCollectorMXBeanImpl</code>.
    *
    * @param name the name of the garbage collector this bean represents.
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
    */
   public GarbageCollectorMXBeanImpl(String name)
+    throws NotCompliantMBeanException
   {
-    super(name);
+    super(name, GarbageCollectorMXBean.class);
   }
 
   public long getCollectionCount()
Index: gnu/java/lang/management/MemoryMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/MemoryMXBeanImpl.java,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 MemoryMXBeanImpl.java
--- gnu/java/lang/management/MemoryMXBeanImpl.java      22 Jul 2006 13:36:03 
-0000      1.4
+++ gnu/java/lang/management/MemoryMXBeanImpl.java      29 Jul 2006 13:59:52 
-0000
@@ -47,6 +47,7 @@ import java.util.List;
 
 import javax.management.ListenerNotFoundException;
 import javax.management.MBeanNotificationInfo;
+import javax.management.NotCompliantMBeanException;
 import javax.management.Notification;
 import javax.management.NotificationEmitter;
 import javax.management.NotificationFilter;
@@ -120,9 +121,18 @@ public final class MemoryMXBeanImpl
          }
   }
 
-
+  /**
+   * Constructs a new <code>MemoryMXBeanImpl</code>.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
   public MemoryMXBeanImpl()
+    throws NotCompliantMBeanException
   {
+    super(MemoryMXBean.class);
     listeners = new ArrayList();
     notificationCount = 0;
   }
Index: gnu/java/lang/management/MemoryManagerMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/MemoryManagerMXBeanImpl.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 MemoryManagerMXBeanImpl.java
--- gnu/java/lang/management/MemoryManagerMXBeanImpl.java       5 Jul 2006 
21:44:08 -0000       1.1
+++ gnu/java/lang/management/MemoryManagerMXBeanImpl.java       29 Jul 2006 
13:59:52 -0000
@@ -39,6 +39,8 @@ package gnu.java.lang.management;
 
 import java.lang.management.MemoryManagerMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about one of the memory 
  * managers used by the current invocation of the
@@ -63,9 +65,32 @@ public class MemoryManagerMXBeanImpl
    * Constructs a new <code>MemoryManagerMXBeanImpl</code>.
    *
    * @param name the name of the manager this bean represents.
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
    */
   public MemoryManagerMXBeanImpl(String name)
+    throws NotCompliantMBeanException
+  {
+    this(name, MemoryManagerMXBean.class);
+  }
+
+  /**
+   * Constructs a new <code>MemoryManagerMXBeanImpl</code>
+   * implementing the specified bean interface.
+   *
+   * @param name the name of the manager this bean represents.
+   * @param iface the bean interface being implemented.
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  protected MemoryManagerMXBeanImpl(String name, Class iface)
+    throws NotCompliantMBeanException
   {
+    super(iface);
     this.name = name;
   }
 
Index: gnu/java/lang/management/MemoryPoolMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/MemoryPoolMXBeanImpl.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 MemoryPoolMXBeanImpl.java
--- gnu/java/lang/management/MemoryPoolMXBeanImpl.java  22 Jul 2006 19:59:14 
-0000      1.2
+++ gnu/java/lang/management/MemoryPoolMXBeanImpl.java  29 Jul 2006 13:59:52 
-0000
@@ -42,6 +42,8 @@ import gnu.classpath.SystemProperties;
 import java.lang.management.MemoryPoolMXBean;
 import java.lang.management.MemoryUsage;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about one of the memory 
  * resources or pools used by the current invocation of the
@@ -78,9 +80,15 @@ public final class MemoryPoolMXBeanImpl
    * Constructs a new <code>MemoryPoolMXBeanImpl</code>.
    *
    * @param name the name of the pool this bean represents.
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
    */
   public MemoryPoolMXBeanImpl(String name)
+    throws NotCompliantMBeanException
   {
+    super(MemoryPoolMXBean.class);
     this.name = name;
   }
 
Index: gnu/java/lang/management/OperatingSystemMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/OperatingSystemMXBeanImpl.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 OperatingSystemMXBeanImpl.java
--- gnu/java/lang/management/OperatingSystemMXBeanImpl.java     1 Jul 2006 
11:37:59 -0000       1.2
+++ gnu/java/lang/management/OperatingSystemMXBeanImpl.java     29 Jul 2006 
13:59:52 -0000
@@ -39,6 +39,8 @@ package gnu.java.lang.management;
 
 import java.lang.management.OperatingSystemMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about the underlying operating
  * system.  
@@ -50,7 +52,21 @@ public final class OperatingSystemMXBean
   extends BeanImpl
   implements OperatingSystemMXBean
 {
-  
+
+  /**
+   * Constructs a new <code>OperatingSystemMXBeanImpl</code>.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  public OperatingSystemMXBeanImpl()
+    throws NotCompliantMBeanException
+  {
+    super(OperatingSystemMXBean.class);
+  }
+
   public String getArch()
   {
     return System.getProperty("os.arch");
Index: gnu/java/lang/management/RuntimeMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/RuntimeMXBeanImpl.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 RuntimeMXBeanImpl.java
--- gnu/java/lang/management/RuntimeMXBeanImpl.java     1 Jul 2006 11:37:59 
-0000       1.3
+++ gnu/java/lang/management/RuntimeMXBeanImpl.java     29 Jul 2006 13:59:52 
-0000
@@ -49,6 +49,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about the virtual machine.
  *
@@ -69,6 +71,20 @@ public final class RuntimeMXBeanImpl
 
   private boolean bootClassPathSupported = true;
 
+  /**
+   * Constructs a new <code>RuntimeMXBeanImpl</code>.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
+   */
+  public RuntimeMXBeanImpl()
+    throws NotCompliantMBeanException
+  {
+    super(RuntimeMXBean.class);
+  }
+
   public String getBootClassPath()
   {
     checkMonitorPermissions();
Index: gnu/java/lang/management/ThreadMXBeanImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/lang/management/ThreadMXBeanImpl.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 ThreadMXBeanImpl.java
--- gnu/java/lang/management/ThreadMXBeanImpl.java      2 Jul 2006 17:29:10 
-0000       1.2
+++ gnu/java/lang/management/ThreadMXBeanImpl.java      29 Jul 2006 13:59:52 
-0000
@@ -42,6 +42,8 @@ import gnu.classpath.SystemProperties;
 import java.lang.management.ThreadInfo;
 import java.lang.management.ThreadMXBean;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * Provides access to information about the threads 
  * of the virtual machine.  An instance of this bean is
@@ -96,9 +98,16 @@ public final class ThreadMXBeanImpl
    * Default constructor to set up flag states.  The
    * VM has to specify whether time monitoring is initially
    * enabled or not.
+   *
+   * @throws NotCompliantMBeanException if this class doesn't implement
+   *                                    the interface or a method appears
+   *                                    in the interface that doesn't comply
+   *                                    with the naming conventions.
    */
   public ThreadMXBeanImpl()
+    throws NotCompliantMBeanException
   {
+    super(ThreadMXBean.class);
     timeEnabled = 
Boolean.parseBoolean(SystemProperties.getProperty(TIME_ENABLED));
     contentionEnabled = false;
   }
Index: java/lang/management/ManagementFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/lang/management/ManagementFactory.java,v
retrieving revision 1.11
diff -u -3 -p -u -r1.11 ManagementFactory.java
--- java/lang/management/ManagementFactory.java 11 Jul 2006 20:17:51 -0000      
1.11
+++ java/lang/management/ManagementFactory.java 29 Jul 2006 13:59:53 -0000
@@ -52,6 +52,8 @@ import gnu.java.lang.management.ThreadMX
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.management.NotCompliantMBeanException;
+
 /**
  * <p>
  * Provides access to the system's management beans via a series
@@ -117,7 +119,16 @@ public class ManagementFactory
   public static OperatingSystemMXBean getOperatingSystemMXBean()
   {
     if (osBean == null)
-      osBean = new OperatingSystemMXBeanImpl();
+      try 
+       {
+         osBean = new OperatingSystemMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "operating system bean is not a " +
+                                 "compliant management bean.");
+       }
     return osBean;
   }
 
@@ -131,7 +142,16 @@ public class ManagementFactory
   public static RuntimeMXBean getRuntimeMXBean()
   {
     if (runtimeBean == null)
-      runtimeBean = new RuntimeMXBeanImpl();
+      try
+       {
+         runtimeBean = new RuntimeMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "runtime bean is not a compliant " +
+                                 "management bean.");
+       }
     return runtimeBean;
   }
 
@@ -145,7 +165,16 @@ public class ManagementFactory
   public static ClassLoadingMXBean getClassLoadingMXBean()
   {
     if (classLoadingBean == null)
-      classLoadingBean = new ClassLoadingMXBeanImpl();
+      try
+       {
+         classLoadingBean = new ClassLoadingMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "class loading bean is not a " +
+                                 "compliant management bean.");
+       }
     return classLoadingBean;
   }
 
@@ -159,7 +188,16 @@ public class ManagementFactory
   public static ThreadMXBean getThreadMXBean()
   {
     if (threadBean == null)
-      threadBean = new ThreadMXBeanImpl();
+      try
+       {
+         threadBean = new ThreadMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "thread bean is not a compliant " +
+                                 "management bean.");
+       }
     return threadBean;
   }
 
@@ -173,7 +211,16 @@ public class ManagementFactory
   public static MemoryMXBean getMemoryMXBean()
   {
     if (memoryBean == null)
-      memoryBean = new MemoryMXBeanImpl();
+      try
+       {
+         memoryBean = new MemoryMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "memory bean is not a compliant " +
+                                 "management bean.");
+       }
     return memoryBean;
   }
 
@@ -191,7 +238,16 @@ public class ManagementFactory
   {
     if (compilationBean == null &&
        SystemProperties.getProperty("gnu.java.compiler.name") != null)
-      compilationBean = new CompilationMXBeanImpl();
+      try
+       {
+         compilationBean = new CompilationMXBeanImpl();
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "compilation bean is not a compliant " +
+                                 "management bean.");
+       }
     return compilationBean;
   }
 
@@ -207,7 +263,16 @@ public class ManagementFactory
     List poolBeans = new ArrayList();
     String[] names = VMManagementFactory.getMemoryPoolNames();
     for (int a = 0; a < names.length; ++a)
-      poolBeans.add(new MemoryPoolMXBeanImpl(names[a]));
+      try
+       {
+         poolBeans.add(new MemoryPoolMXBeanImpl(names[a]));
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "memory pool bean, " + a + ", is " +
+                                 "not a compliant management bean.");
+       }
     return poolBeans;
   }
 
@@ -223,7 +288,16 @@ public class ManagementFactory
     List managerBeans = new ArrayList();
     String[] names = VMManagementFactory.getMemoryManagerNames();
     for (int a = 0; a < names.length; ++a)
-      managerBeans.add(new MemoryManagerMXBeanImpl(names[a]));
+      try
+       {
+         managerBeans.add(new MemoryManagerMXBeanImpl(names[a]));
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "memory manager bean, " + a + ", is " +
+                                 "not a compliant management bean.");
+       }
     managerBeans.addAll(getGarbageCollectorMXBeans());
     return managerBeans;
   }
@@ -240,7 +314,17 @@ public class ManagementFactory
     List gcBeans = new ArrayList();
     String[] names = VMManagementFactory.getGarbageCollectorNames();
     for (int a = 0; a < names.length; ++a)
-      gcBeans.add(new GarbageCollectorMXBeanImpl(names[a]));
+      try
+       {
+         gcBeans.add(new GarbageCollectorMXBeanImpl(names[a]));
+       }
+      catch (NotCompliantMBeanException e)
+       {
+         throw new InternalError("The GNU implementation of the " +
+                                 "garbage collector bean, " + a + 
+                                 ", is not a compliant management " +
+                                 "bean.");
+       }
     return gcBeans;
   }
 
Index: javax/management/MBeanFeatureInfo.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/management/MBeanFeatureInfo.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 MBeanFeatureInfo.java
--- javax/management/MBeanFeatureInfo.java      16 Jul 2006 14:35:38 -0000      
1.2
+++ javax/management/MBeanFeatureInfo.java      29 Jul 2006 13:59:53 -0000
@@ -148,7 +148,8 @@ public class MBeanFeatureInfo
    */
   public int hashCode()
   {
-    return name.hashCode() + description.hashCode();
+    return (name == null ? -1 : name.hashCode())
+      + (description == null ? -1 : description.hashCode());
   }
 
 }

Attachment: signature.asc
Description: Digital signature

Reply via email to