avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/jmx/introspector DefaultDynamicMBean.java DefaultDynamicNotificationMBean.java DynamicMBeanFactory.java
Date Tue, 24 Apr 2001 05:00:53 GMT
donaldp     01/04/23 22:00:53

  Added:       src/java/org/apache/jmx MBeanServerImpl.java
               src/java/org/apache/jmx/adaptor RMIAdaptor.java
                        RMIAdaptorImpl.java
               src/java/org/apache/jmx/introspector
                        DefaultDynamicMBean.java
                        DefaultDynamicNotificationMBean.java
                        DynamicMBeanFactory.java
  Log:
  Commit leos jmx code.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/MBeanServerImpl.java
  
  Index: MBeanServerImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx;
  
  
  import com.sun.management.jmx.*;
  import java.io.ObjectInputStream;
  import java.util.Set;
  import javax.management.*;
  import javax.management.loading.*;
  import javax.management.monitor.*;
  import javax.management.relation.*;
  import javax.management.timer.*;
  
  /**
   * Will become apache's JMX implementation. Currently pointer to sun's reference
   * implementation. Part of the javadocs are from {@link
   * javax.management.MBeanServer}.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/04/24 05:00:51 $
   */
  public class MBeanServerImpl extends com.sun.management.jmx.MBeanServerImpl
  {
      /**
       * Creates an MBeanServer with a standard default domain name. The default
       * domain name is used as the domain part in the ObjectName of MBeans, if no
       * domain is specified by the user. <p>
       *
       * The standard default domain name is defined in {@link
       * com.sun.management.jmx.ServiceName#DOMAIN ServiceName.DOMAIN}
       */
      public MBeanServerImpl()
      {
      }
  
      /**
       * Creates an MBeanServer with the specified default domain name. The
       * default domain name is used as the domain part in the ObjectName of
       * MBeans if no domain is specified by the user.
       *
       * @param domain the domain name
       */
      public MBeanServerImpl( final String domain )
      {
          super( domain );
      }
  
      /**
       * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered with
       * the MBean server.
       *
       * @param name The object name of the MBean.
       * @return The <CODE>ObjectInstance</CODE> associated to the MBean specified
       *      by <VAR>name</VAR> .
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       */
      public ObjectInstance getObjectInstance( final ObjectName name )
          throws InstanceNotFoundException
      {
          return super.getObjectInstance( name );
      }
  
      /**
       * Checks whether an MBean, identified by its object name, is already
       * registered with the MBean server.
       *
       * @param name The object name of the MBean to be checked.
       * @return True if the MBean is already registered in the MBean server,
       *      false otherwise.
       */
      public boolean isRegistered( final ObjectName name )
      {
          return super.isRegistered( name );
      }
  
  
      /**
       * Returns the number of MBeans registered in the MBean server.
       *
       * @return The MBeanCount value
       */
      public Integer getMBeanCount()
      {
          return super.getMBeanCount();
      }
  
      /**
       * Gets the value of a specific attribute of a named MBean. The MBean is
       * identified by its object name.
       *
       * @param name The object name of the MBean from which the attribute is to
       *      be retrieved.
       * @param attribute A String specifying the name of the attribute to be
       *      retrieved.
       * @return The value of the retrieved attribute.
       * @exception AttributeNotFoundException The attribute specified is not
       *      accessible in the MBean.
       * @exception MBeanException Wraps an exception thrown by the MBean's
       *      getter.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE>
       *      thrown when trying to invoke the setter.
       */
      public Object getAttribute( final ObjectName name, final String attribute )
          throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException
      {
          return super.getAttribute( name, attribute );
      }
  
  
      /**
       * Enables the values of several attributes of a named MBean. The MBean is
       * identified by its object name.
       *
       * @param name The object name of the MBean from which the attributes are
       *      retrieved.
       * @param attributes A list of the attributes to be retrieved.
       * @return The list of the retrieved attributes.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception ReflectionException An exception occurred when trying to
       *      invoke the getAttributes method of a Dynamic MBean.
       */
      public AttributeList getAttributes( final ObjectName name, final String[] attributes )
          throws InstanceNotFoundException, ReflectionException
      {
          return super.getAttributes( name, attributes );
      }
  
      /**
       * Returns the default domain used for naming the MBean. The default domain
       * name is used as the domain part in the ObjectName of MBeans if no domain
       * is specified by the user.
       *
       * @return The DefaultDomain value
       */
      public String getDefaultDomain()
      {
          return super.getDefaultDomain();
      }
  
      /**
       * This method discovers the attributes and operations that an MBean exposes
       * for management.
       *
       * @param name The name of the MBean to analyze
       * @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of
       *      all attributes and operations of this MBean.
       * @exception IntrospectionException An exception occurs during
       *      introspection.
       * @exception InstanceNotFoundException The MBean specified is not found.
       * @exception ReflectionException An exception occurred when trying to
       *      invoke the getMBeanInfo of a Dynamic MBean.
       */
      public MBeanInfo getMBeanInfo( final ObjectName name )
          throws
              InstanceNotFoundException, IntrospectionException, ReflectionException
      {
          return super.getMBeanInfo( name );
      }
  
      /**
       * Returns true if the MBean specified is an instance of the specified
       * class, false otherwise.
       *
       * @param name The <CODE>ObjectName</CODE> of the MBean.
       * @param className The name of the class.
       * @return true if the MBean specified is an instance of the specified
       *      class, false otherwise.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       */
      public boolean isInstanceOf( final ObjectName name, final String className )
          throws InstanceNotFoundException
      {
          return super.isInstanceOf( name, className );
      }
  
      /**
       * Instantiates an object using the list of all class loaders registered in
       * the MBean server ({@link javax.management.loading.DefaultLoaderRepository
       * Default Loader Repository}). The object's class should have a public
       * constructor. It returns a reference to the newly created object. The
       * newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       * @return The newly instantiated object.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or the <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      object's constructor.
       * @exception MBeanException The constructor of the object has thrown an
       *      exception
       */
      public Object instantiate( final String className )
          throws ReflectionException, MBeanException
      {
          return super.instantiate( className );
      }
  
      /**
       * Instantiates an object using the class Loader specified by its <CODE>
       * ObjectName</CODE> . If the loader name is null, the ClassLoader that
       * loaded the MBean Server will be used. The object's class should have a
       * public constructor. It returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param loaderName The object name of the class loader to be used.
       * @return The newly instantiated object.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or the <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      object's constructor.
       * @exception MBeanException The constructor of the object has thrown an
       *      exception.
       * @exception InstanceNotFoundException The specified class loader is not
       *      registered in the MBaenServer.
       */
      public Object instantiate( final String className, final ObjectName loaderName )
          throws ReflectionException, MBeanException, InstanceNotFoundException
      {
          return super.instantiate( className, loaderName );
      }
  
      /**
       * Instantiates an object using the list of all class loaders registered in
       * the MBean server ({@link javax.management.loading.DefaultLoaderRepository
       * Default Loader Repository}). The object's class should have a public
       * constructor. The call returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       * @param params An array containing the parameters of the constructor to be
       *      invoked.
       * @param signature An array containing the signature of the constructor to
       *      be invoked.
       * @return The newly instantiated object.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or the <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      object's constructor.
       * @exception MBeanException The constructor of the object has thrown an
       *      exception
       */
      public Object instantiate( final String className, final Object[] params, final String[] signature )
          throws ReflectionException, MBeanException
      {
          return super.instantiate( className, params, signature );
      }
  
      /**
       * Instantiates an object. The class loader to be used is identified by its
       * object name. If the object name of the loader is null, the ClassLoader
       * that loaded the MBean server will be used. The object's class should have
       * a public constructor. The call returns a reference to the newly created
       * object. The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       * @param params An array containing the parameters of the constructor to be
       *      invoked.
       * @param signature An array containing the signature of the constructor to
       *      be invoked.
       * @param loaderName The object name of the class loader to be used.
       * @return The newly instantiated object.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or the <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      object's constructor.
       * @exception MBeanException The constructor of the object has thrown an
       *      exception
       * @exception InstanceNotFoundException The specified class loader is not
       *      registered in the MBean server.
       */
      public Object instantiate( final String className, 
                                 final ObjectName loaderName, 
                                 final Object[] params, 
                                 final String[] signature )
          throws ReflectionException, MBeanException, InstanceNotFoundException
      {
          return super.instantiate( className, loaderName, params, signature );
      }
  
      /**
       * Instantiates and registers an MBean in the MBean server. The MBean server
       * will use the {@link javax.management.loading.DefaultLoaderRepository
       * Default Loader Repository} to load the class of the MBean. An object name
       * is associated to the MBean. If the object name given is null, the MBean
       * can automatically provide its own name by implementing the {@link
       * javax.management.MBeanRegistration MBeanRegistration} interface. The call
       * returns an <CODE>ObjectInstance</CODE> object representing the newly
       * created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @return An <CODE>ObjectInstance</CODE> , containing the <CODE>ObjectName
       *      </CODE>and the Java class name of the newly instantiated MBean.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or a <CODE><CODE>
       *      java.lang.Exception</CODE></CODE> that occurred when trying to
       *      invoke the MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the
       *      control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (
       *      <CODE>MBeanRegistration</CODE> interface) method of the MBean has
       *      thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an
       *      exception
       * @exception NotCompliantMBeanException This class is not a JMX compliant
       *      MBean
       */
      public ObjectInstance createMBean( final String className, final ObjectName name )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException
      {
          return super.createMBean( className, name );
      }
  
      /**
       * Instantiates and registers an MBean in the MBean server. The class loader
       * to be used is identified by its object name. An object name is associated
       * to the MBean. If the object name of the loader is null, the ClassLoader
       * that loaded the MBean server will be used. If the MBean's object name
       * given is null, the MBean can automatically provide its own name by
       * implementing the {@link javax.management.MBeanRegistration
       * MBeanRegistration} interface. The call returns an <CODE>ObjectInstance
       * </CODE>object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param loaderName The object name of the class loader to be used.
       * @return An <CODE>ObjectInstance</CODE> , containing the <CODE>ObjectName
       *      </CODE>and the Java class name of the newly instantiated MBean.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or a <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the
       *      control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (
       *      <CODE>MBeanRegistration</CODE> interface) method of the MBean has
       *      thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an
       *      exception
       * @exception NotCompliantMBeanException This class is not a JMX compliant
       *      MBean
       * @exception InstanceNotFoundException The specified class loader is not
       *      registered in the MBean server.
       */
      public ObjectInstance createMBean( final String className, 
                                         final ObjectName name, 
                                         final ObjectName loaderName )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException
      {
          return super.createMBean( className, name, loaderName );
      }
  
  
      /**
       * Instantiates and registers an MBean in the MBean server. The MBean server
       * will use the {@link javax.management.loading.DefaultLoaderRepository
       * Default Loader Repository} to load the class of the MBean. An object name
       * is associated to the MBean. If the object name given is null, the MBean
       * can automatically provide its own name by implementing the {@link
       * javax.management.MBeanRegistration MBeanRegistration} interface. The call
       * returns an <CODE>ObjectInstance</CODE> object representing the newly
       * created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param params An array containing the parameters of the constructor to be
       *      invoked.
       * @param signature An array containing the signature of the constructor to
       *      be invoked.
       * @return An <CODE>ObjectInstance</CODE> , containing the <CODE>ObjectName
       *      </CODE>and the Java class name of the newly instantiated MBean.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or a <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the
       *      control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (
       *      <CODE>MBeanRegistration</CODE> interface) method of the MBean has
       *      thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an
       *      exception
       * @exception NotCompliantMBeanException thrown if mbean is non-compliant
       */
      public ObjectInstance createMBean( final String className,
                                         final ObjectName name,
                                         final Object[] params,
                                         final String[] signature )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException
      {
          return super.createMBean( className, name, params, signature );
      }
  
      /**
       * Instantiates and registers an MBean in the MBean server. The class loader
       * to be used is identified by its object name. An object name is associated
       * to the MBean. If the object name of the loader is not specified, the
       * ClassLoader that loaded the MBean server will be used. If the MBean
       * object name given is null, the MBean can automatically provide its own
       * name by implementing the {@link javax.management.MBeanRegistration
       * MBeanRegistration} interface. The call returns an <CODE>ObjectInstance
       * </CODE>object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param params An array containing the parameters of the constructor to be
       *      invoked.
       * @param signature An array containing the signature of the constructor to
       *      be invoked.
       * @param loaderName The object name of the class loader to be used.
       * @return An <CODE>ObjectInstance</CODE> , containing the <CODE>ObjectName
       *      </CODE>and the Java class name of the newly instantiated MBean.
       * @exception ReflectionException Wraps a <CODE>
       *      java.lang.ClassNotFoundException</CODE> or a <CODE>
       *      java.lang.Exception</CODE> that occurred when trying to invoke the
       *      MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the
       *      control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (
       *      <CODE>MBeanRegistration</CODE> interface) method of the MBean has
       *      thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an
       *      exception
       * @exception InstanceNotFoundException The specified class loader is not
       *      registered in the MBean server.
       * @exception NotCompliantMBeanException 
       */
      public ObjectInstance createMBean( final String className, 
                                         final ObjectName name, 
                                         final ObjectName loaderName, 
                                         final Object[] params, 
                                         final String[] signature )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException
      {
          return super.createMBean( className, name, loaderName, params, signature );
      }
  
      /**
       * Registers a pre-existing object as an MBean with the MBean server. If the
       * object name given is null, the MBean may automatically provide its own
       * name by implementing the {@link javax.management.MBeanRegistration
       * MBeanRegistration} interface. The call returns an <CODE>ObjectInstance
       * </CODE>object representing the registered MBean.
       *
       * @param object The MBean to be registered as an MBean.
       * @param name The object name of the MBean. May be null.
       * @return The <CODE>ObjectInstance</CODE> for the MBean that has been
       *      registered.
       * @exception InstanceAlreadyExistsException The MBean is already under the
       *      control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (
       *      <CODE>MBeanRegistration</CODE> interface) method of the MBean has
       *      thrown an exception. The MBean will not be registered.
       * @exception NotCompliantMBeanException This object is not a JMX compliant
       *      MBean
       */
      public ObjectInstance registerMBean( final Object object, final ObjectName name )
          throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException
      {
          return super.registerMBean( object, name );
      }
  
      /**
       * De-registers an MBean from the MBean server. The MBean is identified by
       * its object name. Once the method has been invoked, the MBean may no
       * longer be accessed by its object name.
       *
       * @param name The object name of the MBean to be de-registered.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception MBeanRegistrationException The preDeregister (( <CODE>
       *      MBeanRegistration</CODE> interface) method of the MBean has thrown
       *      an exception.
       */
      public void unregisterMBean( final ObjectName name )
          throws InstanceNotFoundException, MBeanRegistrationException
      {
          super.unregisterMBean( name );
      }
  
      /**
       * Gets MBeans controlled by the MBean server. This method allows any of the
       * following to be obtained: All MBeans, a set of MBeans specified by
       * pattern matching on the <CODE>ObjectName</CODE> and/or a Query
       * expression, a specific MBean. When the object name is null or no domain
       * and key properties are specified, all objects are to be selected (and
       * filtered if a query is specified). It returns the set of <CODE>
       * ObjectInstance</CODE> objects (containing the <CODE>ObjectName</CODE> and
       * the Java Class name) for the selected MBeans.
       *
       * @param name The object name pattern identifying the MBeans to be
       *      retrieved. If null or no domain and key properties are specified,
       *      all the MBeans registered will be retrieved.
       * @param query The query expression to be applied for selecting MBeans. If
       *      null no query expression will be applied for selecting MBeans.
       * @return A set containing the <CODE>ObjectInstance</CODE> objects for the
       *      selected MBeans. If no MBean satisfies the query an empty list is
       *      returned.
       */
      public Set queryMBeans( final ObjectName name, final QueryExp query )
      {
          return super.queryMBeans( name, query );
      }
  
      /**
       * Gets the names of MBeans controlled by the MBean server. This method
       * enables any of the following to be obtained: The names of all MBeans, the
       * names of a set of MBeans specified by pattern matching on the <CODE>
       * ObjectName</CODE> and/or a Query expression, a specific MBean name
       * (equivalent to testing whether an MBean is registered). When the object
       * name is null or no domain and key properties are specified, all objects
       * are selected (and filtered if a query is specified). It returns the set
       * of ObjectNames for the MBeans selected.
       *
       * @param name The object name pattern identifying the MBeans to be
       *      retrieved. If null or no domain and key properties are specified,
       *      all the MBeans registered will be retrieved.
       * @param query The query expression to be applied for selecting MBeans. If
       *      null no query expression will be applied for selecting MBeans.
       * @return A set containing the ObjectNames for the MBeans selected. If no
       *      MBean satisfies the query, an empty list is returned.
       */
      public Set queryNames( final ObjectName name, final QueryExp query )
      {
          return super.queryNames( name, query );
      }
  
      /**
       * Invokes an operation on an MBean.
       *
       * @param name The object name of the MBean on which the method is to be
       *      invoked.
       * @param operationName The name of the operation to be invoked.
       * @param params An array containing the parameters to be set when the
       *      operation is invoked
       * @param signature An array containing the signature of the operation. The
       *      class objects will be loaded using the same class loader as the one
       *      used for loading the MBean on which the operation was invoked.
       * @return The object returned by the operation, which represents the result
       *      ofinvoking the operation on the MBean specified.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception MBeanException Wraps an exception thrown by the MBean's
       *      invoked method.
       * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE>
       *      thrown while trying to invoke the method.
       */
      public Object invoke( final ObjectName name, 
                            final String operationName, 
                            final Object[] params,
                            final String[] signature )
          throws InstanceNotFoundException, MBeanException, ReflectionException
      {
          return super.invoke( name, operationName, params, signature );
      }
  
      /**
       * Enables to add a listener to a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be added.
       * @param listener The listener object which will handle the notifications
       *      emitted by the registered MBean.
       * @param filter The filter object. If filter is null, no filtering will be
       *      performed before handling notifications.
       * @param handback The context to be sent to the listener when a
       *      notification is emitted.
       * @exception InstanceNotFoundException The MBean name provided does not
       *      match any of the registered MBeans.
       */
      public void addNotificationListener( final ObjectName name, 
                                           final NotificationListener listener, 
                                           final NotificationFilter filter, 
                                           final Object handback )
          throws InstanceNotFoundException
      {
          super.addNotificationListener( name, listener, filter, handback );
      }
  
      /**
       * Enables to add a listener to a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be added.
       * @param listener The object name of the listener which will handle the
       *      notifications emitted by the registered MBean.
       * @param filter The filter object. If filter is null, no filtering will be
       *      performed before handling notifications.
       * @param handback The context to be sent to the listener when a
       *      notification is emitted.
       * @exception InstanceNotFoundException The MBean name of the notification
       *      listener or of the notification broadcaster does not match any of
       *      the registered MBeans.
       */
      public void addNotificationListener( final ObjectName name, 
                                           final ObjectName listener, 
                                           final NotificationFilter filter, 
                                           final Object handback )
          throws InstanceNotFoundException
      {
          super.addNotificationListener( name, listener, filter, handback );
      }
  
  
      /**
       * Enables to remove a listener from a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be
       *      removed.
       * @param listener The listener object which will handle the notifications
       *      emitted by the registered MBean. This method will remove all the
       *      information related to this listener.
       * @exception InstanceNotFoundException The MBean name provided does not
       *      match any of the registered MBeans.
       * @exception ListenerNotFoundException The listener is not registered in
       *      the MBean.
       */
      public void removeNotificationListener( final ObjectName name, final NotificationListener listener )
          throws InstanceNotFoundException, ListenerNotFoundException
      {
          super.removeNotificationListener( name, listener );
      }
  
      /**
       * Enables to remove a listener from a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be
       *      removed.
       * @param listener The object name of the listener which will handle the
       *      notifications emitted by the registered MBean. This method will
       *      remove all the information related to this listener.
       * @exception InstanceNotFoundException The MBean name provided does not
       *      match any of the registered MBeans.
       * @exception ListenerNotFoundException The listener is not registered in
       *      the MBean.
       */
      public void removeNotificationListener( final ObjectName name, final ObjectName listener )
          throws InstanceNotFoundException, ListenerNotFoundException
      {
          super.removeNotificationListener( name, listener );
      }
  
      /**
       * De-serializes a byte array in the context of the class loader of an
       * MBean.
       *
       * @param name The name of the MBean whose class loader should be used for
       *      the de-serialization.
       * @param data The byte array to be de-sererialized.
       * @return The de-serialized object stream.
       * @exception InstanceNotFoundException The MBean specified is not found.
       * @exception OperationsException Any of the usual Input/Output related
       *      exceptions.
       */
      public ObjectInputStream deserialize( final ObjectName name, final byte[] data )
          throws InstanceNotFoundException, OperationsException
      {
          return super.deserialize( name, data );
      }
  
      /**
       * De-serializes a byte array in the context of a given MBean class loader.
       * The class loader is the one that loaded the class with name "className".
       *
       * @param data The byte array to be de-sererialized.
       * @param className DOC: Insert Description of Parameter
       * @return The de-serialized object stream.
       * @exception OperationsException Any of the usual Input/Output related
       *      exceptions.
       * @exception ReflectionException The specified class could not be loaded by
       *      the default loader repository
       */
      public ObjectInputStream deserialize( final String className, final byte[] data )
          throws OperationsException, ReflectionException
      {
          return super.deserialize( className, data );
      }
  
      /**
       * De-serializes a byte array in the context of a given MBean class loader.
       * The class loader is the one that loaded the class with name "className".
       * The name of the class loader to be used for loading the specified class
       * is specified. If null, the MBean Server's class loader will be used.
       *
       * @param data The byte array to be de-sererialized.
       * @param loaderName The name of the class loader to be used for loading the
       *      specified class. If null, the MBean Server's class loader will be
       *      used.
       * @param className DOC: Insert Description of Parameter
       * @return The de-serialized object stream.
       * @exception InstanceNotFoundException The specified class loader MBean is
       *      not found.
       * @exception OperationsException Any of the usual Input/Output related
       *      exceptions.
       * @exception ReflectionException The specified class could not be loaded by
       *      the specified class loader.
       */
      public ObjectInputStream deserialize( final String className, 
                                            final ObjectName loaderName, 
                                            final byte[] data )
          throws InstanceNotFoundException, OperationsException, ReflectionException
      {
          return super.deserialize( className, loaderName, data );
      }
  
      /**
       * Sets the value of a specific attribute of a named MBean. The MBean is
       * identified by its object name.
       *
       * @param name The name of the MBean within which the attribute is to be
       *      set.
       * @param attribute The identification of the attribute to be set and the
       *      value it is to be set to.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception AttributeNotFoundException The attribute specified is not
       *      accessible in the MBean.
       * @exception InvalidAttributeValueException The value specified for the
       *      attribute is not valid.
       * @exception MBeanException Wraps an exception thrown by the MBean's
       *      setter.
       * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE>
       *      thrown when trying to invoke the setter.
       */
      public void setAttribute( final ObjectName name, final Attribute attribute )
          throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, 
                 MBeanException, ReflectionException
      {
          super.setAttribute( name, attribute );
      }
  
      /**
       * Sets the values of several attributes of a named MBean. The MBean is
       * identified by its object name.
       *
       * @param name The object name of the MBean within which the attributes are
       *      to be set.
       * @param attributes A list of attributes: The identification of the
       *      attributes to be set and the values they are to be set to.
       * @return The list of attributes that were set, with their new values.
       * @exception InstanceNotFoundException The MBean specified is not
       *      registered in the MBean server.
       * @exception ReflectionException An exception occurred when trying to
       *      invoke the getAttributes method of a Dynamic MBean.
       */
      public AttributeList setAttributes( final ObjectName name, final AttributeList attributes )
          throws InstanceNotFoundException, ReflectionException
      {
          return super.setAttributes( name, attributes );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/adaptor/RMIAdaptor.java
  
  Index: RMIAdaptor.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx.adaptor;
  
  import java.io.ObjectInputStream;
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  import java.util.Set;
  import javax.management.*;
  
  /**
   * This is the RMI connection representing an MBeanServer. It is
   * identical to the <code>MBeanServer</code> interface, except
   * it throws exceptions related to remote operations.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   */
  public interface RMIAdaptor 
      extends Remote
  {
      /**
       * Instantiates an object using the list of all class loaders registered
       * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
       * The object's class should have a public constructor.
       * It returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       *
       * @return The newly instantiated object.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the <CODE>java.lang.Exception</CODE> that
       * occurred when trying to invoke the object's constructor.
       * @exception MBeanException The constructor of the object has thrown an exception
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in parameter is null.
       *
       */
      Object instantiate( String className ) 
          throws ReflectionException, MBeanException, RemoteException;
  
      /**
       * Instantiates an object using the class Loader specified by its <CODE>ObjectName</CODE>.
       * If the loader name is null, the ClassLoader that loaded the MBean Server will be used.
       * The object's class should have a public constructor.
       * It returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param loaderName The object name of the class loader to be used.
       *
       * @return The newly instantiated object.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the <CODE>java.lang.Exception</CODE> that
       * occurred when trying to invoke the object's constructor.
       * @exception MBeanException The constructor of the object has thrown an exception.
       * @exception InstanceNotFoundException The specified class loader is not registered in the MBaenServer.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in parameter is null.
       *
       */
      Object instantiate( String className, ObjectName loaderName )
          throws ReflectionException, MBeanException, InstanceNotFoundException, RemoteException;
  
      /**
       * Instantiates an object using the list of all class loaders registered
       * in the MBean server ({@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}).
       * The object's class should have a public constructor.
       * The call returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       * @param params An array containing the parameters of the constructor to be invoked.
       * @param signature An array containing the signature of the constructor to be invoked.
       *
       * @return The newly instantiated object.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the <CODE>java.lang.Exception</CODE> that
       * occurred when trying to invoke the object's constructor.
       * @exception MBeanException The constructor of the object has thrown an exception
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in parameter is null.
       *
       */
      Object instantiate( String className, Object params[], String signature[] )
          throws ReflectionException, MBeanException, RemoteException;
  
      /**
       * Instantiates an object. The class loader to be used is identified by its object
       * name. If the object name of the loader is null, the ClassLoader that loaded the MBean server will be used.
       * The object's class should have a public constructor.
       * The call returns a reference to the newly created object.
       * The newly created object is not registered in the MBean server.
       *
       * @param className The class name of the object to be instantiated.
       * @param params An array containing the parameters of the constructor to be invoked.
       * @param signature An array containing the signature of the constructor to be invoked.
       * @param loaderName The object name of the class loader to be used.
       *
       * @return The newly instantiated object.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or the <CODE>java.lang.Exception</CODE> that
       * occurred when trying to invoke the object's constructor.
       * @exception MBeanException The constructor of the object has thrown an exception
       * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in parameter is null.
       *
       */
      Object instantiate( String className, ObjectName loaderName, Object params[], String signature[] )
          throws ReflectionException, MBeanException, InstanceNotFoundException, RemoteException;
  
      /**
       * Instantiates and registers an MBean in the MBean server.
       * The MBean server will use the {@link javax.management.loading.DefaultLoaderRepository Default Loader Repository}
       * to load the class of the MBean.
       * An object name is associated to the MBean.
       * If the object name given is null, the MBean can automatically provide its
       * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface.
       * The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       *
       * @return  An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
       * of the newly instantiated MBean.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a <CODE><CODE>java.lang.Exception</CODE></CODE> that occurred
       * when trying to invoke the MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> interface) method of the MBean
       * has thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an exception
       * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>:
       * The className passed in parameter is null, the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is specified
       * for the MBean.
       *
       */
      ObjectInstance createMBean( String className, ObjectName name )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException, RemoteException;
  
      /**
       * Instantiates and registers an MBean in the MBean server.
       * The class loader to be used is identified by its object  name. An object name is associated to the MBean.
       * If the object name  of the loader is null, the ClassLoader that loaded the MBean server will be used.
       * If the MBean's object name given is null, the MBean can automatically provide its
       * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface.
       * The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param loaderName The object name of the class loader to be used.
       *
       * @return  An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and the Java class name
       * of the newly instantiated MBean.
       *
       * @exception ReflectionException  Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or a <CODE>java.lang.Exception</CODE> that occurred
       * when trying to invoke the MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE>  interface) method of the MBean
       * has thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an exception
       * @exception NotCompliantMBeanException This class is not a JMX compliant MBean
       * @exception InstanceNotFoundException The specified class loader is not registered in the MBean server.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The className passed in parameter is null,
       * the <CODE>ObjectName</CODE> passed in parameter contains a pattern or no <CODE>ObjectName</CODE> is specified for the MBean.
       */
      ObjectInstance createMBean( String className, ObjectName name, ObjectName loaderName )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException, RemoteException;
  
  
      /**
       * Instantiates and registers an MBean in the MBean server.
       * The MBean server will use the {@link javax.management.loading.DefaultLoaderRepository 
       * Default Loader Repository} to load the class of the MBean.
       * An object name is associated to the MBean.
       * If the object name given is null, the MBean can automatically provide its
       * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface.
       * The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param params An array containing the parameters of the constructor to be invoked.
       * @param signature An array containing the signature of the constructor to be invoked.
       *
       * @return An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> 
       *         and the Java class name of the newly instantiated MBean.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> 
       * or a <CODE>java.lang.Exception</CODE> that occurred
       * when trying to invoke the MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> 
       * (<CODE>MBeanRegistration</CODE>  interface) method of the MBean
       * has thrown an exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an exception
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The className passed in parameter is null, the <CODE>ObjectName</CODE> passed in 
       * parameter contains a pattern or no <CODE>ObjectName</CODE> is specified for the MBean.
       *
       */
      ObjectInstance createMBean( String className, ObjectName name, Object params[], String signature[] )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException, RemoteException;
  
      /**
       * Instantiates and registers an MBean in the MBean server.
       * The class loader to be used is identified by its object
       * name. An object name is associated to the MBean. If the object name
       * of the loader is not specified, the ClassLoader that loaded the MBean server will be used.
       * If  the MBean object name given is null, the MBean can automatically provide its
       * own name by implementing the {@link javax.management.MBeanRegistration MBeanRegistration} interface.
       * The call returns an <CODE>ObjectInstance</CODE> object representing the newly created MBean.
       *
       * @param className The class name of the MBean to be instantiated.
       * @param name The object name of the MBean. May be null.
       * @param params An array containing the parameters of the constructor to be invoked.
       * @param signature An array containing the signature of the constructor to be invoked.
       * @param loaderName The object name of the class loader to be used.
       *
       * @return  An <CODE>ObjectInstance</CODE>, containing the <CODE>ObjectName</CODE> and 
       * the Java class name of the newly instantiated MBean.
       *
       * @exception ReflectionException Wraps a <CODE>java.lang.ClassNotFoundException</CODE> or 
       * a <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the MBean's constructor.
       * @exception InstanceAlreadyExistsException The MBean is already under the control 
       * of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> 
       * (<CODE>MBeanRegistration</CODE>  interface) method of the MBean has thrown an 
       * exception. The MBean will not be registered.
       * @exception MBeanException The constructor of the MBean has thrown an exception
       * @exception InstanceNotFoundException The specified class loader is not registered 
       * in the MBean server.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The className passed in parameter is null, the <CODE>ObjectName</CODE> passed in 
       * parameter contains a pattern or no <CODE>ObjectName</CODE> is specified for the MBean.
       */
      ObjectInstance createMBean( String className, 
                                  ObjectName name, 
                                  ObjectName loaderName, 
                                  Object params[], 
                                  String signature[] )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, 
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException, RemoteException;
  
      /**
       * Registers a pre-existing object as an MBean with the MBean server. If the object name given is
       * null, the MBean may automatically provide its own name by implementing the
       * {@link javax.management.MBeanRegistration MBeanRegistration}  interface.
       * The call returns an <CODE>ObjectInstance</CODE> object representing the registered MBean.
       *
       * @param object The  MBean to be registered as an MBean.
       * @param name The object name of the MBean. May be null.
       *
       * @return  The <CODE>ObjectInstance</CODE> for the MBean that has been registered.
       *
       * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean server.
       * @exception MBeanRegistrationException The <CODE>preRegister</CODE> 
       * (<CODE>MBeanRegistration</CODE>  interface) method of the MBean
       * has thrown an exception. The MBean will not be registered.
       * @exception NotCompliantMBeanException This object is not a JMX compliant MBean
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object passed in parameter is null or no object name is specified.
       */
      ObjectInstance registerMBean( Object object, ObjectName name )
          throws InstanceAlreadyExistsException, MBeanRegistrationException,
                 NotCompliantMBeanException, RemoteException;
  
      /**
       * De-registers an MBean from the MBean server. The MBean is identified by
       * its object name. Once the method has been invoked, the MBean may
       * no longer be accessed by its object name.
       *
       * @param name The object name of the MBean to be de-registered.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception MBeanRegistrationException The preDeregister 
       * ((<CODE>MBeanRegistration</CODE> interface) method of the MBean has thrown an exception.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null or the MBean you are when trying to de-register 
       * is the {@link javax.management.MBeanServerDelegate MBeanServerDelegate} MBean.
       */
      void unregisterMBean( ObjectName name )
          throws InstanceNotFoundException, MBeanRegistrationException, RemoteException;
  
      /**
       * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered with the MBean server.
       *
       * @param name The object name of the MBean.
       *
       * @return The <CODE>ObjectInstance</CODE> associated to the MBean specified by <VAR>name</VAR>.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       */
      ObjectInstance getObjectInstance( ObjectName name ) 
          throws InstanceNotFoundException, RemoteException;
  
      /**
       * Gets MBeans controlled by the MBean server. This method allows any
       * of the following to be obtained: All MBeans, a set of MBeans specified
       * by pattern matching on the <CODE>ObjectName</CODE> and/or a Query expression, a
       * specific MBean. When the object name is null or no domain and key properties are specified,
       * all objects are to be selected (and filtered if a query is specified). It returns the
       * set of <CODE>ObjectInstance</CODE> objects (containing the <CODE>ObjectName</CODE> 
       * and the Java Class name) for the selected MBeans.
       *
       * @param name The object name pattern identifying the MBeans to be retrieved. If
       * null or no domain and key properties are specified, all the MBeans registered will be retrieved.
       * @param query The query expression to be applied for selecting MBeans. If null
       * no query expression will be applied for selecting MBeans.
       *
       * @return  A set containing the <CODE>ObjectInstance</CODE> objects for the selected MBeans.
       * If no MBean satisfies the query an empty list is returned.
       */
      Set queryMBeans( ObjectName name, QueryExp query ) 
          throws RemoteException;
  
      /**
       * Gets the names of MBeans controlled by the MBean server. This method
       * enables any of the following to be obtained: The names of all MBeans,
       * the names of a set of MBeans specified by pattern matching on the
       * <CODE>ObjectName</CODE> and/or a Query expression, a specific MBean name (equivalent to
       * testing whether an MBean is registered). When the object name is
       * null or no domain and key properties are specified, all objects are selected (and filtered if a
       * query is specified). It returns the set of ObjectNames for the MBeans
       * selected.
       *
       * @param name The object name pattern identifying the MBeans to be retrieved. If
       * null or no domain and key properties are specified, all the MBeans registered will be retrieved.
       * @param query The query expression to be applied for selecting MBeans. If null
       * no query expression will be applied for selecting MBeans.
       *
       * @return  A set containing the ObjectNames for the MBeans selected.
       * If no MBean satisfies the query, an empty list is returned.
       *
       */
      Set queryNames( ObjectName name, QueryExp query ) 
          throws RemoteException;
  
      /**
       * Checks whether an MBean, identified by its object name, is already registered
       * with the MBean server.
       *
       * @param name The object name of the MBean to be checked.
       *
       * @return  True if the MBean is already registered in the MBean server, false otherwise.
       *
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null.
       */
      boolean isRegistered( ObjectName name ) 
          throws RemoteException;
  
      /**
       * Returns the number of MBeans registered in the MBean server.
       */
      Integer getMBeanCount() 
          throws RemoteException;
  
      /**
       * Gets the value of a specific attribute of a named MBean. The MBean
       * is identified by its object name.
       *
       * @param name The object name of the MBean from which the attribute is to be retrieved.
       * @param attribute A String specifying the name of the attribute to be
       * retrieved.
       *
       * @return  The value of the retrieved attribute.
       *
       * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
       * @exception MBeanException  Wraps an exception thrown by the MBean's getter.
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception ReflectionException  Wraps a <CODE>java.lang.Exception</CODE> thrown 
       * when trying to invoke the setter.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null or the attribute in parameter is null.
       */
      Object getAttribute( ObjectName name, String attribute ) 
          throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, 
                 ReflectionException, RemoteException;
  
      /**
       * Enables the values of several attributes of a named MBean. The MBean
       * is identified by its object name.
       *
       * @param name The object name of the MBean from which the attributes are
       * retrieved.
       * @param attributes A list of the attributes to be retrieved.
       *
       * @return The list of the retrieved attributes.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception ReflectionException An exception occurred when trying to invoke the 
       * getAttributes method of a Dynamic MBean.
       * @exception RuntimeOperationsException Wrap a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null or attributes in parameter is null.
       */
      AttributeList getAttributes( ObjectName name, String[] attributes )
          throws InstanceNotFoundException, ReflectionException;
  
      /**
       * Sets the value of a specific attribute of a named MBean. The MBean
       * is identified by its object name.
       *
       * @param name The name of the MBean within which the attribute is to be set.
       * @param attribute The identification of the attribute to be set and the value it is to be set to.
       *
       * @return  The value of the attribute that has been set.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
       * @exception InvalidAttributeValueException The value specified for the attribute is not valid.
       * @exception MBeanException Wraps an exception thrown by the MBean's setter.
       * @exception ReflectionException  Wraps a <CODE>java.lang.Exception</CODE> thrown when 
       * trying to invoke the setter.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null or the attribute in parameter is null.
       */
      void setAttribute( ObjectName name, Attribute attribute ) 
          throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, 
                 MBeanException, ReflectionException, RemoteException;
  
      /**
       * Sets the values of several attributes of a named MBean. The MBean is
       * identified by its object name.
       *
       * @param name The object name of the MBean within which the attributes are to
       * be set.
       * @param attributes A list of attributes: The identification of the
       * attributes to be set and  the values they are to be set to.
       *
       * @return  The list of attributes that were set, with their new values.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception ReflectionException An exception occurred when trying to invoke the 
       * getAttributes method of a Dynamic MBean.
       * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: 
       * The object name in parameter is null or attributes in parameter is null.
       */
      AttributeList setAttributes( ObjectName name, AttributeList attributes )
          throws InstanceNotFoundException, ReflectionException, RemoteException;
  
      /**
       * Invokes an operation on an MBean.
       *
       * @param name The object name of the MBean on which the method is to be invoked.
       * @param operationName The name of the operation to be invoked.
       * @param params An array containing the parameters to be set when the operation is
       * invoked
       * @param signature An array containing the signature of the operation. The class objects will
       * be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
       *
       * @return  The object returned by the operation, which represents the result ofinvoking the operation on the
       * MBean specified.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       * @exception MBeanException  Wraps an exception thrown by the MBean's invoked method.
       * @exception ReflectionException  Wraps a <CODE>java.lang.Exception</CODE> thrown 
       * while trying to invoke the method.
       */
      Object invoke( ObjectName name, String operationName, Object params[], String signature[] )
          throws InstanceNotFoundException, MBeanException, ReflectionException, RemoteException;
  
      /**
       * Returns the default domain used for naming the MBean.
       * The default domain name is used as the domain part in the ObjectName
       * of MBeans if no domain is specified by the user.
       */
      String getDefaultDomain() 
          throws RemoteException;
  
      /**
       * Enables to add a listener to a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be added.
       * @param listener The listener object which will handle the notifications emitted 
       * by the registered MBean.
       * @param filter The filter object. If filter is null, no filtering will be 
       * performed before handling notifications.
       * @param handback The context to be sent to the listener when a notification is emitted.
       * @exception InstanceNotFoundException The MBean name provided does not match any of 
       * the registered MBeans.
       */
      void addNotificationListener( ObjectName name, 
                                    NotificationListener listener, 
                                    NotificationFilter filter, 
                                    Object handback )
          throws InstanceNotFoundException, RemoteException;
  
      /**
       * Enables to add a listener to a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be added.
       * @param listener The object name of the listener which will handle the notifications 
       * emitted by the registered MBean.
       * @param filter The filter object. If filter is null, no filtering will be performed before 
       * handling notifications.
       * @param handback The context to be sent to the listener when a notification is emitted.
       *
       * @exception InstanceNotFoundException The MBean name of the notification listener 
       * or of the notification broadcaster does not match any of the registered MBeans.
       */
      void addNotificationListener( ObjectName name, 
                                    ObjectName listener, 
                                    NotificationFilter filter, 
                                    Object handback )
          throws InstanceNotFoundException, RemoteException;
  
      /**
       * Enables to remove a listener from a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be removed.
       * @param listener The listener object which will handle the notifications emitted by 
       * the registered MBean.
       * This method will remove all the information related to this listener.
       *
       * @exception InstanceNotFoundException The MBean name provided does not match any 
       * of the registered MBeans.
       * @exception ListenerNotFoundException The listener is not registered in the MBean.
       */
      void removeNotificationListener( ObjectName name, NotificationListener listener )
          throws InstanceNotFoundException, ListenerNotFoundException, RemoteException;
  
      /**
       * Enables to remove a listener from a registered MBean.
       *
       * @param name The name of the MBean on which the listener should be removed.
       * @param listener The object name of the listener which will handle the 
       * notifications emitted by the registered MBean.
       * This method will remove all the information related to this listener.
       *
       * @exception InstanceNotFoundException The MBean name provided does not match any of 
       * the registered MBeans.
       * @exception ListenerNotFoundException The listener is not registered in the MBean.
       */
      void removeNotificationListener( ObjectName name, ObjectName listener )
          throws InstanceNotFoundException, ListenerNotFoundException, RemoteException;
  
      /**
       * This method discovers the attributes and operations that an MBean exposes
       * for management.
       *
       * @param name The name of the MBean to analyze
       *
       * @return  An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of 
       * all attributes and operations of this MBean.
       *
       * @exception IntrospectionException An exception occurs during introspection.
       * @exception InstanceNotFoundException The MBean specified is not found.
       * @exception ReflectionException An exception occurred when trying to invoke 
       * the getMBeanInfo of a Dynamic MBean.
       */
      MBeanInfo getMBeanInfo( ObjectName name ) 
          throws InstanceNotFoundException, IntrospectionException, ReflectionException, RemoteException;
  
      /** Returns true if the MBean specified is an instance of the specified class, false otherwise.
       *
       * @param name The <CODE>ObjectName</CODE> of the MBean.
       * @param className The name of the class.
       *
       * @return true if the MBean specified is an instance of the specified class, false otherwise.
       *
       * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
       */
      boolean isInstanceOf( ObjectName name, String className ) 
          throws InstanceNotFoundException, RemoteException;
  
      /**
       * De-serializes a byte array in the context of the class loader
       * of an MBean.
       *
       * @param name The name of the MBean whose class loader should be used for the de-serialization.
       * @param data The byte array to be de-sererialized.
       *
       * @return  The de-serialized object stream.
       *
       * @exception InstanceNotFoundException The MBean specified is not found.
       * @exception OperationsException Any of the usual Input/Output related exceptions.
       */
      ObjectInputStream deserialize( ObjectName name, byte[] data )
          throws InstanceNotFoundException, OperationsException, RemoteException;
  
      /**
       * De-serializes a byte array in the context of a given MBean class loader.
       * The class loader is the one that loaded the class with name "className".
       *
       * @param name The name of the class whose class loader should be used for the de-serialization.
       * @param data The byte array to be de-sererialized.
       *
       * @return  The de-serialized object stream.
       *
       * @exception OperationsException Any of the usual Input/Output related exceptions.
       * @exception ReflectionException The specified class could not be loaded by the 
       * default loader repository
       */
      ObjectInputStream deserialize( String className, byte[] data )
          throws OperationsException, ReflectionException, RemoteException;
  
      /**
       * De-serializes a byte array in the context of a given MBean class loader.
       * The class loader is the one that loaded the class with name "className".
       * The name of the class loader to be used for loading the specified class is specified.
       * If null, the MBean Server's class loader will be used.
       *
       * @param name The name of the class whose class loader should be used for the de-serialization.
       * @param data The byte array to be de-sererialized.
       * @param loaderName The name of the class loader to be used for loading the specified class.
       * If null, the MBean Server's class loader will be used.
       *
       * @return  The de-serialized object stream.
       *
       * @exception InstanceNotFoundException The specified class loader MBean is not found.
       * @exception OperationsException Any of the usual Input/Output related exceptions.
       * @exception ReflectionException The specified class could not be loaded by the specified class loader.
       */
      ObjectInputStream deserialize( String className, ObjectName loaderName, byte[] data )
          throws InstanceNotFoundException, OperationsException, ReflectionException, RemoteException;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/adaptor/RMIAdaptorImpl.java
  
  Index: RMIAdaptorImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx.adaptor;
  
  import java.io.ObjectInputStream;
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  import java.util.Set;
  import javax.management.*;
  
  /**
   * This is the RMI connection representing an MBeanServer. It is
   * identical to the <code>MBeanServer</code> interface, except
   * it throws exceptions related to remote operations.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   */
  public class RMIAdaptorImpl 
      extends UnicastRemoteObject 
      implements RMIAdaptor
  {
      private MBeanServer m_server;
  
      public RMIAdaptorImpl( final MBeanServer server )
          throws RemoteException
      {
          m_server = server;
      }
  
      /////////////////////////////////
      /// RMIADAPTOR IMPLEMENTATION ///
      /////////////////////////////////
      public Object instantiate( final String className )
          throws ReflectionException, MBeanException, RemoteException
      {
          return m_server.instantiate( className );
      }
  
      public Object instantiate( final String className, final ObjectName loaderName )
          throws ReflectionException, MBeanException, InstanceNotFoundException, RemoteException
      {
          return m_server.instantiate( className, loaderName );
      }
  
      public Object instantiate( final String className, 
                                 final Object[] params, 
                                 final String[] signature )
          throws ReflectionException, MBeanException, RemoteException
      {
          return m_server.instantiate( className, params, signature );
      }
  
      public Object instantiate( final String className,
                                 final ObjectName loaderName,
                                 final Object[] params,
                                 final String[] signature )
          throws ReflectionException, MBeanException, InstanceNotFoundException, RemoteException
      {
          return m_server.instantiate( className, loaderName, params, signature );
      }
  
      public ObjectInstance createMBean( final String className, final ObjectName name )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException, RemoteException
      {
          return m_server.createMBean( className, name );
      }
  
      public ObjectInstance createMBean( final String className, 
                                         final ObjectName name, 
                                         final ObjectName loaderName )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException, RemoteException
      {
          return m_server.createMBean( className, name, loaderName );
      }
  
      public ObjectInstance createMBean( final String className,
                                         final ObjectName name,
                                         final Object[] params,
                                         final String[] signature )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException, RemoteException
      {
          return m_server.createMBean( className, name, params, signature );
      }
  
      public ObjectInstance createMBean( final String className,
                                         final ObjectName name,
                                         final ObjectName loaderName,
                                         final Object[] params,
                                         final String[] signature )
          throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
                 MBeanException, NotCompliantMBeanException, InstanceNotFoundException, RemoteException
      {
          return m_server.createMBean( className, name, loaderName, params, signature );
      }
  
      public ObjectInstance registerMBean( final Object object, final ObjectName name )
          throws InstanceAlreadyExistsException, MBeanRegistrationException,
                 NotCompliantMBeanException, RemoteException
      {
          return m_server.registerMBean( object, name );
      }
  
      public void unregisterMBean( final ObjectName name )
          throws InstanceNotFoundException, MBeanRegistrationException, RemoteException
      {
          m_server.unregisterMBean( name );
      }
  
      public ObjectInstance getObjectInstance( final ObjectName name )
          throws InstanceNotFoundException, RemoteException 
      {
          return m_server.getObjectInstance( name );
      }
  
      public Set queryMBeans( final ObjectName name, final QueryExp query )
          throws RemoteException
      {
          return m_server.queryMBeans( name, query );
      }
  
      public Set queryNames( final ObjectName name, final QueryExp query ) 
          throws RemoteException
      {
          return m_server.queryMBeans( name, query );
      }
  
      public boolean isRegistered( final ObjectName name ) 
          throws RemoteException
      {
          return m_server.isRegistered( name );
      }
  
      public Integer getMBeanCount() 
          throws RemoteException
      {
          return m_server.getMBeanCount();
      }
  
      public Object getAttribute( final ObjectName name, final String attribute )
          throws MBeanException, AttributeNotFoundException, InstanceNotFoundException,
                 ReflectionException, RemoteException 
      {
          return m_server.getAttribute( name, attribute );
      }
  
      public AttributeList getAttributes( final ObjectName name, final String[] attributes )
          throws InstanceNotFoundException, ReflectionException
      {
          return m_server.getAttributes( name, attributes );
      }
  
      public void setAttribute( final ObjectName name, final Attribute attribute )
          throws InstanceNotFoundException, AttributeNotFoundException,
                 InvalidAttributeValueException, MBeanException, ReflectionException, RemoteException
      {
          m_server.setAttribute( name, attribute );
      }
  
      public AttributeList setAttributes( final ObjectName name, final AttributeList attributes )
          throws InstanceNotFoundException, ReflectionException, RemoteException 
      {
          return m_server.setAttributes( name, attributes );
      }
  
      public Object invoke( final ObjectName name, 
                            final String operationName, 
                            final Object[] params, 
                            final String[] signature )
          throws InstanceNotFoundException, MBeanException, ReflectionException, RemoteException
      {
          return m_server.invoke( name, operationName, params, signature );
      }
  
      public String getDefaultDomain() 
          throws RemoteException
      {
          return m_server.getDefaultDomain();
      }
  
      public void addNotificationListener( final ObjectName name,
                                           final NotificationListener listener,
                                           final NotificationFilter filter,
                                           final Object handback )
          throws InstanceNotFoundException, RemoteException
      {
          m_server.addNotificationListener( name, listener, filter, handback );
      }
  
      public void addNotificationListener( final ObjectName name,
                                           final ObjectName listener,
                                           final NotificationFilter filter,
                                           final Object handback )
          throws InstanceNotFoundException, RemoteException 
      {
          m_server.addNotificationListener( name, listener, filter, handback );
      }
  
      public void removeNotificationListener( final ObjectName name, final NotificationListener listener )
          throws InstanceNotFoundException, ListenerNotFoundException, RemoteException 
      {
          m_server.removeNotificationListener( name, listener );
      }
  
      public void removeNotificationListener( final ObjectName name, final ObjectName listener )
          throws InstanceNotFoundException, ListenerNotFoundException, RemoteException 
      {
          m_server.removeNotificationListener( name, listener );
      }
  
      public MBeanInfo getMBeanInfo( final ObjectName name )
          throws InstanceNotFoundException, IntrospectionException, ReflectionException, RemoteException
      {
          return m_server.getMBeanInfo( name );
      }
      
      public boolean isInstanceOf( final ObjectName name, final String className )
          throws InstanceNotFoundException, RemoteException 
      {
          return m_server.isInstanceOf( name, className );
      }
  
      public ObjectInputStream deserialize( final ObjectName name, final byte[] data )
          throws InstanceNotFoundException, OperationsException, RemoteException 
      {
          return m_server.deserialize( name, data );
      }
  
      public ObjectInputStream deserialize( final String className, final byte[] data )
          throws OperationsException, ReflectionException, RemoteException 
      {
          return m_server.deserialize( className, data );
      }
  
      public ObjectInputStream deserialize( final String className, 
                                            final ObjectName loaderName, 
                                            final byte[] data )
          throws InstanceNotFoundException, OperationsException, ReflectionException,
                 RemoteException 
      {
          return m_server.deserialize( className, loaderName, data );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/introspector/DefaultDynamicMBean.java
  
  Index: DefaultDynamicMBean.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx.introspector;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import javax.management.Attribute;
  import javax.management.AttributeList;
  import javax.management.AttributeList;
  import javax.management.AttributeNotFoundException;
  import javax.management.DynamicMBean;
  import javax.management.IntrospectionException;
  import javax.management.InvalidAttributeValueException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanConstructorInfo;
  import javax.management.MBeanException;
  import javax.management.MBeanInfo;
  import javax.management.MBeanNotificationInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.NotCompliantMBeanException;
  import javax.management.NotificationBroadcaster;
  import javax.management.ReflectionException;
  
  /**
   * This class is used by DynamicMBeanFactory to create DynamicMBeans. It can
   * represent any object. Notifications are not supported. You can easily create
   * custom DynamicMBeans by extending this class and replacing the createXXX()
   * methods. TODO: Or, you can replace the getDescriptionFor() methods to add
   * sensible documentation to your DynamicMBean, making it easier to create Open
   * MBeans if you wish to do so.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/04/24 05:00:53 $
   */
  class DefaultDynamicMBean 
      implements DynamicMBean
  {
      private final static String DEFAULT_DESCRIPTION = "A manageable object.";
  
      /**
       * The object represented by this MBean
       */
      protected final Object m_object;
      /**
       * The MBeanInfo object.
       */
      protected MBeanInfo m_mBeanInfo;
  
      /**
       * The human readable description of the class.
       */
      protected String m_description;
      /**
       * Tells if this is an open MBean.
       */
      protected boolean m_isOpen;
      /**
       * The MBean attribute descriptors.
       */
      protected MBeanAttributeInfo[] m_attributes;
      /**
       * The MBean operation descriptors.
       */
      protected MBeanOperationInfo[] m_operations;
      /**
       * The MBean constructor descriptors.
       */
      protected MBeanConstructorInfo[] m_constructors;
      /**
       * The MBean notification descriptors.
       */
      protected MBeanNotificationInfo[] m_notifications;
  
      DefaultDynamicMBean( final Object object )
          throws NotCompliantMBeanException
      {
          m_object = object;
          final Class clazz = object.getClass();
  
          final Constructor[] constructors = clazz.getConstructors();
          final Method[] methods = clazz.getMethods();
  
          m_constructors = createConstructorInfo( constructors );
          m_operations = createOperationInfo( methods );
          m_attributes = createAttributeInfo( methods );
          m_notifications = new MBeanNotificationInfo[ 0 ];
          m_description = DEFAULT_DESCRIPTION;
  
          createMBeanInfo();
      }
  
      DefaultDynamicMBean( final Object object, final MBeanInfo mBeanInfo )
          throws IllegalArgumentException, NotCompliantMBeanException
      {
          this( object );
  
          m_mBeanInfo = mBeanInfo;
  
          // make sure the MBeanInfo is correct
          try
          {
              if( !( Class.forName( mBeanInfo.getClassName() ) == object.getClass() ) )
              {
                  throw new IllegalArgumentException( "The supplied mBeanInfo does not " + 
                                                      "describe the object!" );
              }
              if( mBeanInfo.getNotifications() != m_notifications )
              {
                  throw new IllegalArgumentException( "The DefaultDynamicMBean does " + 
                                                      "not support notifications!" );
              }
          }
          catch( ClassNotFoundException cnfe )
          {
              throw new IllegalArgumentException( "Unable to find the class specified by the MBeanInfo!" );
          }
  
          m_description = mBeanInfo.getDescription();
      }
  
      ///////////////////////////////
      /// DYNAMIC MBEAN INTERFACE ///
      ///////////////////////////////
  
      /**
       * Obtains the value of a specific attribute of the Dynamic MBean.
       */
      public Object getAttribute( final String attribute )
          throws AttributeNotFoundException, MBeanException, ReflectionException
      {
          final String methodName = 
              "get" + attribute.substring( 0, 1 ).toUpperCase() + attribute.substring( 1 );
          final String methodName2 = 
              "is" + attribute.substring( 0, 1 ).toUpperCase() + attribute.substring( 1 );
  
          final Class clazz = m_object.getClass();
  
          Method method;
          try
          {
              method = clazz.getMethod( methodName, new Class[0] );
          }
          catch( final Exception e )
          {
              try
              {
                  method = clazz.getMethod( methodName2, new Class[0] );
              }
              catch( final Exception ee )
              {
                  throw new AttributeNotFoundException();
              }
          }
  
          try
          {
              return method.invoke( m_object, new Object[0] );
          }
          catch( final Exception e )
          {
              throw new MBeanException( e );
          }
      }
  
      /**
       * Enables the values of several attributes of the Dynamic MBean.
       */
      public AttributeList getAttributes( final String[] atts )
      {
          AttributeList attList = new AttributeList();
          for( int i = 0; i < atts.length; i++ )
          {
              final String name = atts[i];
              final String methodName = 
                  "get" + name.substring( 0, 1 ).toUpperCase() + name.substring( 1 );
              final String methodName2 = 
                  "is" + name.substring( 0, 1 ).toUpperCase() + name.substring( 1 );
  
              final Class clazz = m_object.getClass();
  
              Object value = null;
              Method method;
              
              try
              {
                  method = clazz.getMethod( methodName, new Class[0] );
              }
              catch( final Exception e )
              {
                  try
                  {
                      method = clazz.getMethod( methodName2, new Class[0] );
                  }
                  catch( final Exception ee )
                  {
                      continue;
                  }
              }
  
              try
              {
                  value = method.invoke( m_object, new Object[0] );
              }
              catch( final Exception e )
              {
              }
  
              if( value != null )
              {
                  attList.add( new Attribute( name, value ) );
              }
          }
  
          return attList;
      }
  
      /**
       * Provides the exposed attributes and actions of the Dynamic MBean using an
       * MBeanInfo object.
       *
       * @return An instance of <CODE>MBeanInfo</CODE> allowing all attributes and
       *      actions exposed by this Dynamic MBean to be retrieved.
       */
      public MBeanInfo getMBeanInfo()
      {
          return m_mBeanInfo;
      }
  
      /**
       * Allows an action to be invoked on the Dynamic MBean.
       *
       * @param actionName The name of the action to be invoked.
       * @param params An array containing the parameters to be set when the
       *      action is invoked.
       * @param signature An array containing the signature of the action. The
       *      class objects will be loaded through the same class loader as the
       *      one used for loading the MBean on which the action is invoked.
       * @return The object returned by the action, which represents the result of
       *      invoking the action on the MBean specified.
       * @exception MBeanException Wraps a <CODE>java.lang.Exception</CODE> thrown
       *      by the MBean's invoked method.
       * @exception ReflectionException Wraps a <CODEjava.lang.Exception</CODE
       *      thrown while trying to invoke the method
       */
      public Object invoke( final String actionName, final Object[] params, final String[] signature )
          throws MBeanException, ReflectionException
      {
          Method method;
  
          try
          {
              final Class[] classes = new Class[ signature.length ];
  
              for( int i = 0; i < classes.length; i++ )
              {
                  classes[ i ] = Class.forName( signature[ i ] );
              }
  
              method = m_object.getClass().getMethod( actionName, classes );
          }
          catch( final Exception e )
          {
              throw new ReflectionException( e );
          }
  
          try
          {
              return method.invoke( m_object, params );
          }
          catch( final Exception e )
          {
              throw new MBeanException( e );
          }
      }
  
      /**
       * Sets the value of a specific attribute of the Dynamic MBean
       */
      public void setAttribute( final Attribute attribute )
          throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, 
                 ReflectionException
      {
          final String name = attribute.getName();
          final String methodName = 
              "set" + name.substring( 0, 1 ).toUpperCase() + name.substring( 1 );
  
          Method method;
          try
          {
              final Class clazz = m_object.getClass();
              method = clazz.getMethod( methodName,
                                        new Class[] { attribute.getValue().getClass() } );
          }
          catch( final Exception e )
          {
              throw new AttributeNotFoundException();
          }
  
          try
          {
              method.invoke( m_object, new Object[] { attribute.getValue() } );
          }
          catch( final Exception e )
          {
              throw new MBeanException( e );
          }
      }
  
      /**
       * Sets the values of several attributes of the Dynamic MBean.
       */
      public AttributeList setAttributes( final AttributeList atts )
      {
          final AttributeList attList = new AttributeList();
  
          for( int i = 0; i < atts.size(); i++ )
          {
              final Attribute att = (Attribute)atts.get( i );
              final String name = att.getName();
              final String methodName = "set" + name.substring( 0, 1 ).toUpperCase() + name.substring( 1 );
  
              Object value = null;
              Method m;
              try
              {
                  m = m_object.getClass().getMethod( methodName, new Class[]{att.getValue().getClass()} );
              }
              catch( Exception e )
              {
                  continue;
              }
              try
              {
                  value = m.invoke( m_object, new Object[]{att.getValue()} );
              }
              catch( Exception e )
              {
              }
              if( value != null )
              {
                  attList.add( new Attribute( name, value ) );
              }
          }
          return attList;
      }
  
      /**
       * Extract all the Methods from the supplied array that are operations.
       */
      protected Method[] getOperationFor( Method[] methods )
      {
          final ArrayList ops = new ArrayList();
          for( int i = 0; i < methods.length; i++ )
          {
              final String name = methods[i].getName();
              final String uppercaseChars = new String( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
              final boolean isGetter =
                  ( name.startsWith( "get" ) &&
                    ( uppercaseChars.indexOf( name.substring( 3, 4 ) ) != -1 ) );
              final boolean isSetter =
                  ( name.startsWith( "set" ) &&
                    ( uppercaseChars.indexOf( name.substring( 3, 4 ) ) != -1 ) );
              final boolean isIs =
                  ( name.startsWith( "is" ) &&
                    ( uppercaseChars.indexOf( name.substring( 2, 3 ) ) != -1 ) );
              if( !( isGetter || isSetter || isIs ) )
              {
                  ops.add( methods[i] );
              }
          }
          return (Method[])ops.toArray();
      }
  
      /**
       * Extract all Methods from the supplied array that are of the form getXxx,
       * setXxx or isXxx.
       *
       * @return A multi-dimensional array, with the first element being an array
       *      of getter methods, the second element being an array of setter
       *      methods, and the third element being an array of isser methods.
       */
      protected Method[][] getAttributeFor( Method[] methods )
      {
          final ArrayList getters = new ArrayList();
          final ArrayList setters = new ArrayList();
          final ArrayList issers = new ArrayList();
  
          Method[][] m = new Method[3][];
          for( int i = 0; i < methods.length; i++ )
          {
              final String name = methods[i].getName();
              final String uppercaseChars = new String( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
              final boolean isGetter =
                  ( name.startsWith( "get" ) &&
                    ( uppercaseChars.indexOf( name.substring( 3, 4 ) ) != -1 ) );
              final boolean isSetter =
                  ( name.startsWith( "set" ) &&
                    ( uppercaseChars.indexOf( name.substring( 3, 4 ) ) != -1 ) );
              final boolean isIs =
                  ( name.startsWith( "is" ) &&
                    ( uppercaseChars.indexOf( name.substring( 2, 3 ) ) != -1 ) );
              if( isGetter )
              {
                  getters.add( methods[i] );
              }
              if( isSetter )
              {
                  setters.add( methods[i] );
              }
              if( isIs )
              {
                  issers.add( methods[i] );
              }
          }
          m[0] = (Method[])getters.toArray();
          m[1] = (Method[])setters.toArray();
          m[2] = (Method[])issers.toArray();
          return m;
      }
  
      //////////////////////
      /// HELPER METHODS ///
      //////////////////////
      /**
       * Creates an MBeanConstructorInfo array with an entry for each of the
       * supplied constructors.
       */
      protected MBeanConstructorInfo[] createConstructorInfo( final Constructor[] constructors )
      {
          final MBeanConstructorInfo[] info = new MBeanConstructorInfo[ constructors.length ];
  
          for( int i = 0; i < constructors.length; i++ )
          {
              info[i] = new MBeanConstructorInfo( "Creates a new instance of this MBean.", constructors[i] );
          }
  
          return info;
      }
  
      /**
       * Creates an MBeanOperationInfo array with an entry for each supplied
       * method that is an operation. A method is an operation when it is not
       * named getXxxx, setXxxx or isXxxx.
       */
      protected MBeanOperationInfo[] createOperationInfo( final Method[] methods )
      {
          // getXXX, setXXX and isXXX are not operations, so remove those
          final Method[] ops = getOperationFor( methods );
  
          MBeanOperationInfo[] info = new MBeanOperationInfo[ops.length];
  
          for( int i = 0; i < ops.length; i++ )
          {
              info[i] = new MBeanOperationInfo(
                                               "Call a method on this MBean", ops[i] );
          }
          return info;
      }
  
      /**
       * Creates an MBeanAttributeInfo array with an entry for every attribute.
       * The exposed attributes are found by taking a look at all methods that are
       * named getXxx and isXxx. While this method finds the corresponding setXxx
       * method for these, it does not add an entry into the returned array for
       * write-only attributes. TODO:
  
       * @throws NotCompliantMBeanException when the getXxx, isXxx or setXxx don't
       *      have the right number of arguments (0, 0 and 1, respectively).
       */
      protected MBeanAttributeInfo[] createAttributeInfo( Method[] methods )
          throws NotCompliantMBeanException
      {
          // only getXXX, setXXX and isXXX expose attributes, so remove
          // all others
          final Method[][] m = getAttributeFor( methods );
  
          // all getter and isser methods mean an attribute
          final MBeanAttributeInfo[] info = new MBeanAttributeInfo[( m[0].length + m[2].length )];
          // fill info from this point
          int beginIndex = 0;
  
          // create MBeanAttributeInfo's for all getter methods
          for( int i = 0; i < m[0].length; i++ )
          {
              final Method getter = m[0][i];
              String attributeName = getter.getName().substring( 3 );
              Method setter = null;
              for( int j = 0; j < m[1].length; j++ )
              {
                  String setterName = m[1][j].getName();
                  if( setterName.equals( "set" + attributeName ) )
                  {
                      setter = m[0][j];
                      break;
                  }
              }
              attributeName = attributeName.substring( 0, 1 ).toLowerCase() + attributeName.substring( 1 );
              try
              {
                  info[beginIndex] = new MBeanAttributeInfo( attributeName, "", getter, setter );
              }
              catch( IntrospectionException ie )
              {
                  throw new NotCompliantMBeanException();
              }
              beginIndex++;
          }
  
          // create MBeanAttributeInfo's for all isser methods
          for( int i = 0; i < m[2].length; i++ )
          {
              final Method isser = m[2][i];
              final String attributeName = isser.getName().substring( 2 );
              Method setter = null;
              for( int j = 0; j < m[1].length; j++ )
              {
                  String setterName = m[1][j].getName();
                  if( setterName.equals( "set" + attributeName ) )
                  {
                      setter = m[0][j];
                      break;
                  }
              }
  
              try
              {
                  info[ beginIndex ] = new MBeanAttributeInfo( attributeName, "", isser, setter );
              }
              catch( IntrospectionException ie )
              {
                  throw new NotCompliantMBeanException();
              }
              beginIndex++;
          }
          return info;
      }
  
      protected void createMBeanInfo()
      {
          m_mBeanInfo = 
              new MBeanInfo( m_object.getClass().getName(),
                             m_description,
                             m_attributes,
                             m_constructors,
                             m_operations,
                             m_notifications );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/introspector/DefaultDynamicNotificationMBean.java
  
  Index: DefaultDynamicNotificationMBean.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx.introspector;
  
  import javax.management.ListenerNotFoundException;
  import javax.management.MBeanInfo;
  import javax.management.MBeanNotificationInfo;
  import javax.management.NotCompliantMBeanException;
  import javax.management.NotificationBroadcaster;
  import javax.management.NotificationBroadcasterSupport;
  import javax.management.NotificationFilter;
  import javax.management.NotificationListener;
  
  /**
   * This class is used by DynamicMBeanFactory to create DynamicMBeans. It extends
   * DefaultDynamicMBean, adding support for notifications.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/04/24 05:00:53 $
   */
  public class DefaultDynamicNotificationMBean
      extends DefaultDynamicMBean
      implements NotificationBroadcaster
  {
      public DefaultDynamicNotificationMBean( final NotificationBroadcaster object )
          throws NotCompliantMBeanException
      {
          super( object );
  
          m_notifications = object.getNotificationInfo();
          createMBeanInfo();
      }
  
      public DefaultDynamicNotificationMBean( final NotificationBroadcaster object,
                                              final MBeanInfo mBeanInfo )
          throws NotCompliantMBeanException
      {
          super( object, mBeanInfo );
          m_notifications = object.getNotificationInfo();
          createMBeanInfo();
      }
  
      public MBeanNotificationInfo[] getNotificationInfo()
      {
          return m_notifications;
      }
  
      /////////////////////////////////////////
      /// NOTIFICATIONBROADCASTER INTERFACE ///
      /////////////////////////////////////////
      public void addNotificationListener( final NotificationListener listener,
                                           final NotificationFilter filter,
                                           final Object handback )
          throws java.lang.IllegalArgumentException
      {
          ((NotificationBroadcaster)m_object ).addNotificationListener( listener, filter, handback );
      }
  
      public void removeNotificationListener( final NotificationListener listener )
          throws ListenerNotFoundException
      {
          ((NotificationBroadcaster)m_object).removeNotificationListener( listener );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/jmx/introspector/DynamicMBeanFactory.java
  
  Index: DynamicMBeanFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.jmx.introspector;
  
  import javax.management.DynamicMBean;
  import javax.management.MBeanInfo;
  import javax.management.NotCompliantMBeanException;
  import javax.management.NotificationBroadcaster;
  
  /**
   * This class uses introspection to create DynamicMBeans for any java object. It
   * exposes all public methods. If you wish to provide human-readable information
   * about the exposed properties and methods, you can provide your own MBeanInfo
   * object.
   *
   * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/04/24 05:00:53 $
   */
  
  public class DynamicMBeanFactory
  {
      /**
       * All DynamicMBeanFactory methods are static. It is unneccessary to create
       * instances.
       */
      private DynamicMBeanFactory()
      {
      }
  
      /**
       * Get a <code>DynamicMBean</code> that represents the supplied object.
       *
       * @param obj DOC: Insert Description of Parameter
       * @return DOC: Insert Description of the Returned Value
       * @exception NotCompliantMBeanException DOC: Insert Description of
       *      Exception
       */
      public static DynamicMBean create( final Object object )
          throws NotCompliantMBeanException
      {
          if( object instanceof NotificationBroadcaster )
          {
              return new DefaultDynamicNotificationMBean( (NotificationBroadcaster)object );
          }
          else
          {
              return new DefaultDynamicMBean( object );
          }
      }
  
      /**
       * Get a <code>DynamicMBean</code> that represents the supplied object,
       * using the supplied <code>MBeanInfo</code> object.
       *
       * @exception IllegalArgumentException if the supplied object does not
       *      implement the class specified by the supplied MBeanInfo's
       *      getClassName() method.
       */
      public static DynamicMBean create( final Object object, final MBeanInfo mBeanInfo )
          throws IllegalArgumentException, NotCompliantMBeanException
      {
          if( object instanceof NotificationBroadcaster )
          {
              return new DefaultDynamicNotificationMBean( (NotificationBroadcaster)object, mBeanInfo );
          }
          else
          {
              return new DefaultDynamicMBean( object, mBeanInfo );
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Mime
View raw message