geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/config LocalConfigStoreTest.java
Date Wed, 14 Jan 2004 22:16:38 GMT
dain        2004/01/14 14:16:38

  Modified:    modules/kernel/src/java/org/apache/geronimo/gbean
                        GAttributeInfo.java GBeanInfo.java
                        GNotificationInfo.java GOperationInfo.java
               modules/kernel/src/java/org/apache/geronimo/gbean/jmx
                        CollectionProxy.java SingleProxy.java
               modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java KernelMBean.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        Configuration.java ConfigurationStore.java
                        LocalConfigStore.java
               modules/kernel/src/test/org/apache/geronimo/kernel
                        ConfigTest.java
               modules/kernel/src/test/org/apache/geronimo/kernel/config
                        LocalConfigStoreTest.java
  Added:       modules/kernel/src/java/org/apache/geronimo/gbean GBean.java
               modules/kernel/src/java/org/apache/geronimo/gbean/jmx
                        GBeanMBean.java GBeanMBeanAttribute.java
                        GBeanMBeanEndpoint.java GBeanMBeanOperation.java
  Removed:     modules/kernel/src/java/org/apache/geronimo/gbean/jmx
                        GMBean.java GMBeanAttribute.java
                        GMBeanEndpoint.java GMBeanOperation.java
                        GMBeanTarget.java
  Log:
  Renamed all GMbean* classes to GBeanMBean*
  Moved GMBeanTaget to o.a.g.gbean and renamed it to GBean
  
  Revision  Changes    Path
  1.2       +2 -2      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GAttributeInfo.java
  
  Index: GAttributeInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GAttributeInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GAttributeInfo.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ GAttributeInfo.java	14 Jan 2004 22:16:37 -0000	1.2
  @@ -58,7 +58,7 @@
   import java.io.Serializable;
   
   /**
  - * Describes an attibute of a GMBean.
  + * Describes an attibute of a GBean.
    *
    * @version $Revision$ $Date$
    */
  
  
  
  1.3       +3 -5      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java
  
  Index: GBeanInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GBeanInfo.java	14 Jan 2004 08:31:06 -0000	1.2
  +++ GBeanInfo.java	14 Jan 2004 22:16:37 -0000	1.3
  @@ -66,9 +66,7 @@
   import org.apache.geronimo.gbean.GAttributeInfo;
   
   /**
  - * Describes a GBean.  This extension allows the properties to be mutable during setup,
  - * and once the MBean is deployed an imutable copy of will be made.  This class also adds support for multi target
  - * POJOs under the MBean.
  + * Describes a GBean.
    *
    * @version $Revision$ $Date$
    */
  @@ -173,7 +171,7 @@
       }
   
       public String toString() {
  -        StringBuffer result = new StringBuffer("[GeronimoMBeanInfo: id=").append(super.toString()).append(" name=").append(name).append(" description=").append(description);
  +        StringBuffer result = new StringBuffer("[GBeanInfo: id=").append(super.toString()).append(" name=").append(name).append(" description=").append(description);
           for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
               GAttributeInfo geronimoAttributeInfo = (GAttributeInfo) iterator.next();
               result.append("\n    attribute: ").append(geronimoAttributeInfo);
  
  
  
  1.2       +2 -3      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GNotificationInfo.java
  
  Index: GNotificationInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GNotificationInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GNotificationInfo.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ GNotificationInfo.java	14 Jan 2004 22:16:37 -0000	1.2
  @@ -60,8 +60,7 @@
   import java.util.Set;
   
   /**
  - * Describes a notification of a GeronimoMBean.  This extension allows the properties to be mutable during setup,
  - * and once the MBean is deployed an imutable copy of will be made.
  + * Describes a notification of a GBean.
    *
    * @version $Revision$ $Date$
    */
  
  
  
  1.2       +2 -5      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GOperationInfo.java
  
  Index: GOperationInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GOperationInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GOperationInfo.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ GOperationInfo.java	14 Jan 2004 22:16:37 -0000	1.2
  @@ -62,10 +62,7 @@
   import java.util.List;
   
   /**
  - * Describes an operation on a GMBean.  This extension allows the properties to be mutable during setup,
  - * and once the GBean is deployed an imutable copy of will be made.  This class also adds support to
  - * direct the operation to a specific target in a multi target GeronimoMBean.  It also supports caching of the
  - * invocation result, which can reduce the number of calls on the target.
  + * Describes an operation on a GBean.
    *
    * @version $Revision$ $Date$
    */
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBean.java
  
  Index: GBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.gbean;
  
  import org.apache.geronimo.gbean.WaitingException;
  
  
  /**
   * An optional interface for a GBean.  When a GBean implements this interface, the implementation
   * will get life-cycle callbacks.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/14 22:16:37 $
   */
  public interface GBean {
      /**
       * Starts the GBean.  This informs the GBean that it is about to transition to the running state.
       * @throws org.apache.geronimo.gbean.WaitingException if the target is waiting for an external condition before it can fully start
       * @throws java.lang.Exception if the target failed to start; this will cause a transition to the failed state
       */
      void doStart() throws WaitingException, Exception;
  
      /**
       * Stops the target.  This informs the GBean that it is about to transition to the stopped state.
       * @throws org.apache.geronimo.gbean.WaitingException if the target is waiting for an external condition before it can fully stop
       */
      void doStop() throws WaitingException;
  
      /**
       * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
       */
      void doFail();
  }
  
  
  
  1.2       +4 -4      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java
  
  Index: CollectionProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CollectionProxy.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ CollectionProxy.java	14 Jan 2004 22:16:38 -0000	1.2
  @@ -78,9 +78,9 @@
    */
   public class CollectionProxy implements Proxy {
       /**
  -     * The GMBean to which this proxy belongs.
  +     * The GBeanMBean to which this proxy belongs.
        */
  -    private final GMBean gmbean;
  +    private final GBeanMBean gmbean;
   
       /**
        * The proxy type
  @@ -107,7 +107,7 @@
        */
       private final Factory factory;
   
  -    public CollectionProxy(GMBean gmbean, Class type) {
  +    public CollectionProxy(GBeanMBean gmbean, Class type) {
           this.gmbean = gmbean;
           this.type = type;
           Enhancer enhancer = new Enhancer();
  
  
  
  1.2       +5 -5      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java
  
  Index: SingleProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SingleProxy.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ SingleProxy.java	14 Jan 2004 22:16:38 -0000	1.2
  @@ -62,7 +62,7 @@
   import org.apache.geronimo.kernel.jmx.InterfaceCallbackFilter;
   import org.apache.geronimo.kernel.management.State;
   import org.apache.geronimo.gbean.WaitingException;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.gbean.jmx.Proxy;
   import org.apache.geronimo.gbean.jmx.ProxyMethodInterceptor;
   
  @@ -77,9 +77,9 @@
    */
   public class SingleProxy implements Proxy {
       /**
  -     * The GMBean to which this proxy belongs.
  +     * The GBeanMBean to which this proxy belongs.
        */
  -    private final GMBean gmbean;
  +    private final GBeanMBean gmbean;
   
       /**
        * Name of this proxy.
  @@ -101,7 +101,7 @@
        */
       private ProxyMethodInterceptor methodInterceptor;
   
  -    public SingleProxy(GMBean gmbean, String name, Class type) {
  +    public SingleProxy(GBeanMBean gmbean, String name, Class type) {
           this.gmbean = gmbean;
           this.name = name;
           Enhancer enhancer = new Enhancer();
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
  
  Index: GBeanMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.gbean.jmx;
  
  import java.lang.reflect.Constructor;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  import javax.management.Attribute;
  import javax.management.AttributeList;
  import javax.management.AttributeNotFoundException;
  import javax.management.DynamicMBean;
  import javax.management.InvalidAttributeValueException;
  import javax.management.JMException;
  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.MBeanServer;
  import javax.management.ObjectName;
  import javax.management.ReflectionException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.kernel.jmx.MBeanOperationSignature;
  import org.apache.geronimo.kernel.management.NotificationType;
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GConstructorInfo;
  import org.apache.geronimo.gbean.GEndpointInfo;
  import org.apache.geronimo.gbean.GOperationInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.gbean.GBean;
  import org.apache.geronimo.gbean.jmx.AbstractManagedObject;
  
  import net.sf.cglib.reflect.FastClass;
  
  /**
   * A GeronimoMBean is a J2EE Management Managed Object, and is standard base for Geronimo services.
   * This wraps one or more target POJOs and exposes the attributes and opperation according to a supplied
   * GeronimoMBeanInfo instance.  The GeronimoMBean also support caching of attribute values and invocation results
   * which can reduce the number of calls to a target.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/14 22:16:38 $
   */
  public class GBeanMBean extends AbstractManagedObject implements DynamicMBean {
      public static final FastClass fastClass = FastClass.create(GBeanMBean.class);
      private static final Log log = LogFactory.getLog(GBeanMBean.class);
  
      /**
       * Gets the context class loader from the thread or the system class loader if there is no context class loader.
       * @return the context class loader or the system classloader
       */
      private static ClassLoader getContextClassLoader() {
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          if (classLoader == null) {
              classLoader = ClassLoader.getSystemClassLoader();
          }
          return classLoader;
      }
  
      /**
       * Attributes supported by this GBeanMBean by (String) name.
       */
      private final Map attributeMap = new HashMap();
  
      /**
       * Endpoints supported by this GBeanMBean by (String) name.
       */
      private final Map endpointMap = new HashMap();
  
      /**
       * Opperations supported by this GBeanMBean by (MBeanOperationSignature) name.
       */
      private final Map operationMap = new HashMap();
  
      /**
       * Notifications (MBeanNotificationInfo) fired by this mbean.
       */
      private final Set notifications = new HashSet();
  
      /**
       * The classloader used for all invocations and creating targets.
       */
      private final ClassLoader classLoader;
  
      private final GBeanInfo gbeanInfo;
      private final MBeanInfo mbeanInfo;
      private final String name;
      private final String description;
      private final Class type;
  
      private boolean offline = true;
      private Object target;
  
      public GBeanMBean(GBeanInfo beanInfo, ClassLoader classLoader) throws InvalidConfigurationException {
          this.gbeanInfo = beanInfo;
          this.classLoader = classLoader;
          try {
              type = classLoader.loadClass(beanInfo.getClassName());
          } catch (ClassNotFoundException e) {
              throw new InvalidConfigurationException("Could not load GBean class from classloader: " +
                      " className=" + beanInfo.getClassName());
          }
  
          name = beanInfo.getName();
          description = beanInfo.getDescription();
  
          // attributes
          Map constructorTypes = gbeanInfo.getConstructor().getAttributeTypeMap();
          for (Iterator iterator = beanInfo.getAttributeSet().iterator(); iterator.hasNext();) {
              GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
              addAttribute(new GBeanMBeanAttribute(this, attributeInfo, (Class) constructorTypes.get(attributeInfo.getName())));
          }
  
          // endpoints
          for (Iterator iterator = beanInfo.getEndpointsSet().iterator(); iterator.hasNext();) {
              GEndpointInfo endpointInfo = (GEndpointInfo) iterator.next();
              addEndpoint(new GBeanMBeanEndpoint(this, endpointInfo, (Class) constructorTypes.get(endpointInfo.getName())));
          }
  
          // operations
          for (Iterator iterator = beanInfo.getOperationsSet().iterator(); iterator.hasNext();) {
              GOperationInfo operationInfo = (GOperationInfo) iterator.next();
              addOperation(new GBeanMBeanOperation(this, operationInfo));
          }
  
          // add all attributes and operations from the ManagedObject interface
          addManagedObjectInterface();
  
          int idx;
          idx = 0;
          MBeanAttributeInfo[] mbeanAttrs = new MBeanAttributeInfo[attributeMap.size()];
          for (Iterator i = attributeMap.values().iterator(); i.hasNext();) {
              GBeanMBeanAttribute attr = (GBeanMBeanAttribute) i.next();
              mbeanAttrs[idx++] = attr.getMBeanAttributeInfo();
          }
  
          idx = 0;
          MBeanOperationInfo[] mbeanOps = new MBeanOperationInfo[operationMap.size()];
          for (Iterator i = operationMap.values().iterator(); i.hasNext();) {
              GBeanMBeanOperation op = (GBeanMBeanOperation) i.next();
              mbeanOps[idx++] = op.getMbeanOperationInfo();
          }
  
          mbeanInfo = new MBeanInfo(
                  beanInfo.getClassName(),
                  description,
                  mbeanAttrs,
                  new MBeanConstructorInfo[0],
                  mbeanOps,
                  (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
      }
  
      public GBeanMBean(GBeanInfo beanInfo) throws InvalidConfigurationException {
          this(beanInfo, getContextClassLoader());
      }
  
      /**
       * "Bootstrapping" constructor.  The class specified is loaded and the static method
       * "getGBeanInfo" is called to get the gbean info.  Usually one will include
       * this static method in the class to be wrapped in the GBeanMBean instance.
       * @param className name of the class to call getGBeanInfo on
       * @param classLoader the class loader for this GBean
       * @throws java.lang.Exception if an exception occurs while getting the GeronimoMBeanInfo from the class
       */
      public GBeanMBean(String className, ClassLoader classLoader) throws Exception {
          this(GBeanInfo.getGBeanInfo(className, classLoader), classLoader);
      }
  
      /**
       * "Bootstrapping" constructor.  The class specified is loaded and the static method
       * "getGBeanInfo" is called to get the gbean info.  Usually one will include
       * this static method in the class to be wrapped in the GBeanMBean instance.
       * @param className name of the class to call getGBeanInfo on
       * @throws java.lang.Exception if an exception occurs while getting the GeronimoMBeanInfo from the class
       */
      public GBeanMBean(String className) throws Exception {
          this(className, ClassLoader.getSystemClassLoader());
      }
  
      public String getName() {
          return name;
      }
  
      public ClassLoader getClassLoader() {
          return classLoader;
      }
  
      public boolean isOffline() {
          return offline;
      }
  
      public Class getType() {
          return type;
      }
  
      public Object getTarget() {
          return target;
      }
  
      public synchronized ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception {
          ObjectName returnValue = super.preRegister(server, objectName);
  
  
          // get the constructor
          GConstructorInfo constructorInfo = gbeanInfo.getConstructor();
          Class[] parameterTypes = (Class[]) constructorInfo.getTypes().toArray(new Class[constructorInfo.getTypes().size()]);
          Constructor constructor = type.getConstructor(parameterTypes);
  
          // create the instance
          Object[] parameters = new Object[parameterTypes.length];
          Iterator names = constructorInfo.getAttributeNames().iterator();
          for (int i = 0; i < parameters.length; i++) {
              String name = (String) names.next();
              if (attributeMap.containsKey(name)) {
                  parameters[i] = getAttribute(name);
              } else if (endpointMap.containsKey(name)) {
                  GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) endpointMap.get(name);
                  endpoint.online();
                  parameters[i] = endpoint.getProxy();
              } else {
                  throw new InvalidConfigurationException("Unknown attribute or endpoint name in constructor: name=" + name);
              }
          }
          target = constructor.newInstance(parameters);
  
          // bring all of the attributes online
          for (Iterator iterator = attributeMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) iterator.next();
              attribute.online();
          }
  
          // bring any endpoint not used in the constructor online
          // @todo this code sucks, but works
          for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
              if (!constructorInfo.getAttributeNames().contains(endpoint.getName())) {
                  endpoint.online();
              }
          }
  
          return returnValue;
      }
  
      public void postRegister(Boolean registrationDone) {
          super.postRegister(registrationDone);
  
          if (registrationDone.booleanValue()) {
              // we're now offically on line
              offline = false;
          } else {
              // we need to bring the endpoints back off line
              for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
                  GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
                  endpoint.offline();
              }
  
              // well that didn't work, ditch the instance
              target = null;
          }
      }
  
      public void postDeregister() {
          // take all of the attributes offline
          for (Iterator iterator = attributeMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) iterator.next();
              attribute.offline();
          }
  
          // take all of the endpoints offline
          for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
              endpoint.offline();
          }
  
          offline = true;
          target = null;
  
          super.postDeregister();
      }
  
      public GBeanInfo getGBeanInfo() {
          return gbeanInfo;
      }
  
      public MBeanInfo getMBeanInfo() {
          return mbeanInfo;
      }
  
      protected void doStart() throws Exception {
          // start all of the endpoints
          for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
              endpoint.start();
          }
  
          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
          Thread.currentThread().setContextClassLoader(classLoader);
          try {
              if (target instanceof GBean) {
                  ((GBean) target).doStart();
              }
          } finally {
              Thread.currentThread().setContextClassLoader(oldClassLoader);
          }
      }
  
      protected void doStop() throws Exception {
          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
          Thread.currentThread().setContextClassLoader(classLoader);
          try {
              if (target instanceof GBean) {
                  ((GBean) target).doStop();
              }
          } finally {
              Thread.currentThread().setContextClassLoader(oldClassLoader);
          }
  
          // stop all of the endpoints
          for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
              endpoint.stop();
          }
      }
  
      protected void doFail() {
          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
          Thread.currentThread().setContextClassLoader(classLoader);
          try {
              if (target instanceof GBean) {
                  ((GBean) target).doFail();
              }
          } finally {
              Thread.currentThread().setContextClassLoader(oldClassLoader);
          }
  
          // stop all of the endpoints
          for (Iterator iterator = endpointMap.values().iterator(); iterator.hasNext();) {
              GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) iterator.next();
              endpoint.stop();
          }
      }
  
      public Object getAttribute(String attributeName) throws AttributeNotFoundException, MBeanException, ReflectionException {
          GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(attributeName);
          if (attribute == null) {
              throw new AttributeNotFoundException("Unknown attribute " + attributeName);
          }
  
          return attribute.getValue();
      }
  
      public void setAttribute(Attribute attributeValue) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
          GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(attributeValue.getName());
          if (attribute == null) {
              throw new AttributeNotFoundException("Unknown attribute " + attributeValue.getName());
          }
  
          attribute.setValue(attributeValue.getValue());
      }
  
      public void setAttribute(String name, Object value) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
          GBeanMBeanAttribute attribute = (GBeanMBeanAttribute) attributeMap.get(name);
          if (attribute == null) {
              throw new AttributeNotFoundException("Unknown attribute " + name);
          }
  
          attribute.setValue(value);
      }
  
      public AttributeList getAttributes(String[] attributes) {
          AttributeList results = new AttributeList(attributes.length);
          for (int i = 0; i < attributes.length; i++) {
              String name = attributes[i];
              try {
                  Object value = getAttribute(name);
                  results.add(new Attribute(name, value));
              } catch (JMException e) {
                  log.warn("Exception while getting attribute " + name, e);
              }
          }
          return results;
      }
  
      public AttributeList setAttributes(AttributeList attributes) {
          AttributeList results = new AttributeList(attributes.size());
          for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
              Attribute attribute = (Attribute) iterator.next();
              try {
                  setAttribute(attribute);
                  results.add(attribute);
              } catch (JMException e) {
                  log.warn("Exception while setting attribute " + attribute.getName(), e);
              }
          }
          return results;
      }
  
      public Object invoke(String methodName, Object[] arguments, String[] types) throws MBeanException, ReflectionException {
          MBeanOperationSignature key = new MBeanOperationSignature(methodName, types);
          Object operation = operationMap.get(key);
          if (operation == null) {
              throw new ReflectionException(new NoSuchMethodException("Unknown operation " + key));
          }
  
  
          // If this is an attribute accessor get call the getAttibute or setAttribute method
          if (operation instanceof GBeanMBeanAttribute) {
              if (arguments == null || arguments.length == 0) {
                  return ((GBeanMBeanAttribute) operation).getValue();
              } else {
                  ((GBeanMBeanAttribute) operation).setValue(arguments[0]);
                  return null;
              }
          }
  
          return ((GBeanMBeanOperation) operation).invoke(arguments);
      }
  
      public Set getEndpointPatterns(String name) {
          GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) endpointMap.get(name);
          if (endpoint == null) {
              throw new IllegalArgumentException("Unknown endpoint " + name);
          }
          return endpoint.getPatterns();
      }
  
      public void setEndpointPatterns(String name, Set patterns) {
          GBeanMBeanEndpoint endpoint = (GBeanMBeanEndpoint) endpointMap.get(name);
          if (endpoint == null) {
              throw new IllegalArgumentException("Unknown endpoint " + name);
          }
          endpoint.setPatterns(patterns);
      }
  
      public MBeanNotificationInfo[] getNotificationInfo() {
          return mbeanInfo.getNotifications();
      }
  
      private void addAttribute(GBeanMBeanAttribute mbeanAttribute) {
          String attributeName = mbeanAttribute.getName();
  
          // add to attribute map
          attributeMap.put(attributeName, mbeanAttribute);
      }
  
      private void addEndpoint(GBeanMBeanEndpoint mbeanEndpoint) {
          String endpointName = mbeanEndpoint.getName();
  
          // add to endpoint map
          endpointMap.put(endpointName, mbeanEndpoint);
      }
  
      private void addOperation(GBeanMBeanOperation mbeanOperation) {
          MBeanOperationSignature signature = new MBeanOperationSignature(mbeanOperation.getName(), mbeanOperation.getParameterTypes());
          operationMap.put(signature, mbeanOperation);
      }
  
      private void addManagedObjectInterface() {
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "state",
                  "J2EE Management State",
                  Integer.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return new Integer(getState());
                      }
                  },
                  null));
  
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "objectName",
                  "JMX Object Name",
                  String.class,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return getObjectName();
                      }
                  },
                  null));
  
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "startTime",
                  "Time the MBean started",
                  Long.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return new Long(getStartTime());
                      }
                  },
                  null));
  
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "stateManageable",
                  "Is this MBean state manageable?",
                  Boolean.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return new Boolean(isStateManageable());
                      }
                  },
                  null));
  
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "statisticsProvider",
                  "Does this MBean provide statistics?",
                  Boolean.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return new Boolean(isStatisticsProvider());
                      }
                  },
                  null));
  
  
          addAttribute(new GBeanMBeanAttribute(
                  this,
                  "eventProvider",
                  "Does this MBean provide events?",
                  Boolean.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          return new Boolean(isEventProvider());
                      }
                  },
                  null));
  
          addOperation(new GBeanMBeanOperation(
                  this,
                  "start",
                  "Starts the MBean",
                  Collections.EMPTY_LIST,
                  Void.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          start();
                          return null;
                      }
                  }));
  
          addOperation(new GBeanMBeanOperation(
                  this,
                  "startRecursive",
                  "Starts the MBean and then starts all the dependent MBeans",
                  Collections.EMPTY_LIST,
                  Void.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          startRecursive();
                          return null;
                      }
                  }));
  
          addOperation(new GBeanMBeanOperation(
                  this,
                  "stop",
                  "Stops the MBean",
                  Collections.EMPTY_LIST,
                  Void.TYPE,
                  new MethodInvoker() {
                      public Object invoke(Object target, Object[] arguments) throws Exception {
                          stop();
                          return null;
                      }
                  }));
  
          notifications.add(new MBeanNotificationInfo(
                  NotificationType.TYPES,
                  "javax.management.Notification",
                  "J2EE Notifications"));
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
  
  Index: GBeanMBeanAttribute.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.gbean.jmx;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import javax.management.MBeanAttributeInfo;
  import javax.management.ReflectionException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.gbean.jmx.FastMethodInvoker;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/14 22:16:38 $
   */
  public class GBeanMBeanAttribute {
      private static final Log log = LogFactory.getLog(GBeanMBeanAttribute.class);
      private final GBeanMBean gMBean;
      private final String name;
      private final Class type;
      private final boolean readable;
      private final MethodInvoker getInvoker;
      private final boolean writable;
      private final MethodInvoker setInvoker;
      private final boolean isConstructorArg;
      private final boolean persistent;
      private final MBeanAttributeInfo mbeanAttributeInfo;
  
      private Object persistentValue;
  
      public GBeanMBeanAttribute(GBeanMBean gMBean, String name, String description, Class type, MethodInvoker getInvoker, MethodInvoker setInvoker) {
  
          this.gMBean = gMBean;
          this.name = name;
          this.type = type;
          this.readable = (getInvoker != null);
          this.getInvoker = getInvoker;
          this.writable = (setInvoker != null);
          this.setInvoker = setInvoker;
          this.isConstructorArg = false;
          this.persistent = false;
          mbeanAttributeInfo = new MBeanAttributeInfo(name, type.getName(), description, readable, writable, type == Boolean.TYPE);
      }
  
      public GBeanMBeanAttribute(GBeanMBean gMBean, GAttributeInfo attributeInfo, Class constructorType) throws InvalidConfigurationException {
          if (attributeInfo.isReadable() == Boolean.FALSE &&
                  attributeInfo.isWritable() == Boolean.FALSE &&
                  !attributeInfo.isPersistent()) {
              throw new InvalidConfigurationException("An attribute must be readable, writable, or persistent: +" +
                      " name=" + attributeInfo.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
          this.gMBean = gMBean;
          this.name = attributeInfo.getName();
          this.persistent = attributeInfo.isPersistent();
          this.isConstructorArg = (constructorType != null);
  
  
          // If attribute is persistent or not tagged as unreadable, search for a getter method
          Method getterMethod = null;
          if (attributeInfo.isPersistent() || attributeInfo.isReadable() != Boolean.FALSE) {
              getterMethod = searchForGetter(gMBean, attributeInfo);
          }
          if (getterMethod != null) {
              getInvoker = new FastMethodInvoker(getterMethod);
  
              // this attribute is readable as long as it was not explicitly tagged as unreadable
              readable = attributeInfo.isReadable() != Boolean.FALSE;
          } else {
              getInvoker = null;
              readable = false;
          }
  
          // If attribute is persistent or not tagged as unwritable, search for a setter method
          Method setterMethod = null;
          if (attributeInfo.isPersistent() || attributeInfo.isWritable() != Boolean.FALSE) {
              setterMethod = searchForSetter(gMBean, attributeInfo);
          }
          if (setterMethod != null) {
              setInvoker = new FastMethodInvoker(setterMethod);
  
              // this attribute is writable as long as it was not explicitly tagged as unwritable
              writable = attributeInfo.isWritable() != Boolean.FALSE;
          } else {
              setInvoker = null;
              writable = false;
          }
  
          // getter and setter types are consistent
          if (getInvoker != null && setInvoker != null &&
                  getterMethod.getReturnType() != setterMethod.getParameterTypes()[0]) {
              throw new InvalidConfigurationException("Getter and setter methods do not have the same types:" +
                      " name=" + attributeInfo.getName() +
                      " geterMethod=" + getterMethod.getName() +
                      " seterMethod=" + setterMethod.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          // getter and constructor types are consistent
          if (constructorType != null && getterMethod != null &&
                  constructorType != getterMethod.getReturnType()) {
              throw new InvalidConfigurationException("Constructor argument and getter method do not have the same type:" +
                      " name=" + attributeInfo.getName() +
                      " constructorType=" + constructorType +
                      " geterMethod=" + getterMethod.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          // setter and constructor types are consistent
          if (constructorType != null && setterMethod != null &&
                  constructorType != setterMethod.getReturnType()) {
              throw new InvalidConfigurationException("Constructor argument and setter method do not have the same type:" +
                      " name=" + attributeInfo.getName() +
                      " constructorType=" + constructorType +
                      " seterMethod=" + setterMethod.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          // set the attribute type
          if (constructorType != null) {
              type = constructorType;
          } else if (getterMethod != null) {
              type = getterMethod.getReturnType();
          } else if (setterMethod != null) {
              type = setterMethod.getParameterTypes()[0];
          } else {
              // neither getter/setter/or constructor argument
              type = null;
          }
  
          mbeanAttributeInfo = new MBeanAttributeInfo(
                  attributeInfo.getName(),
                  type.getName(),
                  attributeInfo.getDescription(),
                  readable,
                  writable,
                  writable ? setterMethod.getName().startsWith("is") : false);
      }
  
      public String getName() {
          return name;
      }
  
      public boolean isReadable() {
          return readable;
      }
  
      public boolean isWritable() {
          return writable;
      }
  
      public Class getType() {
          return type;
      }
  
      public boolean isPersistent() {
          return persistent;
      }
  
      public MBeanAttributeInfo getMBeanAttributeInfo() {
          return mbeanAttributeInfo;
      }
  
      public void online() throws ReflectionException {
          if (persistent && !isConstructorArg && setInvoker != null) {
              ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
              try {
                  Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
                  setInvoker.invoke(gMBean.getTarget(), new Object[]{persistentValue});
              } catch (Throwable throwable) {
                  throw new ReflectionException(new InvocationTargetException(throwable));
              } finally {
                  Thread.currentThread().setContextClassLoader(oldClassLoader);
              }
          }
      }
  
      public void offline() {
          if (persistent && getInvoker != null) {
              ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
              try {
                  Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
                  persistentValue = getInvoker.invoke(gMBean.getTarget(), null);
              } catch (Throwable throwable) {
                  log.error("Could not get the current value of persistent attribute while going offline.  The " +
                          "persistent attribute will not reflect the current state attribute: name=" + name, throwable);
              } finally {
                  Thread.currentThread().setContextClassLoader(oldClassLoader);
              }
          }
      }
  
      public Object getValue() throws ReflectionException {
          if (gMBean.isOffline()) {
              if (persistent) {
                  return persistentValue;
              } else {
                  throw new IllegalStateException("Only persistent attributes can be accessed while offline");
              }
          } else {
              if (!readable) {
                  if (persistent) {
                      throw new IllegalStateException("This persistent attribute is not accessible while online");
                  } else {
                      throw new IllegalArgumentException("This attribute is not readable");
                  }
              }
              ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
              try {
                  Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
                  Object value = getInvoker.invoke(gMBean.getTarget(), null);
                  return value;
              } catch (Throwable throwable) {
                  throw new ReflectionException(new InvocationTargetException(throwable));
              } finally {
                  Thread.currentThread().setContextClassLoader(oldClassLoader);
              }
          }
      }
  
      public void setValue(Object value) throws ReflectionException {
          if (gMBean.isOffline()) {
              if (persistent) {
                  this.persistentValue = value;
              } else {
                  throw new IllegalStateException("Only persistent attributes can be modified while offline");
              }
          } else {
              if (!writable) {
                  if (persistent) {
                      throw new IllegalStateException("This persistent attribute is not modifable while online");
                  } else {
                      throw new IllegalArgumentException("This attribute is not writable");
                  }
              }
              ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
              try {
                  Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
                  setInvoker.invoke(gMBean.getTarget(), new Object[]{value});
              } catch (Throwable throwable) {
                  throw new ReflectionException(new InvocationTargetException(throwable));
              } finally {
                  Thread.currentThread().setContextClassLoader(oldClassLoader);
              }
          }
      }
  
      private static Method searchForGetter(GBeanMBean gMBean, GAttributeInfo attributeInfo) throws InvalidConfigurationException {
          if (attributeInfo.getGetterName() == null) {
              // no explicit name give so we must search for a name
              String getterName = "get" + attributeInfo.getName();
              String isName = "is" + attributeInfo.getName();
              Method[] methods = gMBean.getType().getMethods();
              for (int i = 0; i < methods.length; i++) {
                  Method method = methods[i];
                  if (method.getParameterTypes().length == 0 &&
                          method.getReturnType() != Void.TYPE &&
                          (getterName.equalsIgnoreCase(method.getName()) ||
                          isName.equalsIgnoreCase(method.getName()))) {
  
                      return method;
                  }
              }
          } else {
              // we have an explicit name, so no searching is necessary
              try {
                  Method method = gMBean.getType().getMethod(attributeInfo.getGetterName(), null);
                  if (method.getReturnType() != Void.TYPE) {
                      return method;
                  }
              } catch (Exception e) {
                  // we will throw the formatted exception below
              }
          }
  
          // if this attribute was explicity tagged as being readable but there is not getter
          if (attributeInfo.isReadable() == Boolean.TRUE) {
              throw new InvalidConfigurationException("Getter method not found on target:" +
                      " name=" + attributeInfo.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          // a getter is not necessary for this attribute
          return null;
      }
  
      private static Method searchForSetter(GBeanMBean gMBean, GAttributeInfo attributeInfo) throws InvalidConfigurationException {
          if (attributeInfo.getSetterName() == null) {
              // no explicit name give so we must search for a name
              String setterName = "set" + attributeInfo.getName();
              Method[] methods = gMBean.getType().getMethods();
              for (int i = 0; i < methods.length; i++) {
                  Method method = methods[i];
                  if (method.getParameterTypes().length == 1 &&
                          method.getReturnType() == Void.TYPE &&
                          setterName.equalsIgnoreCase(method.getName())) {
  
                      return method;
                  }
              }
          } else {
              // even though we have an exact name we need to search the methods becaus we don't know the parameter type
              Method[] methods = gMBean.getType().getMethods();
              String setterName = attributeInfo.getSetterName();
              for (int i = 0; i < methods.length; i++) {
                  Method method = methods[i];
                  if (method.getParameterTypes().length == 1 &&
                          method.getReturnType() == Void.TYPE &&
                          setterName.equals(method.getName())) {
  
                      return method;
                  }
              }
          }
  
          // An attribute must have a setter if it was explicitly tagged as writable or
          // if it is persistent and it is not a constructor arg (if it is persistent we must have
          // a way toget the data into the instance)
          if (attributeInfo.isWritable() == Boolean.TRUE) {
              throw new InvalidConfigurationException("Setter method not found on target:" +
                      " name=" + attributeInfo.getName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          // a setter is not necessary for this attribute
          return null;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanEndpoint.java
  
  Index: GBeanMBeanEndpoint.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.gbean.jmx;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Modifier;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  import javax.management.AttributeNotFoundException;
  import javax.management.InstanceNotFoundException;
  import javax.management.ListenerNotFoundException;
  import javax.management.MBeanServerNotification;
  import javax.management.Notification;
  import javax.management.NotificationFilterSupport;
  import javax.management.NotificationListener;
  import javax.management.ObjectName;
  import javax.management.ReflectionException;
  
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  import org.apache.geronimo.kernel.management.NotificationType;
  import org.apache.geronimo.kernel.management.State;
  import org.apache.geronimo.gbean.GEndpointInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.gbean.WaitingException;
  import org.apache.geronimo.gbean.jmx.CollectionProxy;
  import org.apache.geronimo.gbean.jmx.FastMethodInvoker;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/14 22:16:38 $
   */
  public class GBeanMBeanEndpoint implements NotificationListener {
      /**
       * Name of this endpoint.
       */
      private final String name;
  
      /**
       * Interface this GBeanMBean uses to refer to the other.
       */
      private final Class type;
  
      /**
       * Is this endpoint single valued or multi (collection) valued.
       */
      private final boolean singleValued;
  
      /**
       * The GBeanMBean to which this endpoint belongs.
       */
      private final GBeanMBean gmbean;
  
      /**
       * The method that will be called to set the attribute value.  If null, the value will be set with
       * a constructor argument
       */
      private final MethodInvoker setInvoker;
  
      /**
       * The target objectName patterns to watch for a connection.
       */
      private Set patterns = Collections.EMPTY_SET;
  
      /**
       * Proxy to the to this connection.
       */
      private Proxy proxy;
  
      public GBeanMBeanEndpoint(GBeanMBean gmbean, GEndpointInfo endpointInfo, Class constructorType) throws InvalidConfigurationException {
          this.gmbean = gmbean;
          this.name = endpointInfo.getName();
          try {
              this.type = gmbean.getClassLoader().loadClass(endpointInfo.getType());
          } catch (ClassNotFoundException e) {
              throw new InvalidConfigurationException("Could not load endpoint type class:" +
                      " name=" + name +
                      " class=" + endpointInfo.getType());
          }
  
          Class setterType;
          if (constructorType != null) {
              setterType = constructorType;
              setInvoker = null;
          } else {
              Method setterMethod = searchForSetter(gmbean, endpointInfo);
              setInvoker = new FastMethodInvoker(setterMethod);
              setterType = setterMethod.getParameterTypes()[0];
          }
  
          // single valued?
          if (Collection.class == setterType) {
              singleValued = false;
          } else if (setterType.isAssignableFrom(type)) {
              singleValued = true;
          } else {
              throw new IllegalArgumentException("Setter parameter or constructor type must be Collection or " + type);
          }
  
          if (Modifier.isFinal(type.getModifiers())) {
              throw new IllegalArgumentException("Proxy interface cannot be a final class: " + type.getName());
          }
      }
  
      public String getName() {
          return name;
      }
  
      public Set getPatterns() {
          return patterns;
      }
  
      public void setPatterns(Set patterns) {
          if (!gmbean.isOffline()) {
              throw new IllegalStateException("Pattern set can not be modified while online");
          }
          if (patterns == null) {
              this.patterns = Collections.EMPTY_SET;
          } else {
              this.patterns = Collections.unmodifiableSet(patterns);
          }
      }
  
      public int hashCode() {
          return super.hashCode();
      }
  
      public Object getProxy() {
          if (patterns.isEmpty()) {
              return null;
          } else {
              return proxy.getProxy();
          }
      }
  
      public synchronized void online() throws ReflectionException {
          // create the proxy
          if (singleValued) {
              proxy = new SingleProxy(gmbean, name, type);
          } else {
              proxy = new CollectionProxy(gmbean, type);
          }
  
  
          // listen for all mbean registration events
          try {
              NotificationFilterSupport mbeanServerFilter = new NotificationFilterSupport();
              mbeanServerFilter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
              mbeanServerFilter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
              gmbean.getServer().addNotificationListener(JMXUtil.DELEGATE_NAME, this, mbeanServerFilter, null);
          } catch (Exception e) {
              // this will never happen... all of the above is well formed
              throw new AssertionError(e);
          }
  
          // register for state change notifications with all mbeans that match the target patterns
          Set registeredTargets = new HashSet();
          for (Iterator targetIterator = patterns.iterator(); targetIterator.hasNext();) {
              ObjectName pattern = (ObjectName) targetIterator.next();
              Set names = gmbean.getServer().queryNames(pattern, null);
              for (Iterator objectNameIterator = names.iterator(); objectNameIterator.hasNext();) {
                  ObjectName target = (ObjectName) objectNameIterator.next();
                  if (!registeredTargets.contains(target)) {
                      try {
                          gmbean.getServer().addNotificationListener(target, this, NotificationType.STATE_CHANGE_FILTER, null);
                      } catch (InstanceNotFoundException e) {
                          // the instance died before we could get going... not a big deal
                          break;
                      }
  
                      // if the bean is running add it to the runningTargets list
                      if (isRunning(target)) {
                          proxy.addTarget(target);
                      }
                  }
              }
          }
  
          // set the proxy into the instance
          if (setInvoker != null && patterns.size() > 0) {
              ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
              try {
                  Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
                  setInvoker.invoke(gmbean.getTarget(), new Object[]{proxy.getProxy()});
              } catch (Throwable throwable) {
                  throw new ReflectionException(new InvocationTargetException(throwable));
              } finally {
                  Thread.currentThread().setContextClassLoader(oldClassLoader);
              }
          }
      }
  
      public synchronized void offline() {
          try {
              gmbean.getServer().removeNotificationListener(JMXUtil.DELEGATE_NAME, this);
          } catch (InstanceNotFoundException ignore) {
              // we don't care... the mbean we were listening to disapeared
          } catch (ListenerNotFoundException ignore) {
              // we don't care... the mbean doesn't think we were listening
          }
  
          if (proxy == null) {
              //we weren't fully online
              return;
          }
  
          // get the targets from the proxy because we are listening to them
          Set registeredTargets = proxy.getTargets();
  
          // destroy the proxy
          proxy = null;
  
          // unregister for all notifications
          for (Iterator iterator = registeredTargets.iterator(); iterator.hasNext();) {
              ObjectName target = (ObjectName) iterator.next();
              try {
                  gmbean.getServer().removeNotificationListener(target, this, NotificationType.STATE_CHANGE_FILTER, null);
              } catch (InstanceNotFoundException ignore) {
                  // we don't care... the mbean we were listening to disapeared
              } catch (ListenerNotFoundException ignore) {
                  // we don't care... the mbean doesn't think we were listening
              }
          }
      }
  
  
      public synchronized void start() throws WaitingException {
          if (!patterns.isEmpty()) {
              proxy.start();
          }
      }
  
      public synchronized void stop() {
          if (!patterns.isEmpty()) {
              proxy.stop();
          }
      }
  
      public synchronized void handleNotification(Notification notification, Object o) {
          String type = notification.getType();
  
          if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type)) {
              ObjectName source = ((MBeanServerNotification) notification).getMBeanName();
  
              // if this is not a possible peer we are done
              if (!isPossiblePeer(source)) {
                  return;
              }
  
              // register for state change notifications
              try {
                  gmbean.getServer().addNotificationListener(source, this, NotificationType.STATE_CHANGE_FILTER, null);
              } catch (InstanceNotFoundException e) {
                  // the instance died before we could get going... not a big deal
                  return;
              }
  
              if (isRunning(source)) {
                  proxy.addTarget(source);
              }
          } else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type)) {
              proxy.removeTarget(((MBeanServerNotification) notification).getMBeanName());
          } else if (NotificationType.STATE_RUNNING.equals(type)) {
              final ObjectName source = (ObjectName) notification.getSource();
              if (isPossiblePeer(source)) {
                  proxy.addTarget(source);
              }
          } else if (NotificationType.STATE_STOPPED.equals(type) || NotificationType.STATE_FAILED.equals(type)) {
              proxy.removeTarget((ObjectName) notification.getSource());
          }
      }
  
  
      /**
       * Is the component in the Running state
       * @param objectName name of the component to check
       * @return true if the component is running; false otherwise
       */
      private boolean isRunning(ObjectName objectName) {
          try {
              final int state = ((Integer) gmbean.getServer().getAttribute(objectName, "state")).intValue();
              return state == State.RUNNING_INDEX;
          } catch (AttributeNotFoundException e) {
              // ok -- mbean is not a startable
              return true;
          } catch (InstanceNotFoundException e) {
              // mbean is no longer registerd
              return false;
          } catch (Exception e) {
              // problem getting the attribute, mbean has most likely failed
              return false;
          }
      }
  
      /**
       * Is the component a possible peer.  A component is a possible peer if
       * its name matched onee of the object name patterns we watch.
       * @param objectName name of the component to check
       * @return true if the component is a possible peer; false otherwise
       */
      private synchronized boolean isPossiblePeer(ObjectName objectName) {
          for (Iterator iterator = patterns.iterator(); iterator.hasNext();) {
              ObjectName pattern = (ObjectName) iterator.next();
              if (pattern.apply(objectName)) {
                  return true;
              }
          }
          return false;
      }
  
      private static Method searchForSetter(GBeanMBean gMBean, GEndpointInfo endpointInfo) throws InvalidConfigurationException {
          if (endpointInfo.getSetterName() == null) {
              // no explicit name give so we must search for a name
              String setterName = "set" + endpointInfo.getName();
              Method[] methods = gMBean.getType().getMethods();
              for (int i = 0; i < methods.length; i++) {
                  Method method = methods[i];
                  if (method.getParameterTypes().length == 1 &&
                          method.getReturnType() == Void.TYPE &&
                          setterName.equalsIgnoreCase(method.getName())) {
  
                      return method;
                  }
              }
          } else {
              // even though we have an exact name we need to search the methods becaus we don't know the parameter type
              Method[] methods = gMBean.getType().getMethods();
              String setterName = endpointInfo.getSetterName();
              for (int i = 0; i < methods.length; i++) {
                  Method method = methods[i];
                  if (method.getParameterTypes().length == 1 &&
                          method.getReturnType() == Void.TYPE &&
                          setterName.equals(method.getName())) {
  
                      return method;
                  }
              }
          }
          throw new InvalidConfigurationException("Target does not have specified method:" +
                  " name=" + endpointInfo.getName() +
                  " targetClass=" + gMBean.getType().getName());
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
  
  Index: GBeanMBeanOperation.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.gbean.jmx;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  import javax.management.MBeanException;
  import javax.management.MBeanOperationInfo;
  import javax.management.MBeanParameterInfo;
  import javax.management.ReflectionException;
  
  import org.apache.geronimo.gbean.GOperationInfo;
  import org.apache.geronimo.gbean.GParameterInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.gbean.jmx.FastMethodInvoker;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/14 22:16:38 $
   */
  public class GBeanMBeanOperation {
      private final GBeanMBean gMBean;
      private final String name;
      private final List parameterTypes;
      private final MBeanOperationInfo mbeanOperationInfo;
      private final MethodInvoker methodInvoker;
  
      public GBeanMBeanOperation(GBeanMBean gMBean, String name, String description, List parameterTypes, Class returnType, MethodInvoker methodInvoker) {
          this.gMBean = gMBean;
          this.name = name;
          this.parameterTypes = parameterTypes;
          this.methodInvoker = methodInvoker;
  
          MBeanParameterInfo[] signature = new MBeanParameterInfo[parameterTypes.size()];
          for (int i = 0; i < signature.length; i++) {
              Class parameterType = (Class) parameterTypes.get(i);
              signature[i] = new MBeanParameterInfo(
                      "arg" + i,
                      parameterType.getName(),
                      null);
          }
  
          mbeanOperationInfo = new MBeanOperationInfo(
                  name,
                  description,
                  signature,
                  returnType.getName(),
                  MBeanOperationInfo.UNKNOWN
          );
  
      }
  
      public GBeanMBeanOperation(GBeanMBean gMBean, GOperationInfo operationInfo) throws InvalidConfigurationException {
          this.gMBean = gMBean;
          this.name = operationInfo.getName();
          ClassLoader classLoader = gMBean.getClassLoader();
  
          // get an array of the parameter classes
          List parameterList = operationInfo.getParameterList();
          parameterTypes = new ArrayList(parameterList.size());
          for (Iterator iterator = parameterList.iterator(); iterator.hasNext();) {
              GParameterInfo parameterInfo = (GParameterInfo) iterator.next();
              try {
                  parameterTypes.add(classLoader.loadClass(parameterInfo.getType()));
              } catch (ClassNotFoundException e) {
                  throw new InvalidConfigurationException("Could not load operation parameter class:" +
                          " name=" + operationInfo.getName() +
                          " class=" + parameterInfo.getType());
              }
          }
  
          // get a method invoker for the operation
          Class returnType;
          try {
              Class[] types = (Class[]) parameterTypes.toArray(new Class[parameterTypes.size()]);
              Method javaMethod = gMBean.getType().getMethod(operationInfo.getMethodName(), types);
              returnType = javaMethod.getReturnType();
              methodInvoker = new FastMethodInvoker(javaMethod);
          } catch (Exception e) {
              throw new InvalidConfigurationException("Target does not have specified method:" +
                      " name=" + operationInfo.getName() +
                      " methodName=" + operationInfo.getMethodName() +
                      " targetClass=" + gMBean.getType().getName());
          }
  
          MBeanParameterInfo[] signature = new MBeanParameterInfo[parameterList.size()];
          for (int i = 0; i < signature.length; i++) {
              GParameterInfo parameterInfo = (GParameterInfo) parameterList.get(i);
              signature[i] = new MBeanParameterInfo(
                      parameterInfo.getName(),
                      parameterInfo.getType(),
                      parameterInfo.getDescription());
          }
  
          mbeanOperationInfo = new MBeanOperationInfo(
                  operationInfo.getName(),
                  operationInfo.getDescription(),
                  signature,
                  returnType.getName(),
                  MBeanOperationInfo.UNKNOWN
          );
      }
  
      public String getName() {
          return name;
      }
  
      public List getParameterTypes() {
          return Collections.unmodifiableList(parameterTypes);
      }
  
      public MBeanOperationInfo getMbeanOperationInfo() {
          return mbeanOperationInfo;
      }
  
      public Object invoke(Object[] arguments) throws MBeanException, ReflectionException {
          if (gMBean.isOffline()) {
              throw new IllegalStateException("Operations can not be called while offline");
          }
  
          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
          try {
              Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
              return methodInvoker.invoke(gMBean.getTarget(), arguments);
          } catch (Throwable throwable) {
              throw new ReflectionException(new InvocationTargetException(throwable));
          } finally {
              Thread.currentThread().setContextClassLoader(oldClassLoader);
          }
      }
  }
  
  
  
  1.3       +10 -10    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
  
  Index: Kernel.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Kernel.java	14 Jan 2004 08:31:07 -0000	1.2
  +++ Kernel.java	14 Jan 2004 22:16:38 -0000	1.3
  @@ -72,7 +72,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.gbean.GBeanInfo;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.kernel.config.ConfigurationStore;
   import org.apache.geronimo.kernel.config.InvalidConfigException;
   import org.apache.geronimo.kernel.config.LocalConfigStore;
  @@ -122,14 +122,14 @@
       private transient Log log;
       private transient boolean running;
       private transient MBeanServer mbServer;
  -    private transient GMBean storeGBean;
  +    private transient GBeanMBean storeGBean;
       private transient ConfigurationStore store;
   
       /**
        * Construct a Kernel using the specified JMX domain and supply the
        * information needed to create the ConfigurationStore.
        * @param domainName the domain name to be used for the JMX MBeanServer
  -     * @param storeInfo the info for the GMBean to be used for the ConfigurationStore
  +     * @param storeInfo the info for the GBeanMBean to be used for the ConfigurationStore
        * @param configStore a local directory to be used by the ConfigurationStore;
        *                    this must be present and writable when the kernel is booted
        */
  @@ -159,19 +159,19 @@
           if (!running) {
               throw new IllegalStateException("Kernel is not running");
           }
  -        GMBean config = store.getConfig(configID);
  +        GBeanMBean config = store.getConfig(configID);
           URL baseURL = store.getBaseURL(configID);
           return load(config, baseURL);
       }
   
       /**
        * Load the supplied Configuration into the Kernel and define its root using the specified URL.
  -     * @param config the GMBean representing the Configuration
  +     * @param config the GBeanMBean representing the Configuration
        * @param rootURL the URL to be used to resolve relative paths in the configuration
        * @return the JMX ObjectName the Kernel registered the Configuration under
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is not valid
        */
  -    public ObjectName load(GMBean config, URL rootURL) throws InvalidConfigException {
  +    public ObjectName load(GBeanMBean config, URL rootURL) throws InvalidConfigException {
           URI configID;
           try {
               configID = (URI) config.getAttribute("ID");
  @@ -192,12 +192,12 @@
        * Load the supplied Configuration into the Kernel and override the default JMX name.
        * This method should be used with discretion as it is possible to create
        * Configurations that cannot be located by management or monitoring tools.
  -     * @param config the GMBean representing the Configuration
  +     * @param config the GBeanMBean representing the Configuration
        * @param rootURL the URL to be used to resolve relative paths in the configuration
        * @param configName the JMX ObjectName to register the Configuration under
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is not valid
        */
  -    public void load(GMBean config, URL rootURL, ObjectName configName) throws InvalidConfigException {
  +    public void load(GBeanMBean config, URL rootURL, ObjectName configName) throws InvalidConfigException {
           if (!running) {
               throw new IllegalStateException("Kernel is not running");
           }
  @@ -266,7 +266,7 @@
           mbServer = MBeanServerFactory.createMBeanServer(domainName);
           mbServer.registerMBean(this, KERNEL);
           mbServer.registerMBean(new DependencyService2(), DEPENDENCY_SERVICE);
  -        storeGBean = new GMBean(storeInfo);
  +        storeGBean = new GBeanMBean(storeInfo);
           storeGBean.setAttribute("root", configStore);
           mbServer.registerMBean(storeGBean, CONFIG_STORE);
           storeGBean.start();
  
  
  
  1.2       +3 -3      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java
  
  Index: KernelMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- KernelMBean.java	12 Jan 2004 01:39:46 -0000	1.1
  +++ KernelMBean.java	14 Jan 2004 22:16:38 -0000	1.2
  @@ -63,7 +63,7 @@
   
   import org.apache.geronimo.kernel.config.InvalidConfigException;
   import org.apache.geronimo.kernel.config.NoSuchConfigException;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   
   /**
    *
  @@ -73,7 +73,7 @@
   public interface KernelMBean {
       public MBeanServer getMBeanServer();
   
  -    public ObjectName load(GMBean config, URL baseURL) throws InvalidConfigException;
  +    public ObjectName load(GBeanMBean config, URL baseURL) throws InvalidConfigException;
   
       public void unload(ObjectName configName) throws NoSuchConfigException;
   
  
  
  
  1.3       +11 -11    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Configuration.java	14 Jan 2004 08:31:07 -0000	1.2
  +++ Configuration.java	14 Jan 2004 22:16:38 -0000	1.3
  @@ -88,8 +88,8 @@
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GConstructorInfo;
   import org.apache.geronimo.gbean.GEndpointInfo;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  -import org.apache.geronimo.gbean.jmx.GMBeanTarget;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
  +import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.kernel.Kernel;
   
   /**
  @@ -121,7 +121,7 @@
    *
    * @version $Revision$ $Date$
    */
  -public class Configuration implements GMBeanTarget {
  +public class Configuration implements GBean {
       private static final Log log = LogFactory.getLog(Configuration.class);
   
       private final URI id;
  @@ -172,7 +172,7 @@
           for (Iterator i = gbeans.entrySet().iterator(); i.hasNext();) {
               Map.Entry entry = (Map.Entry) i.next();
               ObjectName name = (ObjectName) entry.getKey();
  -            GMBean gbean = (GMBean) entry.getValue();
  +            GBeanMBean gbean = (GBeanMBean) entry.getValue();
               mbServer.registerMBean(gbean, name);
               mbServer.invoke(Kernel.DEPENDENCY_SERVICE, "addDependency", new Object[] { name, objectName}, new String[] {ObjectName.class.getName(), ObjectName.class.getName()});
           }
  @@ -273,7 +273,7 @@
        * Load GBeans from the supplied byte array using the supplied ClassLoader
        * @param gbeanState the serialized form of the GBeans
        * @param cl the ClassLoader used to locate classes needed during deserialization
  -     * @return a Map<ObjectName, GMBean> of GBeans loaded from the persisted state
  +     * @return a Map<ObjectName, GBeanMBean> of GBeans loaded from the persisted state
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem deserializing the state
        */
       public static Map loadGBeans(byte[] gbeanState, ClassLoader cl) throws InvalidConfigException {
  @@ -284,7 +284,7 @@
                   while (true) {
                       ObjectName objectName = (ObjectName) ois.readObject();
                       GBeanInfo info = (GBeanInfo) ois.readObject();
  -                    GMBean gbean = new GMBean(info, cl);
  +                    GBeanMBean gbean = new GBeanMBean(info, cl);
                       loadGMBeanState(gbean, ois);
                       gbeans.put(objectName, gbean);
                   }
  @@ -299,7 +299,7 @@
           }
       }
   
  -    static void loadGMBeanState(GMBean gbean, ObjectInputStream ois) throws IOException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, ClassNotFoundException {
  +    static void loadGMBeanState(GBeanMBean gbean, ObjectInputStream ois) throws IOException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, ClassNotFoundException {
           int attributeCount = ois.readInt();
           for (int i = 0; i < attributeCount; i ++) {
               gbean.setAttribute((String)ois.readObject(), ois.readObject());
  @@ -312,7 +312,7 @@
   
       /**
        * Return a byte array containing the persisted form of the supplied GBeans
  -     * @param gbeans a Map<ObjectName, GMBean> of GBeans to store
  +     * @param gbeans a Map<ObjectName, GBeanMBean> of GBeans to store
        * @return the persisted GBeans
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem serializing the state
        */
  @@ -324,7 +324,7 @@
               for (Iterator i = gbeans.entrySet().iterator(); i.hasNext();) {
                   Map.Entry entry = (Map.Entry) i.next();
                   ObjectName objectName = (ObjectName) entry.getKey();
  -                GMBean gbean = (GMBean) entry.getValue();
  +                GBeanMBean gbean = (GBeanMBean) entry.getValue();
                   oos.writeObject(objectName);
                   oos.writeObject(gbean.getGBeanInfo());
                   storeGMBeanState(gbean, oos);
  @@ -336,7 +336,7 @@
           return baos.toByteArray();
       }
   
  -    static void storeGMBeanState(GMBean gbean, ObjectOutputStream oos) throws IOException, AttributeNotFoundException, MBeanException, ReflectionException {
  +    static void storeGMBeanState(GBeanMBean gbean, ObjectOutputStream oos) throws IOException, AttributeNotFoundException, MBeanException, ReflectionException {
           List persistentAttributes = gbean.getGBeanInfo().getPersistentAttributes();
           oos.writeInt(persistentAttributes.size());
           for (Iterator j = persistentAttributes.iterator(); j.hasNext();) {
  
  
  
  1.2       +4 -4      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java
  
  Index: ConfigurationStore.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigurationStore.java	12 Jan 2004 01:39:46 -0000	1.1
  +++ ConfigurationStore.java	14 Jan 2004 22:16:38 -0000	1.2
  @@ -60,7 +60,7 @@
   import java.net.URI;
   import java.net.URL;
   
  -import org.apache.geronimo.gbean.jmx.GMBean;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   
   /**
    * Interface to a store for Configurations.
  @@ -79,12 +79,12 @@
       /**
        * Return the Configuration GBean for the specified ID
        * @param id the unique ID of a Configuration
  -     * @return the GMBean for that configuration
  +     * @return the GBeanMBean for that configuration
        * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if the store does not contain a Configuration with that id
        * @throws java.io.IOException if there was a problem loading the Configuration from the store
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is invalid
        */
  -    GMBean getConfig(URI id) throws NoSuchConfigException, IOException, InvalidConfigException;
  +    GBeanMBean getConfig(URI id) throws NoSuchConfigException, IOException, InvalidConfigException;
   
       /**
        * Return the base URL for the specified ID
  
  
  
  1.3       +10 -10    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/LocalConfigStore.java
  
  Index: LocalConfigStore.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/LocalConfigStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocalConfigStore.java	14 Jan 2004 08:31:07 -0000	1.2
  +++ LocalConfigStore.java	14 Jan 2004 22:16:38 -0000	1.3
  @@ -81,15 +81,15 @@
   import org.apache.geronimo.gbean.GConstructorInfo;
   import org.apache.geronimo.gbean.InvalidConfigurationException;
   import org.apache.geronimo.gbean.WaitingException;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  -import org.apache.geronimo.gbean.jmx.GMBeanTarget;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
  +import org.apache.geronimo.gbean.GBean;
   
   /**
    * Implementation of ConfigurationStore using the local filesystem.
    *
    * @version $Revision$ $Date$
    */
  -public class LocalConfigStore implements ConfigurationStore, GMBeanTarget {
  +public class LocalConfigStore implements ConfigurationStore, GBean {
       private static final String INDEX_NAME = "index.properties";
       private final File root;
       private final Properties index = new Properties();
  @@ -176,7 +176,7 @@
                   }
               }
               try {
  -                GMBean config = loadConfig(bundleRoot);
  +                GBeanMBean config = loadConfig(bundleRoot);
                   index.setProperty(config.getAttribute("ID").toString(), newId);
               } catch (Exception e) {
                   throw new InvalidConfigException("Unable to get ID from downloaded configuration", e);
  @@ -195,7 +195,7 @@
           }
       }
   
  -    public synchronized GMBean getConfig(URI configID) throws NoSuchConfigException, IOException, InvalidConfigException {
  +    public synchronized GBeanMBean getConfig(URI configID) throws NoSuchConfigException, IOException, InvalidConfigException {
           return loadConfig(getRoot(configID));
       }
   
  @@ -216,16 +216,16 @@
           return new File(root, id);
       }
   
  -    private GMBean loadConfig(File configRoot) throws IOException, InvalidConfigException {
  +    private GBeanMBean loadConfig(File configRoot) throws IOException, InvalidConfigException {
           FileInputStream fis = new FileInputStream(new File(configRoot, "META-INF/config.ser"));
           try {
               ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
               GBeanInfo gbeanInfo = Configuration.GBEAN_INFO;
  -            GMBean config;
  +            GBeanMBean config;
               try {
  -                config = new GMBean(gbeanInfo);
  +                config = new GBeanMBean(gbeanInfo);
               } catch (InvalidConfigurationException e) {
  -                throw new InvalidConfigException("Unable to instantiate Configuration GMBean", e);
  +                throw new InvalidConfigException("Unable to instantiate Configuration GBeanMBean", e);
               }
               try {
                   Configuration.loadGMBeanState(config, ois);
  
  
  
  1.4       +10 -10    incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
  
  Index: ConfigTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConfigTest.java	14 Jan 2004 20:41:56 -0000	1.3
  +++ ConfigTest.java	14 Jan 2004 22:16:38 -0000	1.4
  @@ -61,18 +61,18 @@
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.Map;
  -
   import javax.management.InstanceNotFoundException;
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
   
  -import junit.framework.TestCase;
   import org.apache.geronimo.gbean.GBeanInfo;
  -import org.apache.geronimo.gbean.jmx.GMBean;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.kernel.config.Configuration;
   import org.apache.geronimo.kernel.config.LocalConfigStore;
   import org.apache.geronimo.kernel.management.State;
   
  +import junit.framework.TestCase;
  +
   /**
    *
    *
  @@ -89,18 +89,18 @@
       private ObjectName gbeanName2;
   
       public void testOfflineConfig() throws Exception {
  -        GMBean config = new GMBean(Configuration.GBEAN_INFO);
  +        GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO);
           config.setAttribute("ID", new URI("test"));
           config.setEndpointPatterns("Parent", null);
       }
   
       public void testOnlineConfig() throws Exception {
  -        GMBean config = new GMBean(Configuration.GBEAN_INFO);
  +        GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO);
           config.setAttribute("ID", new URI("test"));
           config.setEndpointPatterns("Parent", null);
           config.setAttribute("ClassPath", Collections.EMPTY_LIST);
           config.setAttribute("GBeanState", state);
  -        ObjectName configName = (ObjectName) mbServer.invoke(Kernel.KERNEL, "load", new Object[]{config, null}, new String[]{GMBean.class.getName(), URL.class.getName()});
  +        ObjectName configName = (ObjectName) mbServer.invoke(Kernel.KERNEL, "load", new Object[]{config, null}, new String[]{GBeanMBean.class.getName(), URL.class.getName()});
           mbServer.invoke(configName, "startRecursive", null, null);
   
           assertEquals(new Integer(State.RUNNING.toInt()), mbServer.getAttribute(configName, "state"));
  @@ -119,7 +119,7 @@
               // ok
           }
           assertEquals(new Integer(State.STOPPED.toInt()), mbServer.getAttribute(configName, "state"));
  -        mbServer.invoke(Kernel.KERNEL, "unload", new Object[] {configName}, new String[] {ObjectName.class.getName()});
  +        mbServer.invoke(Kernel.KERNEL, "unload", new Object[]{configName}, new String[]{ObjectName.class.getName()});
           assertFalse(mbServer.isRegistered(configName));
       }
   
  @@ -134,11 +134,11 @@
           mbServer = kernel.getMBeanServer();
   
           gbeanName1 = new ObjectName("geronimo.test:name=MyMockGMBean1");
  -        GMBean mockBean1 = new GMBean(MockGBean.getGBeanInfo());
  +        GBeanMBean mockBean1 = new GBeanMBean(MockGBean.getGBeanInfo());
           mockBean1.setAttribute("Value", "1234");
           mockBean1.setAttribute("Name", "child");
           gbeanName2 = new ObjectName("geronimo.test:name=MyMockGMBean2");
  -        GMBean mockBean2 = new GMBean(MockGBean.getGBeanInfo());
  +        GBeanMBean mockBean2 = new GBeanMBean(MockGBean.getGBeanInfo());
           mockBean2.setAttribute("Value", "5678");
           mockBean2.setAttribute("Name", "Parent");
           mockBean2.setEndpointPatterns("MockEndpoint", Collections.singleton(gbeanName1));
  
  
  
  1.4       +5 -4      incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/config/LocalConfigStoreTest.java
  
  Index: LocalConfigStoreTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/config/LocalConfigStoreTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalConfigStoreTest.java	14 Jan 2004 20:41:56 -0000	1.3
  +++ LocalConfigStoreTest.java	14 Jan 2004 22:16:38 -0000	1.4
  @@ -64,8 +64,9 @@
   import java.util.jar.JarOutputStream;
   import java.util.zip.ZipEntry;
   
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
  +
   import junit.framework.TestCase;
  -import org.apache.geronimo.gbean.jmx.GMBean;
   
   /**
    *
  @@ -83,7 +84,7 @@
           store.install(source);
           assertTrue(new File(root, "1/META-INF/config.ser").exists());
           assertEquals(new File(root, "1").toURL(), store.getBaseURL(uri));
  -        GMBean config = store.getConfig(uri);
  +        GBeanMBean config = store.getConfig(uri);
           assertEquals(uri, config.getAttribute("ID"));
       }
   
  @@ -94,7 +95,7 @@
           store = new LocalConfigStore(root);
           store.doStart();
   
  -        GMBean gbean = new GMBean(Configuration.GBEAN_INFO);
  +        GBeanMBean gbean = new GBeanMBean(Configuration.GBEAN_INFO);
           uri = new URI("test");
           gbean.setAttribute("ID", uri);
           sourceFile = File.createTempFile("test", ".car");
  
  
  

Mime
View raw message