geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r106610 - in geronimo/trunk/modules: axis/src/java/org/apache/geronimo/axis deployment/src/java/org/apache/geronimo/deployment deployment/src/java/org/apache/geronimo/deployment/cli kernel/src/java/org/apache/geronimo/gbean/jmx kernel/src/java/org/apache/geronimo/gbean/runtime kernel/src/java/org/apache/geronimo/kernel kernel/src/java/org/apache/geronimo/kernel/config kernel/src/java/org/apache/geronimo/kernel/proxy kernel/src/test/org/apache/geronimo/gbean kernel/src/test/org/apache/geronimo/gbean/jmx kernel/src/test/org/apache/geronimo/gbean/runtime kernel/src/test/org/apache/geronimo/kernel
Date Thu, 25 Nov 2004 21:40:44 GMT
Author: dain
Date: Thu Nov 25 13:40:42 2004
New Revision: 106610

URL: http://svn.apache.org/viewcvs?view=rev&rev=106610
Log:
Removed last bits of JMX from the GBean architecture.
GBean now only uses the kernel, which still depends on JMX, but the GBean codes doesn't know that.
Moved all GBean code from the jmx package to the runtime package except or the GBeanMBean wrapper.
Changed the kernel to throw geronimo specific exceptions insted of JMX exception.
More work still needs to be done in the Kernel itself to remove JMX exceptions.
Changed Configuration not try to override the classloader attribute.  Instead it has a configurationClassLoader attribute.

Added:
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanJMXUtil.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/AbstractGBeanReference.java
      - copied, changed from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/FastMethodInvoker.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanCollectionReference.java
      - copied, changed from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceLifecycleController.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanOperation.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanReference.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java
      - copied, changed from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/MethodInvoker.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java
      - copied, changed from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/RawInvoker.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/Util.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanAlreadyExistsException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanNotFoundException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InternalKernelException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InvalidGBeanException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchAttributeException.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchOperationException.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
      - copied, changed from r106386, geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java
Removed:
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java
Modified:
   geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java

Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java?view=diff&rev=106610&p1=geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java&r1=106609&p2=geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java	(original)
+++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/EJBWSGBean.java	Thu Nov 25 13:40:42 2004
@@ -23,6 +23,11 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
+import javax.management.ObjectName;
+
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -31,54 +36,72 @@
  */
 public class EJBWSGBean implements GBeanLifecycle {
     private static Log log = LogFactory.getLog(EJBWSGBean.class);
-    
-    public static final GBeanInfo GBEAN_INFO;
-    private final String objectName; 
-    
-    private Collection classList;
-    private final Configuration ejbConfig;
+    /**
+     * Field name
+     */
+    private final String name;
+
+    /**
+     * Field GBEAN_INFO
+     */
+    private static final GBeanInfo GBEAN_INFO;
 
+    /**
+     * Field objectName
+     */
+    private final ObjectName objectName;
+    private Configuration ejbConfig;
+    private Collection classList;
 
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("EJBWSGBean",
                 EJBWSGBean.class);
 
+
         // attributes
+        infoFactory.addAttribute("Name", String.class, true);
         infoFactory.addAttribute("objectName", String.class, false);
+        infoFactory.addReference("ejbConfig", Configuration.class);
         infoFactory.addAttribute("classList", Collection.class, true);
-        
-        infoFactory.addReference("EjbConfig", Configuration.class);
-
         // operations
-        infoFactory.setConstructor(new String[]{"objectName"});
-        infoFactory.setConstructor(new String[]{"objectName","EjbConfig"});
+        infoFactory.setConstructor(new String[]{"Name",
+                                                "objectName"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 
-
-    public EJBWSGBean(String objectName) {
-        this.objectName = objectName;
-        this.ejbConfig = null;
-    }
-
-    public EJBWSGBean(String objectName,Configuration ejbConfig) {
-        this.objectName = objectName;
-        System.out.println(ejbConfig);
-        this.ejbConfig = (Configuration)ejbConfig;
+    /**
+     * Constructor AxisGbean
+     *
+     * @param name
+     * @param objectName
+     */
+    public EJBWSGBean(String name, String objectName) {
+        this.name = name;
+        this.objectName = JMXUtil.getObjectName(objectName);
     }
 
-
-    
+    /**
+     * Method doFail
+     */
     public void doFail() {
+        log.info("Axis GBean has failed");
     }
 
+    /**
+     * Method doStart
+     *
+     * @throws WaitingException
+     * @throws Exception
+     */
     public void doStart() throws WaitingException, Exception {
-        ClassLoader cl = ejbConfig.getClassLoader();
+        System.out.println(name + "has started");
+        ClassLoader cl = ejbConfig.getConfigurationClassLoader();
         for (Iterator it = classList.iterator(); it.hasNext();) {
             String className = (String) it.next();
             ClassUtils.setClassLoader(className, cl);
         }
         AxisGeronimoUtils.addEntryToAxisDD(cl.getResourceAsStream("deploy.wsdd"));
+        log.info(objectName);
     }
 
     /**
@@ -91,24 +114,49 @@
         log.info("WebServiceGBean has stoped");
     }
 
+    /**
+     * Method getGBeanInfo
+     *
+     * @return
+     */
     public static GBeanInfo getGBeanInfo() {
         return GBEAN_INFO;
     }
 
+    /**
+     * Method getName
+     *
+     * @return
+     */
+    public String getName() {
+        return name;
+    }
 
-
+    /**
+     * @return
+     */
     public Collection getClassList() {
         return classList;
     }
 
+    /**
+     * @return
+     */
+    public Configuration getEjbConfig() {
+        return ejbConfig;
+    }
+
+    /**
+     * @param collection
+     */
     public void setClassList(Collection collection) {
         classList = collection;
     }
 
-//    public Configuration getEjbConfig() {
-//        return ejbConfig;
-//    }
-//    public void setEjbConfig(Configuration configuration) {
-//        ejbConfig = configuration;
-//    }
+    /**
+     * @param configuration
+     */
+    public void setEjbConfig(Configuration configuration) {
+        ejbConfig = configuration;
+    }
 }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?view=diff&rev=106610&p1=geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java&r1=106609&p2=geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java	Thu Nov 25 13:40:42 2004
@@ -126,7 +126,7 @@
                 }
             }
             try {
-                parentCL = (ClassLoader) kernel.getAttribute(parentName, "classLoader");
+                parentCL = (ClassLoader) kernel.getAttribute(parentName, "configurationClassLoader");
             } catch (Exception e) {
                 throw new DeploymentException(e);
             }
@@ -171,7 +171,7 @@
      * <p/>
      * NOTE: The class loader that is obtained from this deployment context
      * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getClassLoader</code> method.
+     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the packed jar file should be placed
      * @param jarFile    the jar file to copy
@@ -190,7 +190,7 @@
      * <p/>
      * NOTE: The class loader that is obtained from this deployment context
      * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getClassLoader</code> method.
+     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the ZIP file entry should be placed
      * @param zipFile    the ZIP file
@@ -210,7 +210,7 @@
      * <p/>
      * NOTE: The class loader that is obtained from this deployment context
      * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getClassLoader</code> method.
+     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the file should be placed
      * @param source     the URL of file to be copied
@@ -229,7 +229,7 @@
      * <p/>
      * NOTE: The class loader that is obtained from this deployment context
      * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getClassLoader</code> method.
+     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the file should be placed
      * @param source     the file to be copied
@@ -247,7 +247,7 @@
      * <p/>
      * NOTE: The class loader that is obtained from this deployment context
      * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getClassLoader</code> method.
+     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param moduleFile    the jar file from which the manifest is obtained.
      * @param moduleBaseUri the base for the imported classpath

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java?view=diff&rev=106610&p1=geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java&r1=106609&p2=geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java	Thu Nov 25 13:40:42 2004
@@ -17,15 +17,18 @@
 
 package org.apache.geronimo.deployment.cli;
 
-import org.apache.geronimo.deployment.DeploymentException;
-
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
 import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.Target;
 import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.enterprise.deploy.spi.status.ProgressObject;
-import java.io.PrintWriter;
-import java.io.File;
-import java.util.*;
+
+import org.apache.geronimo.deployment.DeploymentException;
 
 /**
  * The CLI deployer logic to distribute.

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java?view=auto&rev=106609
==============================================================================

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanJMXUtil.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanJMXUtil.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanJMXUtil.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,91 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.gbean.jmx;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GOperationInfo;
+import org.apache.geronimo.kernel.management.NotificationType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class GBeanJMXUtil {
+    private GBeanJMXUtil() {
+    }
+
+    public static MBeanInfo toMBeanInfo(GBeanInfo gBeanInfo) {
+        String className = gBeanInfo.getClassName();
+        String description = "No description available";
+
+        // attributes
+        Set gbeanAttributes = gBeanInfo.getAttributes();
+        MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[gbeanAttributes.size()];
+        int a = 0;
+        for (Iterator iterator = gbeanAttributes.iterator(); iterator.hasNext();) {
+            GAttributeInfo gAttributeInfo = (GAttributeInfo) iterator.next();
+            attributes[a] = new MBeanAttributeInfo(gAttributeInfo.getName(), "no description available", gAttributeInfo.getType(), gAttributeInfo.isReadable().booleanValue(), gAttributeInfo.isWritable().booleanValue(), isIs(gAttributeInfo));
+            a++;
+        }
+
+        //we don't expose managed constructors
+        MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[0];
+
+        // operations
+        Set gbeanOperations = gBeanInfo.getOperations();
+        MBeanOperationInfo[] operations = new MBeanOperationInfo[gbeanOperations.size()];
+        int o = 0;
+        for (Iterator iterator = gbeanOperations.iterator(); iterator.hasNext();) {
+            GOperationInfo gOperationInfo = (GOperationInfo) iterator.next();
+            //list of class names
+            List gparameters = gOperationInfo.getParameterList();
+            MBeanParameterInfo[] parameters = new MBeanParameterInfo[gparameters.size()];
+            int p = 0;
+            for (Iterator piterator = gparameters.iterator(); piterator.hasNext();) {
+                String type = (String) piterator.next();
+                parameters[p] = new MBeanParameterInfo("parameter" + p, type, "no description available");
+                p++;
+            }
+            operations[o] = new MBeanOperationInfo(gOperationInfo.getName(), "no description available", parameters, "java.lang.Object", MBeanOperationInfo.UNKNOWN);
+            o++;
+        }
+
+        MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[1];
+        notifications[0] = new MBeanNotificationInfo(NotificationType.TYPES, "javax.management.Notification", "J2EE Notifications");
+
+        MBeanInfo mbeanInfo = new MBeanInfo(className, description, attributes, constructors, operations, notifications);
+        return mbeanInfo;
+    }
+
+    private static boolean isIs(GAttributeInfo gAttributeInfo) {
+        String getterName = gAttributeInfo.getGetterName();
+        if (getterName == null) {
+            return false;
+        }
+        return getterName.startsWith("is");
+    }
+}

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	Thu Nov 25 13:40:42 2004
@@ -17,46 +17,37 @@
 
 package org.apache.geronimo.gbean.jmx;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
-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.JMException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanConstructorInfo;
+import javax.management.ListenerNotFoundException;
 import javax.management.MBeanInfo;
 import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanOperationInfo;
+import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanOperationInfo;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.gbean.GBeanLifecycleController;
-import org.apache.geronimo.gbean.GConstructorInfo;
-import org.apache.geronimo.gbean.GOperationInfo;
 import org.apache.geronimo.gbean.GOperationSignature;
-import org.apache.geronimo.gbean.GReferenceInfo;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
-import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.NoSuchOperationException;
 import org.apache.geronimo.kernel.management.NotificationType;
 
 /**
@@ -67,21 +58,9 @@
  *
  * @version $Rev$ $Date$
  */
-public class GBeanMBean extends AbstractManagedObject implements DynamicMBean {
-    /**
-     * Attribute name used to retrieve the RawInvoker for the GBean
-     * @deprecated DO NOT USE THIS... THIS WILL BE REMOVED!!!!!!
-     */
-    public static final String RAW_INVOKER = "$$RAW_INVOKER$$";
-
-    /**
-     * Attribute name used to retrieve the GBeanData for the GBean
-     */
-    public static final String GBEAN_DATA = "$$GBEAN_DATA$$";
-
+public final class GBeanMBean implements DynamicMBean, MBeanRegistration, NotificationEmitter {
     private static final Log log = LogFactory.getLog(GBeanMBean.class);
-    private final Constructor constructor;
-    private final GBeanLifecycleController gbeanLifecycleController;
+    private static final MBeanInfo DEFAULT_MBEAN_INFO = new MBeanInfo("java.lang.Object", "", new MBeanAttributeInfo[0], new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]);
 
     /**
      * Gets the context class loader from the thread or the system class loader if there is no context class loader.
@@ -97,39 +76,29 @@
     }
 
     /**
-     * Attributes lookup table
-     */
-    private final GBeanMBeanAttribute[] attributes;
-
-    /**
-     * Attributes supported by this GBeanMBean by (String) name.
-     */
-    private final Map attributeIndex = new HashMap();
-
-    /**
-     * References lookup table
+     * Attribute name used to retrieve the GBeanData for the GBean
      */
-    private final GBeanReference[] references;
+    public static final String GBEAN_DATA = "$$GBEAN_DATA$$";
 
     /**
-     * References supported by this GBeanMBean by (String) name.
+     * The kernel in which this server is registered.
      */
-    private final Map referenceIndex = new HashMap();
+    private Kernel kernel;
 
     /**
-     * Operations lookup table
+     * The unique name of this service.
      */
-    private final GBeanMBeanOperation[] operations;
+    private ObjectName objectName;
 
     /**
-     * Operations supported by this GBeanMBean by (GOperationSignature) name.
+     * The data of the
      */
-    private final Map operationIndex = new HashMap();
+    private GBeanData gbeanData;
 
     /**
-     * Notifications (MBeanNotificationInfo) fired by this mbean.
+     * The instance for this gbean mbean
      */
-    private final Set notifications = new HashSet();
+    private GBeanInstance gbeanInstance;
 
     /**
      * The classloader used for all invocations and creating targets.
@@ -137,46 +106,41 @@
     private final ClassLoader classLoader;
 
     /**
-     * Metadata describing the attributes, operations and references of this GBean
-     */
-    private final GBeanInfo gbeanInfo;
-
-    /**
      * JMX sped mbeanInfo for this gbean (translation of the above gbeanInfo
      */
-    private final MBeanInfo mbeanInfo;
-
-    /**
-     * Our name
-     */
-    private final String name;
-
-    /**
-     * Java type of the wrapped GBean class
-     */
-    private final Class type;
+    private MBeanInfo mbeanInfo = DEFAULT_MBEAN_INFO;
 
     /**
-     * Is this gbean offline?
+     * The broadcaster for notifications
      */
-    private boolean offline = true;
+    private JMXLifecycleBroadcaster lifecycleBroadcaster;
 
     /**
-     * Is this gbean running?
+     * This is the constructor used by the kernel.  This constructor should not be used dirctly.
+     * Instedad you should use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
      */
-    private boolean running = false;
+    public GBeanMBean(Kernel kernel, GBeanData gbeanData, ClassLoader classLoader) throws InvalidConfigurationException {
+        this.kernel = kernel;
+        this.gbeanData = gbeanData;
+        this.classLoader = classLoader;
 
-    /**
-     * Target instance of this GBean wrapper
-     */
-    private Object target;
+        this.objectName = gbeanData.getName();
+    }
 
     /**
-     * A fast index based raw invoker for this GBean.
+     * This constructor allows the kernel to bootstrap and existing GBeanInstance directly into the MBeanServer.
+     * @deprecated DO NOT USE
      */
-    private final RawInvoker rawInvoker;
+    public GBeanMBean(Kernel kernel, GBeanInstance gbeanInstance, JMXLifecycleBroadcaster lifecycleBroadcaster) throws InvalidConfigurationException {
+        this.kernel = kernel;
+        this.gbeanInstance = gbeanInstance;
+        this.lifecycleBroadcaster = lifecycleBroadcaster;
 
-    private Kernel kernel;
+        this.objectName = gbeanInstance.getObjectNameObject();
+        this.gbeanData = gbeanInstance.getGBeanData();
+        this.classLoader = gbeanInstance.getClassLoader();
+    }
 
     /**
      * Constructa a GBeanMBean using the supplied GBeanData and class loader
@@ -185,14 +149,11 @@
      * @param classLoader the class loader used to load the gbean instance and attribute/reference types
      * @throws InvalidConfigurationException if the gbeanInfo is inconsistent with the actual java classes, such as
      * mismatched attribute types or the intial data can not be set
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
      */
     public GBeanMBean(GBeanData gbeanData, ClassLoader classLoader) throws InvalidConfigurationException {
-        this(gbeanData.getGBeanInfo(), classLoader);
-        try {
-            setGBeanData(gbeanData);
-        } catch (Exception e) {
-            throw new InvalidConfigurationException("GBeanData could not be loaded into the GBeanMBean", e);
-        }
+        this.classLoader = classLoader;
+        this.gbeanData = gbeanData;
     }
 
     /**
@@ -202,330 +163,34 @@
      * @param classLoader the class loader used to load the gbean instance and attribute/reference types
      * @throws InvalidConfigurationException if the gbeanInfo is inconsistent with the actual java classes, such as
      * mismatched attribute types
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
      */
     public GBeanMBean(GBeanInfo gbeanInfo, ClassLoader classLoader) throws InvalidConfigurationException {
-        this.gbeanInfo = gbeanInfo;
-        this.classLoader = classLoader;
-        try {
-            type = classLoader.loadClass(gbeanInfo.getClassName());
-        } catch (ClassNotFoundException e) {
-            throw new InvalidConfigurationException("Could not load GBeanInfo class from classloader: " +
-                    " className=" + gbeanInfo.getClassName());
-        }
-
-        name = gbeanInfo.getName();
-
-        // get the constructor
-        constructor = searchForConstructor(gbeanInfo, type);
-
-        // build a map from constructor argument names to type
-        Class[] constructorParameterTypes = constructor.getParameterTypes();
-        Map constructorTypes = new HashMap(constructorParameterTypes.length);
-        List constructorAttributeNames = this.gbeanInfo.getConstructor().getAttributeNames();
-        for (int i = 0; i < constructorParameterTypes.length; i++) {
-            Class type = constructorParameterTypes[i];
-            constructorTypes.put(constructorAttributeNames.get(i), type);
-        }
-
-        // attributes
-        Map attributesMap = new HashMap();
-        for (Iterator iterator = gbeanInfo.getAttributes().iterator(); iterator.hasNext();) {
-            GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
-            attributesMap.put(attributeInfo.getName(), new GBeanMBeanAttribute(this, attributeInfo, constructorTypes.containsKey(attributeInfo.getName())));
-        }
-        addManagedObjectAttributes(attributesMap);
-        attributes = (GBeanMBeanAttribute[]) attributesMap.values().toArray(new GBeanMBeanAttribute[attributesMap.size()]);
-        for (int i = 0; i < attributes.length; i++) {
-            attributeIndex.put(attributes[i].getName(), new Integer(i));
-        }
-
-        // references
-        Set referencesSet = new HashSet();
-        for (Iterator iterator = gbeanInfo.getReferences().iterator(); iterator.hasNext();) {
-            GReferenceInfo referenceInfo = (GReferenceInfo) iterator.next();
-            Class constructorType = (Class) constructorTypes.get(referenceInfo.getName());
-            if (isCollectionValuedReference(this, referenceInfo, constructorType)) {
-                referencesSet.add(new GBeanCollectionReference(this, referenceInfo, constructorType));
-            } else {
-                referencesSet.add(new GBeanSingleReference(this, referenceInfo, constructorType));
-            }
-        }
-        references = (GBeanReference[]) referencesSet.toArray(new GBeanReference[gbeanInfo.getReferences().size()]);
-        for (int i = 0; i < references.length; i++) {
-            referenceIndex.put(references[i].getName(), new Integer(i));
-        }
-
-        // operations
-        Map operationsMap = new HashMap();
-        for (Iterator iterator = gbeanInfo.getOperations().iterator(); iterator.hasNext();) {
-            GOperationInfo operationInfo = (GOperationInfo) iterator.next();
-            GBeanMBeanOperation operation = new GBeanMBeanOperation(this, operationInfo);
-            GOperationSignature signature = new GOperationSignature(operation.getName(), operation.getParameterTypes());
-            operationsMap.put(signature, operation);
-        }
-        addManagedObjectOperations(operationsMap);
-        operations = new GBeanMBeanOperation[operationsMap.size()];
-        int opCounter = 0;
-        for (Iterator iterator = operationsMap.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry)iterator.next();
-            operations[opCounter] = (GBeanMBeanOperation) entry.getValue();
-            operationIndex.put(entry.getKey(), new Integer(opCounter));
-            opCounter++;
-        }
-
-        // add notification type from the ManagedObject interface
-        notifications.add(new MBeanNotificationInfo(NotificationType.TYPES,
-                "javax.management.Notification",
-                "J2EE Notifications"));
-
-        // Build the MBeanInfo
-        ArrayList mbeanAttributesList = new ArrayList(attributes.length);
-        for (int i = 0; i < attributes.length; i++) {
-            // only add the attributes that are readable or writable
-            MBeanAttributeInfo mbeanAttributeInfo = attributes[i].getMBeanAttributeInfo();
-            if (mbeanAttributeInfo != null) {
-                mbeanAttributesList.add(mbeanAttributeInfo);
-            }
-        }
-        MBeanAttributeInfo[] mbeanAttributes = (MBeanAttributeInfo[]) mbeanAttributesList.toArray(new MBeanAttributeInfo[mbeanAttributesList.size()]);
-
-        MBeanOperationInfo[] mbeanOperations = new MBeanOperationInfo[operations.length];
-        for (int i = 0; i < operations.length; i++) {
-            mbeanOperations[i] = operations[i].getMbeanOperationInfo();
-        }
-
-        mbeanInfo = new MBeanInfo(gbeanInfo.getClassName(),
-                null,
-                mbeanAttributes,
-                new MBeanConstructorInfo[0],
-                mbeanOperations,
-                // Is there any way to add notifications before an instance of the class is created?
-                (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
-
-        rawInvoker = new RawInvoker(this);
-
-        gbeanLifecycleController = new GBeanMBeanLifecycleController(this);
-    }
-
-    private static boolean isCollectionValuedReference(GBeanMBean gbeanMBean, GReferenceInfo referenceInfo, Class constructorType) {
-        if (constructorType != null) {
-            return Collection.class == constructorType;
-        } else {
-            Method setterMethod = AbstractGBeanReference.searchForSetter(gbeanMBean, referenceInfo);
-            return Collection.class == setterMethod.getParameterTypes()[0];
-        }
-    }
-
-    /**
-     * Search for a single valid constructor in the class.  A valid constructor is determined by the
-     * attributes and references declared in the GBeanInfo.  For each, constructor gbean attribute
-     * the parameter must have the exact same type.  For a constructor gbean reference parameter, the
-     * parameter type must either match the reference proxy type, be java.util.Collection, or be
-     * java.util.Set.
-     *
-     * @param beanInfo the metadata describing the constructor, attrbutes and references
-     * @param type the target type in which we search for a constructor
-     * @return the sole matching constructor
-     * @throws InvalidConfigurationException if there are no valid constructors or more then one valid
-     * constructors; multiple constructors can match in the case of a gbean reference parameter
-     */
-    private static Constructor searchForConstructor(GBeanInfo beanInfo, Class type) throws InvalidConfigurationException {
-        Set attributes = beanInfo.getAttributes();
-        Map attributeTypes = new HashMap(attributes.size());
-        for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
-            GAttributeInfo attribute = (GAttributeInfo) iterator.next();
-            attributeTypes.put(attribute.getName(), attribute.getType());
-        }
-
-        Set references = beanInfo.getReferences();
-        Map referenceTypes = new HashMap(references.size());
-        for (Iterator iterator = references.iterator(); iterator.hasNext();) {
-            GReferenceInfo reference = (GReferenceInfo) iterator.next();
-            referenceTypes.put(reference.getName(), reference.getType());
-        }
-
-        List arguments = beanInfo.getConstructor().getAttributeNames();
-        String[] argumentTypes = new String[arguments.size()];
-        boolean[] isReference = new boolean[arguments.size()];
-        for (int i = 0; i < argumentTypes.length; i++) {
-            String argumentName = (String) arguments.get(i);
-            if (attributeTypes.containsKey(argumentName)) {
-                argumentTypes[i] = (String) attributeTypes.get(argumentName);
-                isReference[i] = false;
-            } else if (referenceTypes.containsKey(argumentName)) {
-                argumentTypes[i] = (String) referenceTypes.get(argumentName);
-                isReference[i] = true;
-            }
-        }
-
-        Constructor[] constructors = type.getConstructors();
-        Set validConstructors = new HashSet();
-        for (int i = 0; i < constructors.length; i++) {
-            Constructor constructor = constructors[i];
-            if (isValidConstructor(constructor, argumentTypes, isReference)) {
-                validConstructors.add(constructor);
-            }
-        }
-
-        if (validConstructors.isEmpty()) {
-            throw new InvalidConfigurationException("Could not find a valid constructor for GBean: " + beanInfo.getName());
-        }
-        if (validConstructors.size() > 1) {
-            throw new InvalidConfigurationException("More then one valid constructors found for GBean: " + beanInfo.getName());
-        }
-        return (Constructor) validConstructors.iterator().next();
+        this(new GBeanData(gbeanInfo), classLoader);
     }
 
     /**
-     * Is this a valid constructor for the GBean.  This is determined based on the argument types and
-     * if an argument is a reference, as determined by the boolean array, the argument may also be
-     * java.util.Collection or java.util.Set.
-     *
-     * @param constructor the class constructor
-     * @param argumentTypes types of the attributes and references
-     * @param isReference if the argument is a gbean reference
-     * @return true if this is a valid constructor for gbean; false otherwise
-     */
-    private static boolean isValidConstructor(Constructor constructor, String[] argumentTypes, boolean[] isReference) {
-        Class[] parameterTypes = constructor.getParameterTypes();
-
-        // same number of parameters?
-        if (parameterTypes.length != argumentTypes.length) {
-            return false;
-        }
-
-        // is each parameter the correct type?
-        for (int i = 0; i < parameterTypes.length; i++) {
-            String parameterType = parameterTypes[i].getName();
-            if (isReference[i]) {
-                // reference: does type match
-                // OR is it a java.util.Collection
-                // OR is it a java.util.Set?
-                if (!parameterType.equals(argumentTypes[i]) &&
-                        !parameterType.equals(Collection.class.getName()) &&
-                        !parameterType.equals(Set.class.getName())) {
-                    return false;
-                }
-            } else {
-                // attribute: does type match?
-                if (!parameterType.equals(argumentTypes[i])) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    public GBeanMBean(GBeanInfo beanInfo) throws InvalidConfigurationException {
-        this(beanInfo, getContextClassLoader());
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
+     */
+    public GBeanMBean(GBeanInfo gbeanInfo) throws InvalidConfigurationException {
+        this(new GBeanData(gbeanInfo), 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 GBeanInfo from the class
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
      */
     public GBeanMBean(String className, ClassLoader classLoader) throws Exception {
-        this(GBeanInfo.getGBeanInfo(className, classLoader), classLoader);
+        this(new GBeanData(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 GBeanInfo from the class
+     * @deprecated use kernel.loadGBean(GBeanData gbeanData, ClassLoader classLoader)
      */
     public GBeanMBean(String className) throws Exception {
         this(className, ClassLoader.getSystemClassLoader());
     }
 
     /**
-     * Gets the name of the GBean as defined in the gbean info.
-     *
-     * @return the gbean name
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * The class loader used to build this gbean.  This class loader is set into the thread context
-     * class loader before callint the target instace.
-     *
-     * @return the class loader used to build this gbean
-     */
-    public ClassLoader getClassLoader() {
-        return classLoader;
-    }
-
-    /**
-     * Is this gbean offline. An offline gbean is not registered with jmx and effectivly invisible
-     * to external users.
-     *
-     * @return true if the gbean is offline
-     */
-    public boolean isOffline() {
-        return offline;
-    }
-
-    /**
-     * Is this gbean running. Operations and non-persistenct attribtes can not be accessed while not running.
-     *
-     * @return true if the gbean is runing
-     */
-    public boolean isRunning() {
-        return running;
-    }
-
-    /**
-     * The java type of the wrapped gbean instance
-     *
-     * @return the java type of the gbean
-     */
-    public Class getType() {
-        return type;
-    }
-
-    public Object getTarget() {
-        return target;
-    }
-
-    /**
-     * Gets an unmodifiable map from attribute names to index number (Integer).  This index number
-     * can be used to efficiently set or retrieve an attribute value.
-     *
-     * @return an unmodifiable map of attribute indexes by name
-     */
-    public Map getAttributeIndex() {
-        return Collections.unmodifiableMap(new HashMap(attributeIndex));
-    }
-
-    /**
-     * Gets an unmodifiable map from operation signature (GOperationSignature) to index number (Integer).
-     * This index number can be used to efficciently invoke the operation.
-     *
-     * @return an unmodifiable map of operation indexec by signature
-     */
-    public Map getOperationIndex() {
-        return Collections.unmodifiableMap(new HashMap(operationIndex));
-    }
-
-    /**
-     * Gets the GBeanInfo used to build this gbean.
-     *
-     * @return the GBeanInfo used to build this gbean
-     */
-    public GBeanInfo getGBeanInfo() {
-        return gbeanInfo;
-    }
-
-    /**
      * Gets the MBeanInfo equivilent of the GBeanInfo used to construct this gbean.
      *
      * @return the MBeanInfo for this gbean
@@ -535,215 +200,48 @@
     }
 
     public synchronized ObjectName preRegister(MBeanServer server, ObjectName objectName) throws Exception {
-        ObjectName returnValue = super.preRegister(server, objectName);
-
-        setAttribute("objectName", getObjectName());
-        setAttribute("gbeanLifecycleController", gbeanLifecycleController);
-        setAttribute("classLoader", classLoader);
-        try {
-            String kernelName = (String) server.getAttribute(Kernel.KERNEL, "KernelName");
-            kernel = Kernel.getKernel(kernelName);
-            setAttribute("kernel", kernel);
-        } catch (Exception e) {
-            setAttribute("kernel", null);
-        }
-
-        return returnValue;
-    }
-
-    public void postRegister(Boolean registrationDone) {
-        super.postRegister(registrationDone);
-
-        if (registrationDone.booleanValue()) {
-            // we're now offically on line
-            for (int i = 0; i < references.length; i++) {
-                references[i].online(kernel);
-            }
-
-            offline = false;
-        } else {
-            kernel = null;
-            target = null;
-        }
-    }
-
-    public void postDeregister() {
-        // just to be sure, stop all the references again
-        for (int i = 0; i < references.length; i++) {
-            references[i].offline();
-        }
-
-        offline = true;
-        kernel = null;
-        target = null;
-
-        super.postDeregister();
-    }
-
-    protected void doStart() throws Exception {
-        // start each of the references... if they need to wait remember the
-        // waiting exception so we can throw it later. this way we the dependecies
-        // are held until we can start
-        WaitingException waitingException = null;
-        for (int i = 0; i < references.length; i++) {
+        if (gbeanInstance == null) {
+            this.objectName = objectName;
             try {
-                references[i].start();
-            } catch (WaitingException e) {
-                waitingException = e;
-            }
-        }
-        if (waitingException != null) {
-            throw waitingException;
-        }
-
-        GConstructorInfo constructorInfo = gbeanInfo.getConstructor();
-        Class[] parameterTypes = constructor.getParameterTypes();
-
-        // create constructor parameter array
-        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 (attributeIndex.containsKey(name)) {
-                GBeanMBeanAttribute attribute = getAttributeByName(name);
-                parameters[i] = attribute.getPersistentValue();
-            } else if (referenceIndex.containsKey(name)) {
-                parameters[i] = getReferenceByName(name).getProxy();
-            } else {
-                throw new InvalidConfigurationException("Unknown attribute or reference name in constructor: name=" + name);
-            }
-            assert parameters[i] == null || parameterTypes[i].isPrimitive() || parameterTypes[i].isAssignableFrom(parameters[i].getClass()):
-                    "Attempting to construct " + objectName + " of type " + gbeanInfo.getClassName()
-                    + ". Constructor parameter " + i + " should be " + parameterTypes[i].getName()
-                    + " but is " + parameters[i].getClass().getName();
-        }
-
-        // create instance
-        try {
-            target = constructor.newInstance(parameters);
-        } catch (InvocationTargetException e) {
-            Throwable targetException = e.getTargetException();
-            if (targetException instanceof Exception) {
-                throw (Exception) targetException;
-            } else if (targetException instanceof Error) {
-                throw (Error) targetException;
+                String kernelName = (String) server.getAttribute(Kernel.KERNEL, "KernelName");
+                kernel = Kernel.getKernel(kernelName);
+            } catch (Exception e) {
+                throw new IllegalStateException("No kernel is registered in this MBeanServer");
             }
-            throw e;
-        } catch (IllegalArgumentException e) {
-            log.warn("Constructor mismatch for " + objectName, e);
-            throw e;
-        }
-
-        // inject the persistent attribute value into the new instance
-        for (int i = 0; i < attributes.length; i++) {
-            attributes[i].inject();
-        }
 
-        // inject the proxies into the new instance
-        for (int i = 0; i < references.length; i++) {
-            references[i].inject();
-        }
-
-        running = true;
-        if (target instanceof GBeanLifecycle) {
-            ((GBeanLifecycle) target).doStart();
+            gbeanData.setName(objectName);
+            lifecycleBroadcaster = new JMXLifecycleBroadcaster();
+            gbeanInstance = new GBeanInstance(kernel, gbeanData, lifecycleBroadcaster, classLoader);
+            mbeanInfo = GBeanJMXUtil.toMBeanInfo(gbeanInstance.getGBeanInfo());
         }
+        return gbeanInstance.getObjectNameObject();
     }
 
-    protected void doStop() throws Exception {
-        if (target instanceof GBeanLifecycle) {
-            ((GBeanLifecycle) target).doStop();
-        }
-
-        running = false;
-
-        // stop all of the references
-        for (int i = 0; i < references.length; i++) {
-            references[i].stop();
-        }
-
-        if (target != null) {
-            // stop all of the attributes
-            for (int i = 0; i < attributes.length; i++) {
-                GBeanMBeanAttribute attribute = attributes[i];
-                if (attribute.isPersistent() && attribute.isReadable()) {
-                    // copy the current attribute value to the persistent value
-                    Object value = attribute.getValue();
-                    attribute.setPersistentValue(value);
-                }
+    public synchronized void postRegister(Boolean registrationDone) {
+        if (!registrationDone.booleanValue()) {
+            if (gbeanInstance != null) {
+                gbeanInstance.destroy();
+                gbeanInstance = null;
             }
-
-            target = null;
+            mbeanInfo = DEFAULT_MBEAN_INFO;
+            lifecycleBroadcaster = null;
+            kernel = null;
+            objectName = null;
         }
     }
 
-    protected void doFail() {
-        running = false;
-
-        if (target instanceof GBeanLifecycle) {
-            ((GBeanLifecycle) target).doFail();
-        }
-
-        // stop all of the references
-        for (int i = 0; i < references.length; i++) {
-            references[i].stop();
-        }
-
-        target = null;
-        
-        // do not stop the attibutes in the case of a failure
-        // failed gbeans may have corrupted attributes that would be persisted
+    public void preDeregister() throws Exception {
     }
 
-    /**
-     * Gets the attribute value using the attribute index.  This is the most efficient way to get
-     * an attribute as it avoids a HashMap lookup.
-     *
-     * @param index the index of the attribute
-     * @return the attribute value
-     * @throws ReflectionException if a problem occurs while getting the value
-     * @throws IndexOutOfBoundsException if the index is invalid
-     */
-    public Object getAttribute(int index) throws ReflectionException {
-        GBeanMBeanAttribute attribute = attributes[index];
-        if (running || attribute.isFramework()) {
-            return attribute.getValue();
-        } else {
-            return attribute.getPersistentValue();
-        }
-    }
-
-    /**
-     * Gets an attribute's value by name.  This get style is less efficient becuse the attribute must
-     * first be looked up in a HashMap.
-     *
-     * @param attributeName the name of the attribute to retrieve
-     * @return the attribute value
-     * @throws ReflectionException if a problem occurs while getting the value
-     * @throws AttributeNotFoundException if the attribute name is not found in the map
-     */
-    public Object getAttribute(String attributeName) throws ReflectionException, AttributeNotFoundException {
-        GBeanMBeanAttribute attribute;
-        try {
-            attribute = getAttributeByName(attributeName);
-        } catch (AttributeNotFoundException e) {
-            if (attributeName.equals(RAW_INVOKER)) {
-                return rawInvoker;
-            }
-
-            if (attributeName.equals(GBEAN_DATA)) {
-                return getGBeanData();
-
-            }
-
-            throw e;
-        }
-
-        if (running || attribute.isFramework()) {
-            return attribute.getValue();
-        } else {
-            return attribute.getPersistentValue();
+    public synchronized void postDeregister() {
+        if (gbeanInstance != null) {
+            gbeanData = gbeanInstance.getGBeanData();
+            gbeanInstance.destroy();
+            gbeanInstance = null;
         }
+        mbeanInfo = DEFAULT_MBEAN_INFO;
+        kernel = null;
+        objectName = null;
     }
 
     /**
@@ -751,120 +249,65 @@
      * @return the gbean data
      */
     public GBeanData getGBeanData() {
-        GBeanData gbeanData = new GBeanData(objectName, gbeanInfo);
-
-        // add the attributes
-        for (int i = 0; i < attributes.length; i++) {
-            GBeanMBeanAttribute attribute = attributes[i];
-            if (attribute.isPersistent()) {
-                String name = attribute.getName();
-                Object value;
-                if ((running || attribute.isFramework()) && attribute.isReadable()) {
-                    try {
-                        value = attribute.getValue();
-                    } catch (Throwable throwable) {
-                        value = attribute.getPersistentValue();
-                        log.debug("Could not get the current value of persistent attribute.  The persistent " +
-                                "attribute will not reflect the current state attribute. " + attribute.getDescription(), throwable);
-                    }
-                } else {
-                    value = attribute.getPersistentValue();
-                }
-                gbeanData.setAttribute(name, value);
-            }
-        }
-
-        // add the references
-        for (int i = 0; i < references.length; i++) {
-            GBeanReference reference = references[i];
-            String name = reference.getName();
-            Set patterns = reference.getPatterns();
-            gbeanData.setReferencePatterns(name, patterns);
+        if (gbeanInstance != null) {
+            return gbeanInstance.getGBeanData();
+        } else {
+            return gbeanData;
         }
-        return gbeanData;
     }
 
-    public void setGBeanData(GBeanData gbeanData) throws ReflectionException, AttributeNotFoundException {
-        // set the attributes
-        Map attributes = gbeanData.getAttributes();
-        for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String name = (String) entry.getKey();
-            Object value = entry.getValue();
-            setAttribute(name, value);
-        }
-
-        // add the references
-        Map references = gbeanData.getReferences();
-        for (Iterator iterator = references.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String name = (String) entry.getKey();
-            Set patterns = (Set) entry.getValue();
-            setReferencePatterns(name, patterns);
+    public void setGBeanData(GBeanData gbeanData) throws Exception {
+        if (gbeanInstance != null) {
+            gbeanInstance.setGBeanData(gbeanData);
+        } else {
+            this.gbeanData = gbeanData;
         }
     }
 
-    /**
-     * Sets the attribute value using the attribute index.  This is the most efficient way to set
-     * an attribute as it avoids a HashMap lookup.
-     *
-     * @param index the index of the attribute
-     * @param value the new value of attribute value
-     * @throws ReflectionException if a problem occurs while setting the value
-     * @throws IndexOutOfBoundsException if the index is invalid
-     */
-    public void setAttribute(int index, Object value) throws ReflectionException, IndexOutOfBoundsException {
-        GBeanMBeanAttribute attribute = attributes[index];
-        if (running || attribute.isFramework()) {
-            attribute.setValue(value);
+    public Object getAttribute(String name) throws ReflectionException, AttributeNotFoundException {
+        if (gbeanInstance == null) {
+            return gbeanData.getAttribute(name);
         } else {
-            attribute.setPersistentValue(value);
+            try {
+                return gbeanInstance.getAttribute(name);
+            } catch (NoSuchAttributeException e) {
+                throw new AttributeNotFoundException(name);
+            } catch (Exception e) {
+                throw new ReflectionException(e);
+            }
         }
     }
 
-    /**
-     * Sets an attribute's value by name.  This set style is less efficient becuse the attribute must
-     * first be looked up in a HashMap.
-     *
-     * @param attributeName the name of the attribute to retrieve
-     * @param value the new attribute value
-     * @throws ReflectionException if a problem occurs while getting the value
-     * @throws AttributeNotFoundException if the attribute name is not found in the map
-     */
-    public void setAttribute(String attributeName, Object value) throws ReflectionException, AttributeNotFoundException {
-        GBeanMBeanAttribute attribute = getAttributeByName(attributeName);
-        if (running || attribute.isFramework()) {
-            attribute.setValue(value);
+    public void setAttribute(String name, Object value) throws ReflectionException, AttributeNotFoundException {
+        if (gbeanInstance == null) {
+            gbeanData.setAttribute(name, value);
         } else {
-            attribute.setPersistentValue(value);
+            try {
+                gbeanInstance.setAttribute(name, value);
+            } catch (NoSuchAttributeException e) {
+                throw new AttributeNotFoundException(name);
+            } catch (Exception e) {
+                throw new ReflectionException(e);
+            }
         }
     }
 
-    /**
-     * Sets an attirubte's value by name.  This set style is generally very inefficient becuse the attribute object
-     * is usually constructed first and the target attribute must be looked up in a HashMap.
-     *
-     * @param attributeValue the attribute object, which contains a name and value
-     * @throws ReflectionException if a problem occurs while getting the value
-     * @throws AttributeNotFoundException if the attribute name is not found in the map
-     */
-    public void setAttribute(Attribute attributeValue) throws ReflectionException, AttributeNotFoundException {
-        GBeanMBeanAttribute attribute = getAttributeByName(attributeValue.getName());
-        Object value = attributeValue.getValue();
-        if (running || attribute.isFramework()) {
-            attribute.setValue(value);
+    public void setAttribute(Attribute attribute) throws ReflectionException, AttributeNotFoundException {
+        String name = attribute.getName();
+        Object value = attribute.getValue();
+        if (gbeanInstance == null) {
+            gbeanData.setAttribute(name, value);
         } else {
-            attribute.setPersistentValue(value);
+            try {
+                gbeanInstance.setAttribute(name, value);
+            } catch (NoSuchAttributeException e) {
+                throw new AttributeNotFoundException(name);
+            } catch (Exception e) {
+                throw new ReflectionException(e);
+            }
         }
     }
 
-    /**
-     * Gets several attirubte values by name.  This set style is very inefficient becuse each attribute implementation
-     * must be looked up in a HashMap by name and each value must be wrapped in an Attribute object and that requires
-     * lots of object creation.  Further, any exceptions are not seen by the caller.
-     *
-     * @param attributes the attribute objects, which contains a name and value
-     */
     public AttributeList getAttributes(String[] attributes) {
         AttributeList results = new AttributeList(attributes.length);
         for (int i = 0; i < attributes.length; i++) {
@@ -879,13 +322,6 @@
         return results;
     }
 
-    /**
-     * Sets several attirubte values by name.  This set style is generally very inefficient becuse each attribute object
-     * is usually constructed first and the target attribute must be looked up in a HashMap.  Further
-     * any exception are not seen by the caller.
-     *
-     * @param attributes the attribute objects, which contains a name and value
-     */
     public AttributeList setAttributes(AttributeList attributes) {
         AttributeList results = new AttributeList(attributes.size());
         for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
@@ -900,45 +336,18 @@
         return results;
     }
 
-    private GBeanMBeanAttribute getAttributeByName(String name) throws AttributeNotFoundException {
-        Integer index = (Integer) attributeIndex.get(name);
-        if (index == null) {
-            throw new AttributeNotFoundException("Unknown attribute " + name);
-        }
-        GBeanMBeanAttribute attribute = attributes[index.intValue()];
-        return attribute;
-    }
-
-    public Object invoke(int index, Object[] arguments) throws ReflectionException {
-        GBeanMBeanOperation operation = operations[index];
-        if (!running && !operation.isFramework()) {
-            throw new IllegalStateException("Operations can only be invoke while the GBean is running: " + getObjectName());
-        }
-        return operation.invoke(arguments);
-    }
-
-    /**
-     * Invokes an operation on the target gbean by method signature.  This style if invocation is
-     * inefficient, because the target method must be looked up in a hashmap using a freshly constructed
-     * GOperationSignature object.
-     *
-     * @param operationName the name of the operation to invoke
-     * @param arguments arguments to the operation
-     * @param types types of the operation arguemtns
-     * @return the result of the operation
-     * @throws ReflectionException if a problem occurs while invokeing the operation
-     */
     public Object invoke(String operationName, Object[] arguments, String[] types) throws ReflectionException {
-        GOperationSignature signature = new GOperationSignature(operationName, types);
-        Integer index = (Integer) operationIndex.get(signature);
-        if (index == null) {
-            throw new ReflectionException(new NoSuchMethodException("Unknown operation " + signature));
-        }
-        GBeanMBeanOperation operation = operations[index.intValue()];
-        if (!running && !operation.isFramework()) {
-            throw new IllegalStateException("Operations can only be invoke while the GBean is running: " + getObjectName());
+        if (gbeanInstance == null) {
+            throw new IllegalStateException("An offline gbean can not be invoked: " + objectName);
+        } else {
+            try {
+                return gbeanInstance.invoke(operationName, arguments, types);
+            } catch (NoSuchOperationException e) {
+                throw new ReflectionException(new NoSuchMethodException(new GOperationSignature(operationName, types).toString()));
+            } catch (Exception e) {
+                throw new ReflectionException(e);
+            }
         }
-        return operation.invoke(arguments);
     }
 
     /**
@@ -948,7 +357,11 @@
      * @return the object name patterns for the reference
      */
     public Set getReferencePatterns(String name) {
-        return getReferenceByName(name).getPatterns();
+        if (gbeanInstance != null) {
+            return gbeanInstance.getReferencePatterns(name);
+        } else {
+            return gbeanData.getReferencePatterns(name);
+        }
     }
 
     /**
@@ -958,7 +371,11 @@
      * @param pattern the new single object name pattern for the reference
      */
     public void setReferencePattern(String name, ObjectName pattern) {
-        getReferenceByName(name).setPatterns(Collections.singleton(pattern));
+        if (gbeanInstance != null) {
+            gbeanInstance.setReferencePattern(name, pattern);
+        } else {
+            gbeanData.setReferencePattern(name, pattern);
+        }
     }
 
     /**
@@ -968,175 +385,39 @@
      * @param patterns the new object name patterns for the reference
      */
     public void setReferencePatterns(String name, Set patterns) {
-        getReferenceByName(name).setPatterns(patterns);
+        if (gbeanInstance != null) {
+            gbeanInstance.setReferencePatterns(name, patterns);
+        } else {
+            gbeanData.setReferencePatterns(name, patterns);
+        }
     }
 
-    private GBeanReference getReferenceByName(String name) {
-        Integer index = (Integer) referenceIndex.get(name);
-        if (index == null) {
-            throw new IllegalArgumentException("Unknown reference " + name);
-        }
-        GBeanReference reference = references[index.intValue()];
-        return reference;
+    public final String getObjectName() {
+        return objectName.getCanonicalName();
     }
 
     public MBeanNotificationInfo[] getNotificationInfo() {
-        return mbeanInfo.getNotifications();
+        return new MBeanNotificationInfo[]{
+            new MBeanNotificationInfo(NotificationType.TYPES, "javax.management.Notification", "J2EE Notifications")
+        };
     }
 
-    private void addManagedObjectAttributes(Map attributesMap) {
-        //
-        //  Special attributes
-        //
-        attributesMap.put("objectName",
-                GBeanMBeanAttribute.createSpecialAttribute((GBeanMBeanAttribute) attributesMap.get("objectName"),
-                        this,
-                        "objectName",
-                        String.class,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return getObjectName();
-                            }
-                        }));
-
-        attributesMap.put("gbeanInfo",
-                GBeanMBeanAttribute.createSpecialAttribute((GBeanMBeanAttribute) attributesMap.get("gbeanInfo"),
-                        this,
-                        "gbeanInfo",
-                        GBeanInfo.class,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return getGBeanInfo();
-                            }
-                        }));
-
-        attributesMap.put("classLoader",
-                GBeanMBeanAttribute.createSpecialAttribute((GBeanMBeanAttribute) attributesMap.get("classLoader"),
-                        this,
-                        "classLoader",
-                        ClassLoader.class));
-
-        attributesMap.put("gbeanLifecycleController",
-                GBeanMBeanAttribute.createSpecialAttribute((GBeanMBeanAttribute) attributesMap.get("gbeanLifecycleController"),
-                        this,
-                        "gbeanLifecycleController",
-                        GBeanLifecycleController.class));
-
-        attributesMap.put("kernel",
-                GBeanMBeanAttribute.createSpecialAttribute((GBeanMBeanAttribute) attributesMap.get("kernel"),
-                        this,
-                        "kernel",
-                        Kernel.class));
-
-        //
-        // Framework attributes
-        //
-        attributesMap.put("state",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "state",
-                        Integer.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Integer(getState());
-                            }
-                        }));
-
-        attributesMap.put("startTime",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "startTime",
-                        Long.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Long(getStartTime());
-                            }
-                        }));
-
-        attributesMap.put("stateManageable",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "stateManageable",
-                        Boolean.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Boolean(isStateManageable());
-                            }
-                        }));
-
-        attributesMap.put("statisticsProvider",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "statisticsProvider",
-                        Boolean.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Boolean(isStatisticsProvider());
-                            }
-                        }));
-
-
-        attributesMap.put("eventProvider",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "eventProvider",
-                        Boolean.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Boolean(isEventProvider());
-                            }
-                        }));
-
-        attributesMap.put("gbeanEnabled",
-                GBeanMBeanAttribute.createFrameworkAttribute(this,
-                        "gbeanEnabled",
-                        Boolean.TYPE,
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                return new Boolean(isEnabled());
-                            }
-                        },
-                        new MethodInvoker() {
-                            public Object invoke(Object target, Object[] arguments) throws Exception {
-                                Boolean enabled = (Boolean) arguments[0];
-                                setEnabled(enabled.booleanValue());
-                                return null;
-                            }
-                        },
-                        true,
-                        Boolean.TRUE));
-    }
-
-    private void addManagedObjectOperations(Map operationsMap) {
-        operationsMap.put(new GOperationSignature("start", Collections.EMPTY_LIST),
-                GBeanMBeanOperation.createFrameworkOperation(this,
-                "start",
-                Collections.EMPTY_LIST,
-                Void.TYPE,
-                new MethodInvoker() {
-                    public Object invoke(Object target, Object[] arguments) throws Exception {
-                        start();
-                        return null;
-                    }
-                }));
-
-        operationsMap.put(new GOperationSignature("startRecursive", Collections.EMPTY_LIST),
-                GBeanMBeanOperation.createFrameworkOperation(this,
-                "startRecursive",
-                Collections.EMPTY_LIST,
-                Void.TYPE,
-                new MethodInvoker() {
-                    public Object invoke(Object target, Object[] arguments) throws Exception {
-                        startRecursive();
-                        return null;
-                    }
-                }));
-
-        operationsMap.put(new GOperationSignature("stop", Collections.EMPTY_LIST),
-                GBeanMBeanOperation.createFrameworkOperation(this,
-                "stop",
-                Collections.EMPTY_LIST,
-                Void.TYPE,
-                new MethodInvoker() {
-                    public Object invoke(Object target, Object[] arguments) throws Exception {
-                        stop();
-                        return null;
-                    }
-                }));
+    public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
+        lifecycleBroadcaster.addNotificationListener(listener, filter, handback);
+    }
+
+    public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
+        lifecycleBroadcaster.removeNotificationListener(listener);
+    }
+
+    public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException {
+        lifecycleBroadcaster.removeNotificationListener(listener, filter, handback);
+    }
+
+    public String toString() {
+        if (objectName == null) {
+            return super.toString();
+        }
+        return objectName.toString();
     }
 }

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java?view=auto&rev=106609
==============================================================================

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,79 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.gbean.jmx;
+
+import javax.management.ObjectName;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.NotificationFilter;
+import javax.management.ListenerNotFoundException;
+
+import org.apache.geronimo.kernel.LifecycleListener;
+import org.apache.geronimo.kernel.management.NotificationType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JMXLifecycleBroadcaster implements LifecycleListener {
+    private final NotificationBroadcasterSupport notificationBroadcaster = new NotificationBroadcasterSupport();
+    private long sequence;
+
+    public void loaded(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_CREATED, objectName, nextSequence()));
+    }
+
+    public void starting(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STARTING, objectName, nextSequence()));
+    }
+
+    public void running(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_RUNNING, objectName, nextSequence()));
+    }
+
+    public void stopping(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPING, objectName, nextSequence()));
+    }
+
+    public void stopped(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPED, objectName, nextSequence()));
+    }
+
+    public void failed(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_FAILED, objectName, nextSequence()));
+    }
+
+    public void unloaded(ObjectName objectName) {
+        notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_DELETED, objectName, nextSequence()));
+    }
+
+    void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
+        notificationBroadcaster.addNotificationListener(listener, filter, handback);
+    }
+
+    void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
+        notificationBroadcaster.removeNotificationListener(listener);
+    }
+
+    void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException {
+        notificationBroadcaster.removeNotificationListener(listener, filter, handback);
+    }
+
+    private synchronized long nextSequence() {
+        return sequence++;
+    }
+}

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java?view=auto&rev=106609
==============================================================================

Deleted: /geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java?view=auto&rev=106609
==============================================================================

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/AbstractGBeanReference.java (from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/AbstractGBeanReference.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java&r1=106387&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/AbstractGBeanReference.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractGBeanReference.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/AbstractGBeanReference.java	Thu Nov 25 13:40:42 2004
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -22,8 +22,6 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
 import javax.management.ObjectName;
 
 import org.apache.geronimo.gbean.GReferenceInfo;
@@ -32,6 +30,8 @@
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.LifecycleAdapter;
 import org.apache.geronimo.kernel.LifecycleListener;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.management.State;
 
 /**
@@ -44,14 +44,14 @@
     private final String name;
 
     /**
-     * Interface this GBeanMBean uses to refer to the other.
+     * Interface this GBeanInstance uses to refer to the other.
      */
     private final Class type;
 
     /**
-     * The GBeanMBean to which this reference belongs.
+     * The GBeanInstance to which this reference belongs.
      */
-    private final GBeanMBean gmbean;
+    private final GBeanInstance gbeanInstance;
 
     /**
      * The method that will be called to set the attribute value.  If null, the value will be set with
@@ -84,11 +84,11 @@
      */
     private Object proxy;
 
-    public AbstractGBeanReference(GBeanMBean gmbean, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
-        this.gmbean = gmbean;
+    public AbstractGBeanReference(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
+        this.gbeanInstance = gbeanInstance;
         this.name = referenceInfo.getName();
         try {
-            this.type = ClassLoading.loadClass(referenceInfo.getType(), gmbean.getClassLoader());
+            this.type = ClassLoading.loadClass(referenceInfo.getType(), gbeanInstance.getClassLoader());
         } catch (ClassNotFoundException e) {
             throw new InvalidConfigurationException("Could not load reference proxy interface class:" +
                     " name=" + name +
@@ -101,7 +101,7 @@
         if (constructorType != null) {
             setInvoker = null;
         } else {
-            Method setterMethod = searchForSetter(gmbean, referenceInfo);
+            Method setterMethod = searchForSetter(gbeanInstance, referenceInfo);
             setInvoker = new FastMethodInvoker(setterMethod);
         }
 
@@ -114,6 +114,22 @@
             }
 
             public void stoping(ObjectName objectName) {
+                removeTarget(objectName);
+            }
+
+            public void stopped(ObjectName objectName) {
+                removeTarget(objectName);
+            }
+
+            public void failed(ObjectName objectName) {
+                removeTarget(objectName);
+            }
+
+            public void unloaded(ObjectName objectName) {
+                removeTarget(objectName);
+            }
+
+            private void removeTarget(ObjectName objectName) {
                 boolean wasTarget = targets.remove(objectName);
                 if (wasTarget) {
                     targetRemoved(objectName);
@@ -126,8 +142,8 @@
         return kernel;
     }
 
-    protected final GBeanMBean getGBeanMBean() {
-        return gmbean;
+    public final GBeanInstance getGBeanInstance() {
+        return gbeanInstance;
     }
 
     public final String getName() {
@@ -138,7 +154,6 @@
         return type;
     }
 
-
     public Object getProxy() {
         return proxy;
     }
@@ -210,7 +225,7 @@
     public final synchronized void inject() throws Exception {
         // set the proxy into the instance
         if (setInvoker != null && patterns.size() > 0) {
-            setInvoker.invoke(gmbean.getTarget(), new Object[]{getProxy()});
+            setInvoker.invoke(gbeanInstance.getTarget(), new Object[]{getProxy()});
         }
     }
 
@@ -224,10 +239,10 @@
         try {
             final int state = ((Integer) kernel.getAttribute(objectName, "state")).intValue();
             return state == State.RUNNING_INDEX;
-        } catch (AttributeNotFoundException e) {
+        } catch (NoSuchAttributeException e) {
             // ok -- mbean is not a startable
             return true;
-        } catch (InstanceNotFoundException e) {
+        } catch (GBeanNotFoundException e) {
             // mbean is no longer registerd
             return false;
         } catch (Exception e) {
@@ -236,11 +251,11 @@
         }
     }
 
-    protected static Method searchForSetter(GBeanMBean gMBean, GReferenceInfo referenceInfo) throws InvalidConfigurationException {
+    protected static Method searchForSetter(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo) throws InvalidConfigurationException {
         if (referenceInfo.getSetterName() == null) {
             // no explicit name give so we must search for a name
             String setterName = "set" + referenceInfo.getName();
-            Method[] methods = gMBean.getType().getMethods();
+            Method[] methods = gbeanInstance.getType().getMethods();
             for (int i = 0; i < methods.length; i++) {
                 Method method = methods[i];
                 if (method.getParameterTypes().length == 1 &&
@@ -253,7 +268,7 @@
         } else {
             // even though we have an exact name we need to search the methods because
             // we don't know the parameter type
-            Method[] methods = gMBean.getType().getMethods();
+            Method[] methods = gbeanInstance.getType().getMethods();
             String setterName = referenceInfo.getSetterName();
             for (int i = 0; i < methods.length; i++) {
                 Method method = methods[i];
@@ -267,6 +282,6 @@
         }
         throw new InvalidConfigurationException("Target does not have specified method:" +
                 " name=" + referenceInfo.getName() +
-                " targetClass=" + gMBean.getType().getName());
+                " targetClass=" + gbeanInstance.getType().getName());
     }
 }

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/FastMethodInvoker.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/FastMethodInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/FastMethodInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/FastMethodInvoker.java	Thu Nov 25 13:40:42 2004
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java	Thu Nov 25 13:40:42 2004
@@ -15,12 +15,9 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import javax.management.MBeanAttributeInfo;
-import javax.management.ReflectionException;
 
 import org.apache.geronimo.gbean.DynamicGAttributeInfo;
 import org.apache.geronimo.gbean.DynamicGBean;
@@ -31,8 +28,8 @@
 /**
  * @version $Rev$ $Date$
  */
-public class GBeanMBeanAttribute {
-    private final GBeanMBean gmbean;
+public class GBeanAttribute {
+    private final GBeanInstance gbeanInstance;
 
     private final String name;
 
@@ -50,8 +47,6 @@
 
     private final boolean persistent;
 
-    private final MBeanAttributeInfo mbeanAttributeInfo;
-
     private Object persistentValue;
 
     /**
@@ -63,50 +58,43 @@
 
     private final boolean framework;
 
-    static GBeanMBeanAttribute createSpecialAttribute(GBeanMBeanAttribute attribute, GBeanMBean gmbean, String name, Class type) {
-        return new GBeanMBeanAttribute(attribute, gmbean, name, type, null);
-    }
+    private final boolean dynamic;
 
-    static GBeanMBeanAttribute createSpecialAttribute(GBeanMBeanAttribute attribute, GBeanMBean gmbean, String name, Class type, MethodInvoker getInvoker) {
-        return new GBeanMBeanAttribute(attribute, gmbean, name, type, getInvoker);
+    static GBeanAttribute createSpecialAttribute(GBeanAttribute attribute, GBeanInstance gbeanInstance, String name, Class type, Object value) {
+        return new GBeanAttribute(attribute, gbeanInstance, name, type, value);
     }
 
-    private GBeanMBeanAttribute(GBeanMBeanAttribute attribute, GBeanMBean gmbean, String name, Class type, MethodInvoker getInvoker) {
+    private GBeanAttribute(GBeanAttribute attribute, GBeanInstance gbeanInstance, String name, Class type, Object value) {
         this.special = true;
         this.framework = false;
+        this.dynamic = false;
 
-        if (gmbean == null || name == null || type == null) {
+        if (gbeanInstance == null || name == null || type == null) {
             throw new IllegalArgumentException("null param(s) supplied");
         }
 
-        // if we have an attribute verify the gmbean, namd and types match
+        // if we have an attribute verify the gbean instance, name and types match
         if (attribute != null) {
-            assert (gmbean == attribute.gmbean);
+            assert (gbeanInstance == attribute.gbeanInstance);
             assert (name.equals(attribute.name));
             if (type != attribute.type) {
                 throw new InvalidConfigurationException("Special attribute " + name +
                         " must have the type " + type.getName() + ", but is " +
-                        attribute.type.getName() + ": targetClass=" + gmbean.getType().getName());
+                        attribute.type.getName() + ": targetClass=" + gbeanInstance.getType().getName());
             }
             if (attribute.isPersistent()) {
                 throw new InvalidConfigurationException("Special attributes must not be persistent:" +
-                        " name=" + name + ", targetClass=" + gmbean.getType().getName());
+                        " name=" + name + ", targetClass=" + gbeanInstance.getType().getName());
             }
         }
 
-        this.gmbean = gmbean;
+        this.gbeanInstance = gbeanInstance;
         this.name = name;
         this.type = type;
 
         // getter
-        if (getInvoker != null) {
-            this.getInvoker = getInvoker;
-        } else if (attribute != null) {
-            this.getInvoker = attribute.getInvoker;
-        } else {
-            this.getInvoker = null;
-        }
-        this.readable = (this.getInvoker != null);
+        this.getInvoker = null;
+        this.readable = true;
 
         // setter
         if (attribute != null) {
@@ -116,37 +104,31 @@
             this.setInvoker = null;
             this.isConstructorArg = false;
         }
-        this.writable = (this.setInvoker != null);
+        this.writable = false;
 
         // persistence
         this.persistent = false;
-        initializePersistentValue(null);
-
-        // mbean info
-        if (!readable && !writable) {
-            this.mbeanAttributeInfo = null;
-        } else {
-            this.mbeanAttributeInfo = new MBeanAttributeInfo(name, type.getName(), null, readable, writable, type == Boolean.TYPE);
-        }
+        initializePersistentValue(value);
     }
 
-    static GBeanMBeanAttribute createFrameworkAttribute(GBeanMBean gmbean, String name, Class type, MethodInvoker getInvoker) {
-        return new GBeanMBeanAttribute(gmbean, name, type, getInvoker, null, false, null);
+    static GBeanAttribute createFrameworkAttribute(GBeanInstance gbeanInstance, String name, Class type, MethodInvoker getInvoker) {
+        return new GBeanAttribute(gbeanInstance, name, type, getInvoker, null, false, null);
     }
 
-    static GBeanMBeanAttribute createFrameworkAttribute(GBeanMBean gmbean, String name, Class type, MethodInvoker getInvoker, MethodInvoker setInvoker, boolean persistent, Object persistentValue) {
-        return new GBeanMBeanAttribute(gmbean, name, type, getInvoker, setInvoker, persistent, persistentValue);
+    static GBeanAttribute createFrameworkAttribute(GBeanInstance gbeanInstance, String name, Class type, MethodInvoker getInvoker, MethodInvoker setInvoker, boolean persistent, Object persistentValue) {
+        return new GBeanAttribute(gbeanInstance, name, type, getInvoker, setInvoker, persistent, persistentValue);
     }
 
-    private GBeanMBeanAttribute(GBeanMBean gmbean, String name, Class type, MethodInvoker getInvoker, MethodInvoker setInvoker, boolean persistent, Object persistentValue) {
+    private GBeanAttribute(GBeanInstance gbeanInstance, String name, Class type, MethodInvoker getInvoker, MethodInvoker setInvoker, boolean persistent, Object persistentValue) {
         this.special = false;
         this.framework = true;
+        this.dynamic = false;
 
-        if (gmbean == null || name == null || type == null) {
+        if (gbeanInstance == null || name == null || type == null) {
             throw new IllegalArgumentException("null param(s) supplied");
         }
 
-        this.gmbean = gmbean;
+        this.gbeanInstance = gbeanInstance;
         this.name = name;
         this.type = type;
 
@@ -162,41 +144,33 @@
         // persistence
         this.persistent = persistent;
         initializePersistentValue(persistentValue);
-
-        // mbean info
-        if (!readable && !writable) {
-            this.mbeanAttributeInfo = null;
-        } else {
-            this.mbeanAttributeInfo = new MBeanAttributeInfo(name, type.getName(), null, readable, writable, type == Boolean.TYPE);
-        }
     }
 
-    public GBeanMBeanAttribute(GBeanMBean gmbean, GAttributeInfo attributeInfo, boolean isConstructorArg) throws InvalidConfigurationException {
+    public GBeanAttribute(GBeanInstance gbeanInstance, GAttributeInfo attributeInfo, boolean isConstructorArg) throws InvalidConfigurationException {
         this.special = false;
         this.framework = false;
 
-        if (gmbean == null || attributeInfo == null) {
+        if (gbeanInstance == null || attributeInfo == null) {
             throw new IllegalArgumentException("null param(s) supplied");
         }
         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());
+                    + " name=" + attributeInfo.getName() + " targetClass=" + gbeanInstance.getType().getName());
         }
-        this.gmbean = gmbean;
+        this.gbeanInstance = gbeanInstance;
         this.name = attributeInfo.getName();
         this.isConstructorArg = isConstructorArg;
         try {
-            this.type = ClassLoading.loadClass(attributeInfo.getType(), gmbean.getClassLoader());
+            this.type = ClassLoading.loadClass(attributeInfo.getType(), gbeanInstance.getClassLoader());
         } catch (ClassNotFoundException e) {
             throw new InvalidConfigurationException("Could not load attribute class: " + attributeInfo.getType());
         }
         this.persistent = attributeInfo.isPersistent();
 
-        boolean isIs;
-
         // If attribute is persistent or not tagged as unreadable, search for a
         // getter method
         if (attributeInfo instanceof DynamicGAttributeInfo) {
+            this.dynamic = true;
             readable = attributeInfo.isReadable().booleanValue();
             if (readable) {
                 getInvoker = new DynamicGetterMethodInvoker(name);
@@ -209,11 +183,11 @@
             } else {
                 setInvoker = null;
             }
-            isIs = false;
         } else {
+            this.dynamic = false;
             Method getterMethod = null;
             if (attributeInfo.isPersistent() || attributeInfo.isReadable() != Boolean.FALSE) {
-                getterMethod = searchForGetter(gmbean, attributeInfo, type);
+                getterMethod = searchForGetter(gbeanInstance, attributeInfo, type);
             }
             if (getterMethod != null) {
                 getInvoker = new FastMethodInvoker(getterMethod);
@@ -230,7 +204,7 @@
             // for a setter method
             Method setterMethod = null;
             if (attributeInfo.isPersistent() || attributeInfo.isWritable() != Boolean.FALSE) {
-                setterMethod = searchForSetter(gmbean, attributeInfo, type);
+                setterMethod = searchForSetter(gbeanInstance, attributeInfo, type);
             }
             if (setterMethod != null) {
                 setInvoker = new FastMethodInvoker(setterMethod);
@@ -238,21 +212,17 @@
                 // this attribute is writable as long as it was not explicitly
                 // tagged as unwritable
                 writable = attributeInfo.isWritable() != Boolean.FALSE;
-                isIs = setterMethod.getName().startsWith("is");
             } else {
                 setInvoker = null;
                 writable = false;
-                isIs = false;
             }
         }
 
-        mbeanAttributeInfo = new MBeanAttributeInfo(attributeInfo.getName(), type.getName(), null, readable, writable, isIs);
-
         initializePersistentValue(null);
     }
 
     private void initializePersistentValue(Object value) {
-        if (persistent) {
+        if (persistent || special) {
             if (value == null && type.isPrimitive()) {
                 if (type == Boolean.TYPE) {
                     value = Boolean.FALSE;
@@ -296,6 +266,10 @@
         return framework;
     }
 
+    public boolean isDynamic() {
+        return dynamic;
+    }
+
     public boolean isPersistent() {
         return persistent;
     }
@@ -304,10 +278,6 @@
         return special;
     }
 
-    public MBeanAttributeInfo getMBeanAttributeInfo() {
-        return mbeanAttributeInfo;
-    }
-
     public void inject() throws Exception {
         if ((persistent || special) && !isConstructorArg && writable) {
             setValue(persistentValue);
@@ -323,7 +293,7 @@
 
     public void setPersistentValue(Object persistentValue) {
         if (!persistent && !special) {
-                    throw new IllegalStateException("Attribute is not persistent " + getDescription());
+            throw new IllegalStateException("Attribute is not persistent " + getDescription());
         }
 
         if (persistentValue == null && type.isPrimitive()) {
@@ -334,35 +304,36 @@
         this.persistentValue = persistentValue;
     }
 
-    public Object getValue() throws ReflectionException {
+    public Object getValue() throws Exception {
         if (!readable) {
             if (persistent) {
                 throw new IllegalStateException("This persistent attribute is not accessible while started. " + getDescription());
             } else {
-                throw new IllegalArgumentException("This attribute is not readable. " + getDescription());
+                throw new IllegalStateException("This attribute is not readable. " + getDescription());
             }
         }
 
+        if (special) {
+            return persistentValue;
+        }
+        
         // get the target to invoke
-        Object target = gmbean.getTarget();
+        Object target = gbeanInstance.getTarget();
         if (target == null && !framework) {
             throw new IllegalStateException("GBeanMBean does not have a target instance to invoke. " + getDescription());
         }
 
         // call the getter
-        try {
-            Object value = getInvoker.invoke(target, null);
-            return value;
-        } catch (Throwable throwable) {
-            throw new ReflectionException(new InvocationTargetException(throwable));
-        }
+        Object value = getInvoker.invoke(target, null);
+        return value;
     }
-    public void setValue(Object value) throws ReflectionException {
+
+    public void setValue(Object value) throws Exception {
         if (!writable) {
             if (persistent) {
                 throw new IllegalStateException("This persistent attribute is not modifable while running. " + getDescription());
             } else {
-                throw new IllegalArgumentException("This attribute is not writable. " + getDescription());
+                throw new IllegalStateException("This attribute is not writable. " + getDescription());
             }
         }
 
@@ -374,30 +345,26 @@
         // @todo actually check type
 
         // get the target to invoke
-        Object target = gmbean.getTarget();
+        Object target = gbeanInstance.getTarget();
         if (target == null && !framework) {
             throw new IllegalStateException("GBeanMBean does not have a target instance to invoke. " + getDescription());
         }
 
         // call the setter
-        try {
-            setInvoker.invoke(target, new Object[]{value});
-        } catch (Throwable throwable) {
-            throw new ReflectionException(new InvocationTargetException(throwable));
-        }
+        setInvoker.invoke(target, new Object[]{value});
     }
 
     public String getDescription() {
-        return "Attribute Name: " + getName() + ", Type: " + getType() + ", GBean: " + gmbean.getName();
+        return "Attribute Name: " + getName() + ", Type: " + getType() + ", GBeanInstance: " + gbeanInstance.getName();
     }
 
-    private static Method searchForGetter(GBeanMBean gMBean, GAttributeInfo attributeInfo, Class type) throws InvalidConfigurationException {
+    private static Method searchForGetter(GBeanInstance gbeanInstance, GAttributeInfo attributeInfo, Class type) throws InvalidConfigurationException {
         Method getterMethod = null;
         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();
+            Method[] methods = gbeanInstance.getType().getMethods();
             for (int i = 0; i < methods.length; i++) {
                 if (methods[i].getParameterTypes().length == 0 && methods[i].getReturnType() != Void.TYPE
                         && (getterName.equalsIgnoreCase(methods[i].getName()) || isName.equalsIgnoreCase(methods[i].getName()))) {
@@ -410,12 +377,12 @@
         } else {
             // we have an explicit name, so no searching is necessary
             try {
-                getterMethod = gMBean.getType().getMethod(attributeInfo.getGetterName(), null);
+                getterMethod = gbeanInstance.getType().getMethod(attributeInfo.getGetterName(), null);
                 if (getterMethod.getReturnType() == Void.TYPE) {
                     throw new InvalidConfigurationException("Getter method return VOID:" +
                             " name=" + attributeInfo.getName() +
                             ", type=" + type.getName() +
-                            ", targetClass=" + gMBean.getType().getName());
+                            ", targetClass=" + gbeanInstance.getType().getName());
                 }
             } catch (Exception e) {
                 // we will throw the formatted exception below
@@ -426,7 +393,7 @@
         if (getterMethod != null && !type.equals(getterMethod.getReturnType())) {
             throw new InvalidConfigurationException("Incorrect return type for getter method:" +
                     " name=" + attributeInfo.getName() +
-                    ", targetClass=" + gMBean.getType().getName() +
+                    ", targetClass=" + gbeanInstance.getType().getName() +
                     ", getter type=" + getterMethod.getReturnType() +
                     ", expected type=" + type.getName());
         }
@@ -436,17 +403,17 @@
             throw new InvalidConfigurationException("Getter method not found on target:" +
                     " name=" + attributeInfo.getName() +
                     ", type=" + type.getName() +
-                    ", targetClass=" + gMBean.getType().getName());
+                    ", targetClass=" + gbeanInstance.getType().getName());
         }
 
         return getterMethod;
     }
 
-    private static Method searchForSetter(GBeanMBean gMBean, GAttributeInfo attributeInfo, Class type) throws InvalidConfigurationException {
+    private static Method searchForSetter(GBeanInstance gbeanInstance, GAttributeInfo attributeInfo, Class type) 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();
+            Method[] methods = gbeanInstance.getType().getMethods();
             for (int i = 0; i < methods.length; i++) {
                 Method method = methods[i];
                 if (method.getParameterTypes().length == 1 &&
@@ -460,12 +427,12 @@
         } else {
             // we have an explicit name, so no searching is necessary
             try {
-                Method method = gMBean.getType().getMethod(attributeInfo.getSetterName(), new Class[]{type});
+                Method method = gbeanInstance.getType().getMethod(attributeInfo.getSetterName(), new Class[]{type});
                 if (method.getReturnType() != Void.TYPE) {
                     throw new InvalidConfigurationException("Setter method must return VOID:" +
                             " name=" + attributeInfo.getName() +
                             ", type=" + type.getName() +
-                            ", targetClass=" + gMBean.getType().getName());
+                            ", targetClass=" + gbeanInstance.getType().getName());
                 }
                 return method;
             } catch (Exception e) {
@@ -481,7 +448,7 @@
             throw new InvalidConfigurationException("Setter method not found on target:" +
                     " name=" + attributeInfo.getName() +
                     ", type=" + type.getName() +
-                    ", targetClass=" + gMBean.getType().getName());
+                    ", targetClass=" + gbeanInstance.getType().getName());
         }
 
         // a setter is not necessary for this attribute

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanCollectionReference.java (from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanCollectionReference.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java&r1=106387&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanCollectionReference.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanCollectionReference.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanCollectionReference.java	Thu Nov 25 13:40:42 2004
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import javax.management.ObjectName;
 
@@ -26,8 +26,8 @@
  * @version $Rev: 71492 $ $Date: 2004-11-14 21:31:50 -0800 (Sun, 14 Nov 2004) $
  */
 public class GBeanCollectionReference extends AbstractGBeanReference {
-    public GBeanCollectionReference(GBeanMBean gmbean, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
-        super(gmbean, referenceInfo, constructorType);
+    public GBeanCollectionReference(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
+        super(gbeanInstance, referenceInfo, constructorType);
     }
 
     public synchronized void start() throws Exception {

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,1043 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.gbean.runtime;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.management.ObjectName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.GBeanLifecycleController;
+import org.apache.geronimo.gbean.GConstructorInfo;
+import org.apache.geronimo.gbean.GOperationInfo;
+import org.apache.geronimo.gbean.GOperationSignature;
+import org.apache.geronimo.gbean.GReferenceInfo;
+import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.gbean.DynamicGAttributeInfo;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.LifecycleListener;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+import org.apache.geronimo.kernel.management.EventProvider;
+import org.apache.geronimo.kernel.management.ManagedObject;
+import org.apache.geronimo.kernel.management.NotificationType;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.management.StateManageable;
+
+/**
+ * A GBeanInstance is a J2EE Management Managed Object, and is standard base for Geronimo services.
+ *
+ * @version $Rev: 106387 $ $Date: 2004-11-23 22:16:54 -0800 (Tue, 23 Nov 2004) $
+ */
+public final class GBeanInstance implements ManagedObject, StateManageable, EventProvider {
+    private static final Log log = LogFactory.getLog(GBeanInstance.class);
+
+    /**
+     * Attribute name used to retrieve the RawInvoker for the GBean
+     * @deprecated DO NOT USE THIS... THIS WILL BE REMOVED!!!!!!
+     */
+    public static final String RAW_INVOKER = "$$RAW_INVOKER$$";
+
+    /**
+     * Attribute name used to retrieve the GBeanData for the GBean
+     */
+    public static final String GBEAN_DATA = "$$GBEAN_DATA$$";
+
+    /**
+     * The kernel in which this server is registered.
+     */
+    private final Kernel kernel;
+
+    /**
+     * The unique name of this service.
+     */
+    private final ObjectName objectName;
+
+    /**
+     * This handles all state transiitions for this instance.
+     */
+    private final GBeanInstanceState gbeanInstanceState;
+
+    /**
+     * The constructor used to create the instance
+     */
+    private final Constructor constructor;
+
+    /**
+     * A fast index based raw invoker for this GBean.
+     */
+    private final RawInvoker rawInvoker;
+
+    /**
+     * The single listener to which we broadcast lifecycle change events.
+     */
+    private final LifecycleListener lifecycleBroadcaster;
+
+    /**
+     * The lifecycle controller given to the instance
+     */
+    private final GBeanLifecycleController gbeanLifecycleController;
+
+    /**
+     * Attributes lookup table
+     */
+    private final GBeanAttribute[] attributes;
+
+    /**
+     * Attributes supported by this GBeanMBean by (String) name.
+     */
+    private final Map attributeIndex = new HashMap();
+
+    /**
+     * References lookup table
+     */
+    private final GBeanReference[] references;
+
+    /**
+     * References supported by this GBeanMBean by (String) name.
+     */
+    private final Map referenceIndex = new HashMap();
+
+    /**
+     * Operations lookup table
+     */
+    private final GBeanOperation[] operations;
+
+    /**
+     * Operations supported by this GBeanMBean by (GOperationSignature) name.
+     */
+    private final Map operationIndex = new HashMap();
+
+    /**
+     * The classloader used for all invocations and creating targets.
+     */
+    private final ClassLoader classLoader;
+
+    /**
+     * Metadata describing the attributes, operations and references of this GBean
+     */
+    private final GBeanInfo gbeanInfo;
+
+    /**
+     * Our name
+     */
+    private final String name;
+
+    /**
+     * Java type of the wrapped GBean class
+     */
+    private final Class type;
+
+    /**
+     * Has this instance been destroyed?
+     */
+    private boolean destroyed = true;
+
+    /**
+     * Is this gbean running?
+     */
+    private boolean running = false;
+
+    /**
+     * Target instance of this GBean wrapper
+     */
+    private Object target;
+
+    /**
+     * The time this application started.
+     */
+    private long startTime;
+
+    /**
+     * Is this gbean enabled?  A disabled gbean can not be started.
+     */
+    private boolean enabled = true;
+
+
+    /**
+     * Constructa a GBeanMBean using the supplied GBeanData and class loader
+     *
+     * @param gbeanData the data for the new GBean including GBeanInfo, intial attribute values, and reference patterns
+     * @param classLoader the class loader used to load the gbean instance and attribute/reference types
+     * @throws org.apache.geronimo.gbean.InvalidConfigurationException if the gbeanInfo is inconsistent with the actual java classes, such as
+     * mismatched attribute types or the intial data can not be set
+     */
+    public GBeanInstance(Kernel kernel, GBeanData gbeanData, LifecycleListener lifecycleBroadcaster, ClassLoader classLoader) throws InvalidConfigurationException {
+        this.kernel = kernel;
+        this.objectName = gbeanData.getName();
+        this.lifecycleBroadcaster = lifecycleBroadcaster;
+        this.gbeanInstanceState = new GBeanInstanceState(kernel, objectName, new GBeanLifecycleCallback(), lifecycleBroadcaster);
+        this.classLoader = classLoader;
+        gbeanLifecycleController = new GBeanInstanceLifecycleController(this);
+
+        GBeanInfo gbeanInfo = gbeanData.getGBeanInfo();
+        try {
+            type = classLoader.loadClass(gbeanInfo.getClassName());
+        } catch (ClassNotFoundException e) {
+            throw new InvalidConfigurationException("Could not load GBeanInfo class from classloader: " +
+                    " className=" + gbeanInfo.getClassName());
+        }
+
+        name = gbeanInfo.getName();
+
+        // get the constructor
+        constructor = Util.searchForConstructor(gbeanInfo, type);
+
+        // build a map from constructor argument names to type
+        Class[] constructorParameterTypes = constructor.getParameterTypes();
+        Map constructorTypes = new HashMap(constructorParameterTypes.length);
+        List constructorAttributeNames = gbeanInfo.getConstructor().getAttributeNames();
+        for (int i = 0; i < constructorParameterTypes.length; i++) {
+            Class type = constructorParameterTypes[i];
+            constructorTypes.put(constructorAttributeNames.get(i), type);
+        }
+
+        // attributes
+        Map attributesMap = new HashMap();
+        for (Iterator iterator = gbeanInfo.getAttributes().iterator(); iterator.hasNext();) {
+            GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
+            attributesMap.put(attributeInfo.getName(), new GBeanAttribute(this, attributeInfo, constructorTypes.containsKey(attributeInfo.getName())));
+        }
+        addManagedObjectAttributes(attributesMap);
+        attributes = (GBeanAttribute[]) attributesMap.values().toArray(new GBeanAttribute[attributesMap.size()]);
+        for (int i = 0; i < attributes.length; i++) {
+            attributeIndex.put(attributes[i].getName(), new Integer(i));
+        }
+
+        // references
+        Set referencesSet = new HashSet();
+        for (Iterator iterator = gbeanInfo.getReferences().iterator(); iterator.hasNext();) {
+            GReferenceInfo referenceInfo = (GReferenceInfo) iterator.next();
+            Class constructorType = (Class) constructorTypes.get(referenceInfo.getName());
+            if (Util.isCollectionValuedReference(this, referenceInfo, constructorType)) {
+                referencesSet.add(new GBeanCollectionReference(this, referenceInfo, constructorType));
+            } else {
+                referencesSet.add(new GBeanSingleReference(this, referenceInfo, constructorType));
+            }
+        }
+        references = (GBeanReference[]) referencesSet.toArray(new GBeanReference[gbeanInfo.getReferences().size()]);
+        for (int i = 0; i < references.length; i++) {
+            referenceIndex.put(references[i].getName(), new Integer(i));
+        }
+
+        // operations
+        Map operationsMap = new HashMap();
+        addManagedObjectOperations(operationsMap);
+        for (Iterator iterator = gbeanInfo.getOperations().iterator(); iterator.hasNext();) {
+            GOperationInfo operationInfo = (GOperationInfo) iterator.next();
+            GOperationSignature signature = new GOperationSignature(operationInfo.getName(), operationInfo.getParameterList());
+            // do not allow overriding of framework operations
+            if (!operationsMap.containsKey(signature)) {
+                GBeanOperation operation = new GBeanOperation(this, operationInfo);
+                operationsMap.put(signature, operation);
+            }
+        }
+        operations = new GBeanOperation[operationsMap.size()];
+        int opCounter = 0;
+        for (Iterator iterator = operationsMap.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry)iterator.next();
+            operations[opCounter] = (GBeanOperation) entry.getValue();
+            operationIndex.put(entry.getKey(), new Integer(opCounter));
+            opCounter++;
+        }
+
+        rawInvoker = new RawInvoker(this);
+        this.gbeanInfo = rebuildGBeanInfo(gbeanInfo);
+
+        // set the initial attribute values
+        try {
+            setGBeanData(gbeanData);
+        } catch (Exception e) {
+            throw new InvalidConfigurationException("GBeanData could not be loaded into the GBeanMBean", e);
+        }
+
+        for (int i = 0; i < references.length; i++) {
+            references[i].online(this.kernel);
+        }
+        lifecycleBroadcaster.loaded(objectName);
+    }
+
+    public void destroy() {
+        synchronized (this) {
+            if (destroyed) {
+                return;
+            }
+            destroyed = true;
+        }
+
+        lifecycleBroadcaster.unloaded(objectName);
+
+        // just to be sure, stop all the references again
+        for (int i = 0; i < references.length; i++) {
+            references[i].offline();
+        }
+
+        target = null;
+    }
+
+    /**
+     * Gets the name of the GBean as defined in the gbean info.
+     *
+     * @return the gbean name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * The class loader used to build this gbean.  This class loader is set into the thread context
+     * class loader before callint the target instace.
+     *
+     * @return the class loader used to build this gbean
+     */
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
+    /**
+     * Has this gbean instance been destroyed. An destroyed gbean can no longer be used.
+     *
+     * @return true if the gbean has been destroyed
+     */
+    public synchronized boolean isDestroyed() {
+        return destroyed;
+    }
+
+    /**
+     * Is this gbean instance running. Operations and non-persistenct attribtes can not be accessed while not running.
+     *
+     * @return true if the gbean is runing
+     */
+    public boolean isRunning() {
+        return running;
+    }
+
+    /**
+     * The java type of the wrapped gbean instance
+     *
+     * @return the java type of the gbean
+     */
+    public Class getType() {
+        return type;
+    }
+
+    public Object getTarget() {
+        return target;
+    }
+
+    public final String getObjectName() {
+        return objectName.getCanonicalName();
+    }
+
+    public final ObjectName getObjectNameObject() {
+        return objectName;
+    }
+
+    /**
+     * Is this gbean enabled.  A disabled gbean can not be started.
+     *
+     * @return true if the gbean is enabled and can be started
+     */
+    public synchronized final boolean isEnabled() {
+        return enabled;
+    }
+
+    /**
+     * Changes the enabled status.
+     *
+     * @param enabled the new enabled flag
+     */
+    public synchronized final void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public final boolean isStateManageable() {
+        return true;
+    }
+
+    public boolean isStatisticsProvider() {
+        return false;
+    }
+
+    public final boolean isEventProvider() {
+        return true;
+    }
+
+    public final String[] getEventTypes() {
+        return NotificationType.TYPES;
+    }
+
+    public final long getStartTime() {
+        return startTime;
+    }
+
+    public int getState() {
+        return gbeanInstanceState.getState();
+    }
+
+    public final State getStateInstance() {
+        return gbeanInstanceState.getStateInstance();
+    }
+
+    /**
+     * Gets an unmodifiable map from attribute names to index number (Integer).  This index number
+     * can be used to efficiently set or retrieve an attribute value.
+     *
+     * @return an unmodifiable map of attribute indexes by name
+     */
+    public Map getAttributeIndex() {
+        return Collections.unmodifiableMap(new HashMap(attributeIndex));
+    }
+
+    /**
+     * Gets an unmodifiable map from operation signature (GOperationSignature) to index number (Integer).
+     * This index number can be used to efficciently invoke the operation.
+     *
+     * @return an unmodifiable map of operation indexec by signature
+     */
+    public Map getOperationIndex() {
+        return Collections.unmodifiableMap(new HashMap(operationIndex));
+    }
+
+    /**
+     * Gets the GBeanInfo used to build this gbean.
+     *
+     * @return the GBeanInfo used to build this gbean
+     */
+    public GBeanInfo getGBeanInfo() {
+        return gbeanInfo;
+    }
+
+    /**
+     * Moves this GBeanInstance to the starting state and then attempts to move this MBean immediately
+     * to the running state.
+     *
+     * @throws Exception If an exception occurs while starting this MBean
+     * @throws IllegalStateException If the gbean is disabled
+     */
+    public final void start() throws Exception {
+        synchronized (this) {
+            if (!enabled) {
+                throw new IllegalStateException("A disabled GBean can not be started: objectName=" + objectName);
+            }
+        }
+        gbeanInstanceState.start();
+    }
+
+    /**
+     * Starts this GBeanInstance and then attempts to start all of its start dependent children.
+     *
+     * @throws Exception if a problem occurs will starting this MBean or any child MBean
+     * @throws IllegalStateException If the gbean is disabled
+     */
+    public final void startRecursive() throws Exception {
+        synchronized (this) {
+            if (!enabled) {
+                throw new IllegalStateException("A disabled GBean can not be started: objectName=" + objectName);
+            }
+        }
+        gbeanInstanceState.startRecursive();
+    }
+
+    /**
+     * Moves this GBeanInstance to the STOPPING state, calls stop on all start dependent children, and then attempt
+     * to move this MBean to the STOPPED state.
+     *
+     * @throws Exception If an exception occurs while stoping this MBean or any of the childern
+     */
+    public final void stop() throws Exception {
+        gbeanInstanceState.stop();
+    }
+
+    /**
+     * Moves this GBeanInstance to the FAILED state.  There are no calls to dependent children, but they will be
+     * notified using standard J2EE management notification.
+     */
+    final void fail() {
+        gbeanInstanceState.fail();
+    }
+
+    /**
+     * Gets the gbean data for the gbean held by this gbean mbean.
+     * @return the gbean data
+     */
+    public GBeanData getGBeanData() {
+        GBeanData gbeanData = new GBeanData(objectName, gbeanInfo);
+
+        // add the attributes
+        for (int i = 0; i < attributes.length; i++) {
+            GBeanAttribute attribute = attributes[i];
+            if (attribute.isPersistent()) {
+                String name = attribute.getName();
+                Object value;
+                if ((running || attribute.isFramework()) && attribute.isReadable()) {
+                    try {
+                        value = attribute.getValue();
+                    } catch (Throwable throwable) {
+                        value = attribute.getPersistentValue();
+                        log.debug("Could not get the current value of persistent attribute.  The persistent " +
+                                "attribute will not reflect the current state attribute. " + attribute.getDescription(), throwable);
+                    }
+                } else {
+                    value = attribute.getPersistentValue();
+                }
+                gbeanData.setAttribute(name, value);
+            }
+        }
+
+        // add the references
+        for (int i = 0; i < references.length; i++) {
+            GBeanReference reference = references[i];
+            String name = reference.getName();
+            Set patterns = reference.getPatterns();
+            gbeanData.setReferencePatterns(name, patterns);
+        }
+        return gbeanData;
+    }
+
+    public void setGBeanData(GBeanData gbeanData) throws Exception, NoSuchAttributeException {
+        // set the attributes
+        Map attributes = gbeanData.getAttributes();
+        for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String name = (String) entry.getKey();
+            Object value = entry.getValue();
+            setAttribute(name, value);
+        }
+
+        // add the references
+        Map references = gbeanData.getReferences();
+        for (Iterator iterator = references.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            String name = (String) entry.getKey();
+            Set patterns = (Set) entry.getValue();
+            setReferencePatterns(name, patterns);
+        }
+    }
+
+    /**
+     * Gets the attribute value using the attribute index.  This is the most efficient way to get
+     * an attribute as it avoids a HashMap lookup.
+     *
+     * @param index the index of the attribute
+     * @return the attribute value
+     * @throws Exception if a target instance throws and exception
+     * @throws IndexOutOfBoundsException if the index is invalid
+     */
+    public Object getAttribute(int index) throws Exception {
+        GBeanAttribute attribute = attributes[index];
+        if (running || attribute.isFramework()) {
+            return attribute.getValue();
+        } else {
+            return attribute.getPersistentValue();
+        }
+    }
+
+    /**
+     * Gets an attribute's value by name.  This get style is less efficient becuse the attribute must
+     * first be looked up in a HashMap.
+     *
+     * @param attributeName the name of the attribute to retrieve
+     * @return the attribute value
+     * @throws Exception if a problem occurs while getting the value
+     * @throws NoSuchAttributeException if the attribute name is not found in the map
+     */
+    public Object getAttribute(String attributeName) throws NoSuchAttributeException, Exception {
+        GBeanAttribute attribute;
+        try {
+            attribute = getAttributeByName(attributeName);
+        } catch (NoSuchAttributeException e) {
+            if (attributeName.equals(RAW_INVOKER)) {
+                return rawInvoker;
+            }
+
+            if (attributeName.equals(GBEAN_DATA)) {
+                return getGBeanData();
+
+            }
+
+            throw e;
+        }
+
+        if (running || attribute.isFramework()) {
+            return attribute.getValue();
+        } else {
+            return attribute.getPersistentValue();
+        }
+    }
+
+    /**
+     * Sets the attribute value using the attribute index.  This is the most efficient way to set
+     * an attribute as it avoids a HashMap lookup.
+     *
+     * @param index the index of the attribute
+     * @param value the new value of attribute value
+     * @throws Exception if a target instance throws and exception
+     * @throws IndexOutOfBoundsException if the index is invalid
+     */
+    public void setAttribute(int index, Object value) throws Exception, IndexOutOfBoundsException {
+        GBeanAttribute attribute = attributes[index];
+        if (running || attribute.isFramework()) {
+            attribute.setValue(value);
+        } else {
+            attribute.setPersistentValue(value);
+        }
+    }
+
+    /**
+     * Sets an attribute's value by name.  This set style is less efficient becuse the attribute must
+     * first be looked up in a HashMap.
+     *
+     * @param attributeName the name of the attribute to retrieve
+     * @param value the new attribute value
+     * @throws Exception if a target instance throws and exception
+     * @throws NoSuchAttributeException if the attribute name is not found in the map
+     */
+    public void setAttribute(String attributeName, Object value) throws Exception, NoSuchAttributeException {
+        GBeanAttribute attribute = getAttributeByName(attributeName);
+        if (running || attribute.isFramework()) {
+            attribute.setValue(value);
+        } else {
+            attribute.setPersistentValue(value);
+        }
+    }
+
+    private GBeanAttribute getAttributeByName(String name) throws NoSuchAttributeException {
+        Integer index = (Integer) attributeIndex.get(name);
+        if (index == null) {
+            throw new NoSuchAttributeException("Unknown attribute " + name);
+        }
+        GBeanAttribute attribute = attributes[index.intValue()];
+        return attribute;
+    }
+
+    /**
+     * Invokes an opreation using the operation index.  This is the most efficient way to invoke
+     * an operation as it avoids a HashMap lookup.
+     *
+     * @param index the index of the attribute
+     * @param arguments the arguments to the operation
+     * @return the result of the operation
+     * @throws Exception if a target instance throws and exception
+     * @throws IndexOutOfBoundsException if the index is invalid
+     * @throws IllegalStateException if the gbean instance has been destroyed
+     */
+    public Object invoke(int index, Object[] arguments) throws Exception {
+        GBeanOperation operation = operations[index];
+        if (!running && !operation.isFramework()) {
+            throw new IllegalStateException("Operations can only be invoke while the GBean instance is running: " + objectName);
+        }
+        return operation.invoke(arguments);
+    }
+
+    /**
+     * Invokes an operation on the target gbean by method signature.  This style if invocation is
+     * inefficient, because the target method must be looked up in a hashmap using a freshly constructed
+     * GOperationSignature object.
+     *
+     * @param operationName the name of the operation to invoke
+     * @param arguments arguments to the operation
+     * @param types types of the operation arguemtns
+     * @return the result of the operation
+     * @throws Exception if a target instance throws and exception
+     * @throws NoSuchOperationException if the operation signature is not found in the map
+     * @throws IllegalStateException if the gbean instance has been destroyed
+     */
+    public Object invoke(String operationName, Object[] arguments, String[] types) throws Exception, NoSuchOperationException {
+        GOperationSignature signature = new GOperationSignature(operationName, types);
+        Integer index = (Integer) operationIndex.get(signature);
+        if (index == null) {
+            throw new NoSuchOperationException("Unknown operation " + signature);
+        }
+        GBeanOperation operation = operations[index.intValue()];
+        if (!running && !operation.isFramework()) {
+            throw new IllegalStateException("Operations can only be invoke while the GBean is running: " + objectName);
+        }
+        return operation.invoke(arguments);
+    }
+
+    /**
+     * Gets the object name patters for a reference.
+     *
+     * @param name the reference name
+     * @return the object name patterns for the reference
+     */
+    public Set getReferencePatterns(String name) {
+        return getReferenceByName(name).getPatterns();
+    }
+
+    /**
+     * Sets a single object name pattern for a reference.
+     *
+     * @param name the reference name
+     * @param pattern the new single object name pattern for the reference
+     */
+    public void setReferencePattern(String name, ObjectName pattern) {
+        getReferenceByName(name).setPatterns(Collections.singleton(pattern));
+    }
+
+    /**
+     * Sets the object name patterns for a reference.
+     *
+     * @param name the reference name
+     * @param patterns the new object name patterns for the reference
+     */
+    public void setReferencePatterns(String name, Set patterns) {
+        getReferenceByName(name).setPatterns(patterns);
+    }
+
+    private GBeanReference getReferenceByName(String name) {
+        Integer index = (Integer) referenceIndex.get(name);
+        if (index == null) {
+            throw new IllegalArgumentException("Unknown reference " + name);
+        }
+        GBeanReference reference = references[index.intValue()];
+        return reference;
+    }
+
+    private class GBeanLifecycleCallback implements GBeanLifecycle {
+        public void doStart() throws Exception {
+            // start each of the references... if they need to wait remember the
+            // waiting exception so we can throw it later. this way we the dependecies
+            // are held until we can start
+            WaitingException waitingException = null;
+            for (int i = 0; i < references.length; i++) {
+                try {
+                    references[i].start();
+                } catch (WaitingException e) {
+                    waitingException = e;
+                }
+            }
+            if (waitingException != null) {
+                throw waitingException;
+            }
+
+            GConstructorInfo constructorInfo = gbeanInfo.getConstructor();
+            Class[] parameterTypes = constructor.getParameterTypes();
+
+            // create constructor parameter array
+            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 (attributeIndex.containsKey(name)) {
+                    GBeanAttribute attribute = getAttributeByName(name);
+                    parameters[i] = attribute.getPersistentValue();
+                } else if (referenceIndex.containsKey(name)) {
+                    parameters[i] = getReferenceByName(name).getProxy();
+                } else {
+                    throw new InvalidConfigurationException("Unknown attribute or reference name in constructor: name=" + name);
+                }
+                assert parameters[i] == null || parameterTypes[i].isPrimitive() || parameterTypes[i].isAssignableFrom(parameters[i].getClass()):
+                        "Attempting to construct " + objectName + " of type " + gbeanInfo.getClassName()
+                        + ". Constructor parameter " + i + " should be " + parameterTypes[i].getName()
+                        + " but is " + parameters[i].getClass().getName();
+            }
+
+            // create instance
+            try {
+                target = constructor.newInstance(parameters);
+            } catch (InvocationTargetException e) {
+                Throwable targetException = e.getTargetException();
+                if (targetException instanceof Exception) {
+                    throw (Exception) targetException;
+                } else if (targetException instanceof Error) {
+                    throw (Error) targetException;
+                }
+                throw e;
+            } catch (IllegalArgumentException e) {
+                log.warn("Constructor mismatch for " + objectName, e);
+                throw e;
+            }
+
+            // inject the persistent attribute value into the new instance
+            for (int i = 0; i < attributes.length; i++) {
+                attributes[i].inject();
+            }
+
+            // inject the proxies into the new instance
+            for (int i = 0; i < references.length; i++) {
+                references[i].inject();
+            }
+
+            running = true;
+            startTime = System.currentTimeMillis();
+            if (target instanceof GBeanLifecycle) {
+                ((GBeanLifecycle) target).doStart();
+            }
+        }
+
+        public void doStop() throws Exception {
+            if (target instanceof GBeanLifecycle) {
+                ((GBeanLifecycle) target).doStop();
+            }
+
+            running = false;
+
+            // stop all of the references
+            for (int i = 0; i < references.length; i++) {
+                references[i].stop();
+            }
+
+            if (target != null) {
+                // stop all of the attributes
+                for (int i = 0; i < attributes.length; i++) {
+                    GBeanAttribute attribute = attributes[i];
+                    if (attribute.isPersistent() && attribute.isReadable()) {
+                        // copy the current attribute value to the persistent value
+                        Object value = attribute.getValue();
+                        attribute.setPersistentValue(value);
+                    }
+                }
+
+                target = null;
+            }
+        }
+
+        public void doFail() {
+            running = false;
+
+            if (target instanceof GBeanLifecycle) {
+                ((GBeanLifecycle) target).doFail();
+            }
+
+            // stop all of the references
+            for (int i = 0; i < references.length; i++) {
+                references[i].stop();
+            }
+
+            target = null;
+
+            // do not stop the attibutes in the case of a failure
+            // failed gbeans may have corrupted attributes that would be persisted
+        }
+    }
+
+    private void addManagedObjectAttributes(Map attributesMap) {
+        //
+        //  Special attributes
+        //
+        attributesMap.put("objectName",
+                GBeanAttribute.createSpecialAttribute((GBeanAttribute) attributesMap.get("objectName"),
+                        this,
+                        "objectName",
+                        String.class,
+                        getObjectName()));
+
+        attributesMap.put("gbeanInfo",
+                GBeanAttribute.createSpecialAttribute((GBeanAttribute) attributesMap.get("gbeanInfo"),
+                        this,
+                        "gbeanInfo",
+                        GBeanInfo.class,
+                        gbeanInfo));
+
+        attributesMap.put("classLoader",
+                GBeanAttribute.createSpecialAttribute((GBeanAttribute) attributesMap.get("classLoader"),
+                        this,
+                        "classLoader",
+                        ClassLoader.class,
+                        classLoader));
+
+        attributesMap.put("gbeanLifecycleController",
+                GBeanAttribute.createSpecialAttribute((GBeanAttribute) attributesMap.get("gbeanLifecycleController"),
+                        this,
+                        "gbeanLifecycleController",
+                        GBeanLifecycleController.class,
+                        gbeanLifecycleController));
+
+        attributesMap.put("kernel",
+                GBeanAttribute.createSpecialAttribute((GBeanAttribute) attributesMap.get("kernel"),
+                        this,
+                        "kernel",
+                        Kernel.class,
+                        kernel));
+
+        //
+        // Framework attributes
+        //
+        attributesMap.put("state",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "state",
+                        Integer.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Integer(getState());
+                            }
+                        }));
+
+        attributesMap.put("startTime",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "startTime",
+                        Long.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Long(getStartTime());
+                            }
+                        }));
+
+        attributesMap.put("stateManageable",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "stateManageable",
+                        Boolean.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Boolean(isStateManageable());
+                            }
+                        }));
+
+        attributesMap.put("statisticsProvider",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "statisticsProvider",
+                        Boolean.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Boolean(isStatisticsProvider());
+                            }
+                        }));
+
+
+        attributesMap.put("eventProvider",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "eventProvider",
+                        Boolean.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Boolean(isEventProvider());
+                            }
+                        }));
+
+        attributesMap.put("gbeanEnabled",
+                GBeanAttribute.createFrameworkAttribute(this,
+                        "gbeanEnabled",
+                        Boolean.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                return new Boolean(isEnabled());
+                            }
+                        },
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws Exception {
+                                Boolean enabled = (Boolean) arguments[0];
+                                setEnabled(enabled.booleanValue());
+                                return null;
+                            }
+                        },
+                        true,
+                        Boolean.TRUE));
+    }
+
+    private void addManagedObjectOperations(Map operationsMap) {
+        operationsMap.put(new GOperationSignature("start", Collections.EMPTY_LIST),
+                GBeanOperation.createFrameworkOperation(this,
+                "start",
+                Collections.EMPTY_LIST,
+                new MethodInvoker() {
+                    public Object invoke(Object target, Object[] arguments) throws Exception {
+                        start();
+                        return null;
+                    }
+                }));
+
+        operationsMap.put(new GOperationSignature("startRecursive", Collections.EMPTY_LIST),
+                GBeanOperation.createFrameworkOperation(this,
+                "startRecursive",
+                Collections.EMPTY_LIST,
+                new MethodInvoker() {
+                    public Object invoke(Object target, Object[] arguments) throws Exception {
+                        startRecursive();
+                        return null;
+                    }
+                }));
+
+        operationsMap.put(new GOperationSignature("stop", Collections.EMPTY_LIST),
+                GBeanOperation.createFrameworkOperation(this,
+                "stop",
+                Collections.EMPTY_LIST,
+                new MethodInvoker() {
+                    public Object invoke(Object target, Object[] arguments) throws Exception {
+                        stop();
+                        return null;
+                    }
+                }));
+    }
+
+    public String toString() {
+        if (objectName == null) {
+            return super.toString();
+        }
+        return objectName.toString();
+    }
+
+    // todo this is a lame hack to get around the gbean info not being accurate when the gbean instance is creted
+    private GBeanInfo rebuildGBeanInfo(GBeanInfo source) {
+        Set attributeInfos = new HashSet();
+        for (int i = 0; i < attributes.length; i++) {
+            GBeanAttribute attribute = attributes[i];
+            if (attribute.isDynamic()) {
+                attributeInfos.add(new DynamicGAttributeInfo(attribute.getName(),
+                        attribute.getType().getName(),
+                        attribute.isPersistent(),
+                        attribute.isReadable(),
+                        attribute.isWritable()
+                ));
+            } else {
+                attributeInfos.add(new GAttributeInfo(attribute.getName(),
+                        attribute.getType().getName(),
+                        attribute.isPersistent(),
+                        Boolean.valueOf(attribute.isReadable()),
+                        Boolean.valueOf(attribute.isWritable()),
+                        null,
+                        null
+                ));
+            }
+        }
+        Set operationInfos = new HashSet();
+        for (int i = 0; i < operations.length; i++) {
+            GBeanOperation operation = operations[i];
+            operationInfos.add(new GOperationInfo(operation.getName(), operation.getParameterTypes()));
+        }
+
+        Set referenceInfos = new HashSet();
+        for (int i = 0; i < references.length; i++) {
+            GBeanReference reference = references[i];
+            referenceInfos.add(new GReferenceInfo(reference.getName(), reference.getType()));
+        }
+
+        return Util.perfect(new GBeanInfo(source.getName(),
+                source.getClassName(),
+                attributeInfos,
+                source.getConstructor(),
+                operationInfos,
+                referenceInfos,
+                new HashSet(Arrays.asList(NotificationType.TYPES))), classLoader);
+    }
+}

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceLifecycleController.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceLifecycleController.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceLifecycleController.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanLifecycleController.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceLifecycleController.java	Thu Nov 25 13:40:42 2004
@@ -15,27 +15,26 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import org.apache.geronimo.gbean.GBeanLifecycleController;
-import org.apache.geronimo.kernel.management.State;
 
 /**
  * @version $Rev$ $Date$
  */
-public final class GBeanMBeanLifecycleController implements GBeanLifecycleController {
+public final class GBeanInstanceLifecycleController implements GBeanLifecycleController {
     /**
-     * The GeronimoMBean which owns the target.
+     * The GeronimoInstance which owns the target.
      */
-    private final GBeanMBean gmbean;
+    private final GBeanInstance gbeanInstance;
 
     /**
      * Creates a new context for a target.
      *
-     * @param gmbean the Geronimo Mbean the contains the target
+     * @param gbeanInstance the GeronimoInstance 
      */
-    public GBeanMBeanLifecycleController(GBeanMBean gmbean) {
-        this.gmbean = gmbean;
+    public GBeanInstanceLifecycleController(GBeanInstance gbeanInstance) {
+        this.gbeanInstance = gbeanInstance;
     }
 
     /**
@@ -45,7 +44,7 @@
      * @return the current state of this component
      */
     public int getState() {
-        return gmbean.getState();
+        return gbeanInstance.getState();
     }
 
     /**
@@ -57,7 +56,7 @@
      * @throws Exception if a problem occurs while starting the component
      */
     public void start() throws Exception {
-        gmbean.attemptFullStart();
+        gbeanInstance.start();
     }
 
     /**
@@ -69,12 +68,7 @@
      * @throws Exception if a problem occurs while stopping the component
      */
     public void stop() throws Exception {
-        final int state = gmbean.getState();
-        if (state == State.RUNNING_INDEX || state == State.STARTING_INDEX) {
-            gmbean.stop();
-        } else if (state == State.STOPPING_INDEX) {
-            gmbean.attemptFullStop();
-        }
+        gbeanInstance.stop();
     }
 
     /**
@@ -83,6 +77,6 @@
      * The component is guaranteed to be in the failed state when the method returns.
      */
     public void fail() {
-        gmbean.fail();
+        gbeanInstance.fail();
     }
 }

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,546 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.gbean.runtime;
+
+import java.util.Set;
+import java.util.Iterator;
+
+import javax.management.ObjectName;
+
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.LifecycleAdapter;
+import org.apache.geronimo.kernel.LifecycleListener;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GBeanInstanceState {
+    private static final Log log = LogFactory.getLog(GBeanInstanceState.class);
+
+    /**
+     * The GBeanInstance in which this server is registered.
+     */
+    private final GBeanLifecycle gbeanLifecycle;
+
+    /**
+     * The kernel in which this server is registered.
+     */
+    private final Kernel kernel;
+
+    /**
+     * The unique name of this service.
+     */
+    private final ObjectName objectName;
+
+    /**
+     * The dependency manager
+     */
+    private final DependencyManager dependencyManager;
+
+    /**
+     * The broadcaster of lifecycle events
+     */
+    private final LifecycleListener lifecycleBroadcaster;
+
+    /**
+     * The listener for the of the object blocking the start of this gbean.
+     * When the blocker dies we attempt to start.
+     */
+    private LifecycleListener blockerListener;
+
+    // This must be volatile otherwise getState must be synchronized which will result in deadlock as dependent
+    // objects check if each other are in one state or another (i.e., classic A calls B while B calls A)
+    private volatile State state = State.STOPPED;
+
+    GBeanInstanceState(Kernel kernel, ObjectName objectName, GBeanLifecycle gbeanLifecycle, LifecycleListener lifecycleBroadcaster) {
+        this.kernel = kernel;
+        this.dependencyManager = kernel.getDependencyManager();
+        this.objectName = objectName;
+        this.gbeanLifecycle = gbeanLifecycle;
+        this.lifecycleBroadcaster = lifecycleBroadcaster;
+    }
+
+    /**
+     * Moves this MBean to the {@link org.apache.geronimo.kernel.management.State#STARTING} state and then attempts to move this MBean immediately
+     * to the {@link org.apache.geronimo.kernel.management.State#RUNNING} state.
+     * <p/>
+     * Note:  This method cannot be called while the current thread holds a synchronized lock on this MBean,
+     * because this method sends JMX notifications. Sending a general notification from a synchronized block
+     * is a bad idea and therefore not allowed.
+     *
+     * @throws Exception If an exception occurs while starting this MBean
+     */
+    public final void start() throws Exception {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+
+        // Move to the starting state
+        State state;
+        synchronized (this) {
+            state = getStateInstance();
+            if (state == State.RUNNING) {
+                return;
+            }
+            // only try to change states if we are not already starting
+            if (state != State.STARTING) {
+                setStateInstance(State.STARTING);
+            }
+        }
+
+        // only fire a notification if we are not already starting
+        if (state != State.STARTING) {
+            lifecycleBroadcaster.starting(objectName);
+        }
+
+        attemptFullStart();
+    }
+
+    /**
+     * Starts this MBean and then attempts to start all of its start dependent children.
+     * <p/>
+     * Note:  This method cannot be call while the current thread holds a synchronized lock on this MBean,
+     * because this method sends JMX notifications.  Sending a general notification from a synchronized block
+     * is a bad idea and therefore not allowed.
+     *
+     * @throws Exception if a problem occurs will starting this MBean or any child MBean
+     */
+    public final void startRecursive() throws Exception {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+
+        State state = getStateInstance();
+        if (state != State.STOPPED && state != State.FAILED) {
+            // Cannot startRecursive while in the stopping state
+            // Dain: I don't think we can throw an exception here because there is no way for the caller
+            // to lock the instance and check the state before calling
+            return;
+        }
+
+        // get myself starting
+        start();
+
+        // startRecursive all of objects that depend on me
+        Set dependents = dependencyManager.getChildren(objectName);
+        for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
+            ObjectName dependent = (ObjectName) iterator.next();
+            boolean enabled = true;
+            try {
+                enabled = ((Boolean) kernel.getAttribute(dependent, "gbeanEnabled")).booleanValue();
+            } catch (NoSuchAttributeException e) {
+                // this is ok didn't have the attribute....
+            }
+            if (enabled) {
+                try {
+                    kernel.invoke(dependent, "startRecursive", null, null);
+                } catch (NoSuchMethodException e) {
+                    // did not have a startRecursive method - ok
+                }
+            }
+        }
+    }
+
+    /**
+     * Moves this MBean to the STOPPING state, calls stop on all start dependent children, and then attempt
+     * to move this MBean to the STOPPED state.
+     * <p/>
+     * Note:  This method can not be call while the current thread holds a syncronized lock on this MBean,
+     * because this method sends JMX notifications.  Sending a general notification from a synchronized block
+     * is a bad idea and therefore not allowed.
+     *
+     * @throws Exception If an exception occurs while stoping this MBean or any of the childern
+     */
+    public final void stop() throws Exception {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a syncrhonized lock on this";
+
+        // move to the stopping state
+        synchronized (this) {
+            State state = getStateInstance();
+            if (state == State.STOPPED) {
+                return;
+            }
+
+            // only try to change states if we are not already stopping
+            if (state != State.STOPPING) {
+                setStateInstance(State.STOPPING);
+            }
+        }
+
+        // only fire a notification if we are not already stopping
+        if (state != State.STOPPING) {
+            lifecycleBroadcaster.stopping(objectName);
+        }
+
+        // Don't try to stop dependents from within a synchronized block... this should reduce deadlocks
+
+        // stop all of my dependent objects
+        Set dependents = dependencyManager.getChildren(objectName);
+        for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
+            ObjectName child = (ObjectName) iterator.next();
+            try {
+                log.trace("Checking if child is running: child=" + child);
+                if (((Integer) kernel.getAttribute(child, "state")).intValue() == State.RUNNING_INDEX) {
+                    log.trace("Stopping child: child=" + child);
+                    kernel.invoke(child, "stop", null, null);
+                    log.trace("Stopped child: child=" + child);
+                }
+            } catch (Exception ignore) {
+                // not a big deal... did my best
+            }
+        }
+
+        attemptFullStop();
+    }
+
+    /**
+     * Moves this MBean to the FAILED state.  There are no calls to dependent children, but they will be notified
+     * using standard J2EE management notification.
+     * <p/>
+     * Note:  This method can not be call while the current thread holds a syncronized lock on this MBean,
+     * because this method sends JMX notifications.  Sending a general notification from a synchronized block
+     * is a bad idea and therefore not allowed.
+     */
+    final void fail() {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+
+        synchronized (this) {
+            State state = getStateInstance();
+            if (state == State.STOPPED || state == State.FAILED) {
+                return;
+            }
+            doSafeFail();
+            setStateInstance(State.FAILED);
+        }
+        lifecycleBroadcaster.failed(objectName);
+    }
+
+    /**
+     * Attempts to bring the component into {@link org.apache.geronimo.kernel.management.State#RUNNING} state. If an Exception occurs while
+     * starting the component, the component will be failed.
+     *
+     * @throws Exception if a problem occurs while starting the component
+     * <p/>
+     * Note: Do not call this from within a synchronized block as it makes may send a JMX notification
+     */
+    void attemptFullStart() throws Exception {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+
+        State newState = null;
+        try {
+            synchronized (this) {
+                try {
+                    // if we are still trying to start and can start now... start
+                    if (getStateInstance() != State.STARTING) {
+                        return;
+                    }
+
+                    // check if an mbean is blocking us from starting
+                    final ObjectName blocker = dependencyManager.checkBlocker(objectName);
+                    if (blocker != null) {
+                        blockerListener = new LifecycleAdapter() {
+
+                            public void stopped(ObjectName objectName) {
+                                checkBlocker(objectName);
+                            }
+
+                            public void failed(ObjectName objectName) {
+                                checkBlocker(objectName);
+                            }
+
+                            public void unloaded(ObjectName objectName) {
+                                checkBlocker(objectName);
+                            }
+
+                            private void checkBlocker(ObjectName objectName) {
+                                if (objectName.equals(blocker)) {
+                                    try {
+                                        attemptFullStart();
+                                    } catch (Exception e) {
+                                        log.warn("A problem occured while attempting to start", e);
+                                    }
+                                }
+                            }
+                        };
+                        kernel.getLifecycleMonitor().addLifecycleListener(blockerListener, blocker);
+                        return;
+                    }
+
+                    // check if all of the mbeans we depend on are running
+                    Set parents = dependencyManager.getParents(objectName);
+                    for (Iterator i = parents.iterator(); i.hasNext();) {
+                        ObjectName parent = (ObjectName) i.next();
+                        if (!kernel.isLoaded(parent)) {
+                            log.trace("Cannot run because parent is not registered: parent=" + parent);
+                            return;
+                        }
+                        try {
+                            log.trace("Checking if parent is running: parent=" + parent);
+                            if (((Integer) kernel.getAttribute(parent, "state")).intValue() != State.RUNNING_INDEX) {
+                                log.trace("Cannot run because parent is not running: parent=" + parent);
+                                return;
+                            }
+                            log.trace("Parent is running: parent=" + parent);
+                        } catch (NoSuchAttributeException e) {
+                            // ok -- parent is not a startable
+                            log.trace("Parent does not have a State attibute");
+                        } catch (GBeanNotFoundException e) {
+                            // depended on instance was removed bewteen the register check and the invoke
+                            log.trace("Cannot run because parent is not registered: parent=" + parent);
+                            return;
+                        } catch (Exception e) {
+                            // problem getting the attribute, parent has most likely failed
+                            log.trace("Cannot run because an error occurred while checking if parent is running: parent=" + parent);
+                            return;
+                        }
+                    }
+
+                    // remove any open watches on a blocker
+                    // todo is this correct if we are returning to a waiting state?
+                    if (blockerListener != null) {
+                        // remove any open watches on a blocker
+                        kernel.getLifecycleMonitor().removeLifecycleListener(blockerListener);
+                        blockerListener = null;
+                    }
+
+                    try {
+                        gbeanLifecycle.doStart();
+                    } catch (WaitingException e) {
+                        log.debug("Waiting to start: objectName=\"" + objectName + "\" reason=\"" + e.getMessage() + "\"");
+                        return;
+                    }
+                    setStateInstance(State.RUNNING);
+                    newState = State.RUNNING;
+                } catch (Exception e) {
+                    doSafeFail();
+                    setStateInstance(State.FAILED);
+                    newState = State.FAILED;
+                    throw e;
+                } catch (Error e) {
+                    doSafeFail();
+                    setStateInstance(State.FAILED);
+                    newState = State.FAILED;
+                    throw e;
+                }
+            }
+        } finally {
+            if (newState != null) {
+                stateChanged(newState);
+            }
+        }
+    }
+
+    /**
+     * Attempt to bring the component into the fully stopped state.
+     * If an exception occurs while stopping the component, the component will be failed.
+     *
+     * @throws Exception if a problem occurs while stopping the component
+     * <p/>
+     * Note: Do not call this from within a synchronized block as it may send a JMX notification
+     */
+    void attemptFullStop() throws Exception {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+
+        State newState = null;
+        try {
+            synchronized (this) {
+                // if we are still trying to stop...
+                if (getStateInstance() != State.STOPPING) {
+                    return;
+                }
+                try {
+                    // check if all of the mbeans depending on us are stopped
+                    Set children = dependencyManager.getChildren(objectName);
+                    for (Iterator i = children.iterator(); i.hasNext();) {
+                        ObjectName child = (ObjectName) i.next();
+                        if (kernel.isLoaded(child)) {
+                            try {
+                                log.trace("Checking if child is stopped: child=" + child);
+                                int state = ((Integer) kernel.getAttribute(child, "State")).intValue();
+                                if (state == State.RUNNING_INDEX) {
+                                    log.trace("Cannot stop because child is still running: child=" + child);
+                                    return;
+                                }
+                            } catch (NoSuchAttributeException e) {
+                                // ok -- dependect bean is not state manageable
+                                log.trace("Child does not have a State attibute");
+                            } catch (GBeanNotFoundException e) {
+                                // depended on instance was removed between the register check and the invoke
+                            } catch (Exception e) {
+                                // problem getting the attribute, depended on bean has most likely failed
+                                log.trace("Cannot run because an error occurred while checking if child is stopped: child=" + child);
+                                return;
+                            }
+                        }
+                    }
+
+                    // if we can stop, stop
+                    try {
+                        gbeanLifecycle.doStop();
+                    } catch (WaitingException e) {
+                        log.debug("Waiting to stop: objectName=\"" + objectName + "\" reason=\"" + e.getMessage() + "\"");
+                        return;
+                    }
+                    setStateInstance(State.STOPPED);
+                    newState = State.STOPPED;
+                } catch (Exception e) {
+                    doSafeFail();
+                    setStateInstance(State.FAILED);
+                    newState = State.FAILED;
+                    throw e;
+                } catch (Error e) {
+                    doSafeFail();
+                    setStateInstance(State.FAILED);
+                    newState = State.FAILED;
+                    throw e;
+                }
+            }
+        } finally {
+            if (newState != null) {
+                stateChanged(newState);
+            }
+        }
+    }
+
+    /**
+     * Calls doFail, but catches all RutimeExceptions and Errors.
+     * These problems are logged but ignored.
+     * <p/>
+     * Note: This must be called while holding a lock on this
+     */
+    private void doSafeFail() {
+        assert Thread.holdsLock(this): "This method can only called while holding a synchronized lock on this";
+
+        try {
+            gbeanLifecycle.doFail();
+        } catch (RuntimeException e) {
+            log.warn("RuntimeException thrown from doFail", e);
+        } catch (Error e) {
+            log.warn("Error thrown from doFail", e);
+        }
+    }
+
+    public int getState() {
+        return state.toInt();
+    }
+
+    public final State getStateInstance() {
+        return state;
+    }
+
+    /**
+     * Set the Component state.
+     *
+     * @param newState the target state to transition
+     * @throws IllegalStateException Thrown if the transition is not supported by the J2EE Management lifecycle.
+     */
+    private synchronized void setStateInstance(State newState) throws IllegalStateException {
+        switch (state.toInt()) {
+            case State.STOPPED_INDEX:
+                switch (newState.toInt()) {
+                    case State.STARTING_INDEX:
+                        break;
+                    case State.STOPPED_INDEX:
+                    case State.RUNNING_INDEX:
+                    case State.STOPPING_INDEX:
+                    case State.FAILED_INDEX:
+                        throw new IllegalStateException("Cannot transition to " + newState + " state from " + state);
+                }
+                break;
+
+            case State.STARTING_INDEX:
+                switch (newState.toInt()) {
+                    case State.RUNNING_INDEX:
+                    case State.FAILED_INDEX:
+                    case State.STOPPING_INDEX:
+                        break;
+                    case State.STOPPED_INDEX:
+                    case State.STARTING_INDEX:
+                        throw new IllegalStateException("Cannot transition to " + newState + " state from " + state);
+                }
+                break;
+
+            case State.RUNNING_INDEX:
+                switch (newState.toInt()) {
+                    case State.STOPPING_INDEX:
+                    case State.FAILED_INDEX:
+                        break;
+                    case State.STOPPED_INDEX:
+                    case State.STARTING_INDEX:
+                    case State.RUNNING_INDEX:
+                        throw new IllegalStateException("Cannot transition to " + newState + " state from " + state);
+                }
+                break;
+
+            case State.STOPPING_INDEX:
+                switch (newState.toInt()) {
+                    case State.STOPPED_INDEX:
+                    case State.FAILED_INDEX:
+                        break;
+                    case State.STARTING_INDEX:
+                    case State.RUNNING_INDEX:
+                    case State.STOPPING_INDEX:
+                        throw new IllegalStateException("Cannot transition to " + newState + " state from " + state);
+                }
+                break;
+
+            case State.FAILED_INDEX:
+                switch (newState.toInt()) {
+                    case State.STARTING_INDEX:
+                    case State.STOPPING_INDEX:
+                        break;
+                    case State.RUNNING_INDEX:
+                    case State.STOPPED_INDEX:
+                    case State.FAILED_INDEX:
+                        throw new IllegalStateException("Cannot transition to " + newState + " state from " + state);
+                }
+                break;
+        }
+        log.debug(toString() + " State changed from " + state + " to " + newState);
+        state = newState;
+    }
+
+    private void stateChanged(State state) {
+        assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized lock on this";
+        switch (state.toInt()) {
+            case State.STOPPED_INDEX:
+                lifecycleBroadcaster.stopped(objectName);
+                break;
+
+            case State.STARTING_INDEX:
+                lifecycleBroadcaster.starting(objectName);
+                break;
+
+            case State.RUNNING_INDEX:
+                lifecycleBroadcaster.running(objectName);
+                break;
+
+            case State.STOPPING_INDEX:
+                lifecycleBroadcaster.stopping(objectName);
+                break;
+
+            case State.FAILED_INDEX:
+                lifecycleBroadcaster.failed(objectName);
+                break;
+        }
+    }
+
+}

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanOperation.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanOperation.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanOperation.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanOperation.java	Thu Nov 25 13:40:42 2004
@@ -15,18 +15,13 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
 import java.util.Iterator;
-
-import javax.management.MBeanOperationInfo;
-import javax.management.MBeanParameterInfo;
-import javax.management.ReflectionException;
+import java.util.List;
 
 import org.apache.geronimo.gbean.DynamicGBean;
 import org.apache.geronimo.gbean.DynamicGOperationInfo;
@@ -37,47 +32,34 @@
 /**
  * @version $Rev$ $Date$
  */
-public final class GBeanMBeanOperation {
-    private final GBeanMBean gmbean;
+public final class GBeanOperation {
+    private final GBeanInstance gbeanInstance;
     private final String name;
     private final List parameterTypes;
-    private final MBeanOperationInfo mbeanOperationInfo;
     private final MethodInvoker methodInvoker;
     private final boolean framework;
 
-    static GBeanMBeanOperation createFrameworkOperation(GBeanMBean gMBean, String name, List parameterTypes, Class returnType, MethodInvoker methodInvoker) {
-        return new GBeanMBeanOperation(gMBean, name, parameterTypes, returnType, methodInvoker);
+    static GBeanOperation createFrameworkOperation(GBeanInstance gbeanInstance, String name, List parameterTypes, MethodInvoker methodInvoker) {
+        return new GBeanOperation(gbeanInstance, name, parameterTypes, methodInvoker);
     }
 
-    private GBeanMBeanOperation(GBeanMBean gMBean, String name, List parameterTypes, Class returnType, MethodInvoker methodInvoker) {
+    private GBeanOperation(GBeanInstance gbeanInstance, String name, List parameterTypes, MethodInvoker methodInvoker) {
         framework = true;
-        this.gmbean = gMBean;
+        this.gbeanInstance = gbeanInstance;
         this.name = name;
         this.parameterTypes = Collections.unmodifiableList(new ArrayList(parameterTypes));
         this.methodInvoker = methodInvoker;
-
-        MBeanParameterInfo[] signature = new MBeanParameterInfo[parameterTypes.size()];
-        for (int i = 0; i < signature.length; i++) {
-            signature[i] = new MBeanParameterInfo("arg" + i, (String) parameterTypes.get(i), null);
-        }
-
-        mbeanOperationInfo = new MBeanOperationInfo(name,
-                null,
-                signature,
-                returnType.getName(),
-                MBeanOperationInfo.UNKNOWN);
-
     }
 
-    public GBeanMBeanOperation(GBeanMBean gMBean, GOperationInfo operationInfo) throws InvalidConfigurationException {
+    public GBeanOperation(GBeanInstance gbeanInstance, GOperationInfo operationInfo) throws InvalidConfigurationException {
         framework = false;
-        this.gmbean = gMBean;
+        this.gbeanInstance = gbeanInstance;
         this.name = operationInfo.getName();
 
         // get an array of the parameter classes
         this.parameterTypes = Collections.unmodifiableList(new ArrayList(operationInfo.getParameterList()));
         Class[] types = new Class[parameterTypes.size()];
-        ClassLoader classLoader = gMBean.getClassLoader();
+        ClassLoader classLoader = gbeanInstance.getClassLoader();
         for (int i = 0; i < types.length; i++) {
             String type = (String) parameterTypes.get(i);
             try {
@@ -90,43 +72,27 @@
         }
 
         // get a method invoker for the operation
-        Class returnType;
         if (operationInfo instanceof DynamicGOperationInfo) {
-            returnType = Object.class;
             methodInvoker = new MethodInvoker() {
                 private String[] types = (String[]) parameterTypes.toArray(new String[parameterTypes.size()]);
 
                 public Object invoke(Object target, Object[] arguments) throws Exception {
-                    DynamicGBean dynamicGBean = (DynamicGBean) GBeanMBeanOperation.this.gmbean.getTarget();
+                    DynamicGBean dynamicGBean = (DynamicGBean) GBeanOperation.this.gbeanInstance.getTarget();
                     dynamicGBean.invoke(name, arguments, types);
                     return null;
                 }
             };
         } else {
             try {
-                Method javaMethod = gMBean.getType().getMethod(operationInfo.getMethodName(), types);
-                returnType = javaMethod.getReturnType();
+                Method javaMethod = gbeanInstance.getType().getMethod(operationInfo.getMethodName(), types);
                 methodInvoker = new FastMethodInvoker(javaMethod);
             } catch (Exception e) {
                 throw new InvalidConfigurationException("Target does not have specified method (declared in a GBeanInfo operation):" +
                         " name=" + operationInfo.getName() +
                         " methodName=" + operationInfo.getMethodName() +
-                        " targetClass=" + gMBean.getType().getName());
+                        " targetClass=" + gbeanInstance.getType().getName());
             }
         }
-
-        MBeanParameterInfo[] signature = new MBeanParameterInfo[parameterTypes.size()];
-        for (int i = 0; i < signature.length; i++) {
-            signature[i] = new MBeanParameterInfo("arg" + i,
-                    (String) parameterTypes.get(i),
-                    null);
-        }
-
-        mbeanOperationInfo = new MBeanOperationInfo(operationInfo.getName(),
-                null,
-                signature,
-                returnType.getName(),
-                MBeanOperationInfo.UNKNOWN);
     }
 
     public String getName() {
@@ -137,23 +103,12 @@
         return parameterTypes;
     }
 
-    public MBeanOperationInfo getMbeanOperationInfo() {
-        return mbeanOperationInfo;
-    }
-
     public boolean isFramework() {
         return framework;
     }
 
-    public Object invoke(final Object[] arguments) throws ReflectionException {
-        // get the target to invoke
-        try {
-            return methodInvoker.invoke(gmbean.getTarget(), arguments);
-        } catch (Exception e) {
-            throw new ReflectionException(e);
-        } catch (Throwable throwable) {
-            throw new ReflectionException(new InvocationTargetException(throwable));
-        }
+    public Object invoke(final Object[] arguments) throws Exception {
+        return methodInvoker.invoke(gbeanInstance.getTarget(), arguments);
     }
 
     public String getDescription() {
@@ -166,6 +121,6 @@
             }
         }
         signature += ")";
-        return "Operation Signature: " + signature + ", GBean: " + gmbean.getName();
+        return "Operation Signature: " + signature + ", GBeanInstance: " + gbeanInstance.getName();
     }
 }

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanReference.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanReference.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanReference.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanReference.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanReference.java	Thu Nov 25 13:40:42 2004
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.util.Set;
 

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java (from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java&r1=106387&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanSingleReference.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanSingleReference.java	Thu Nov 25 13:40:42 2004
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.util.Set;
 import javax.management.ObjectName;
@@ -44,8 +44,8 @@
      */
     private ObjectName proxyTarget;
 
-    public GBeanSingleReference(GBeanMBean gmbean, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
-        super(gmbean, referenceInfo, constructorType);
+    public GBeanSingleReference(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo, Class constructorType) throws InvalidConfigurationException {
+        super(gbeanInstance, referenceInfo, constructorType);
     }
 
     public synchronized void start() throws Exception {
@@ -74,7 +74,7 @@
 
         // stop all gbeans that would match our patterns from starting
         Kernel kernel = getKernel();
-        ObjectName objectName = getGBeanMBean().getObjectNameObject();
+        ObjectName objectName = getGBeanInstance().getObjectNameObject();
         kernel.getDependencyManager().addStartHolds(objectName, getPatterns());
 
         // add a dependency on our target and create the proxy
@@ -87,7 +87,7 @@
     public synchronized void stop() {
         waitingForMe = false;
         Kernel kernel = getKernel();
-        ObjectName objectName = getGBeanMBean().getObjectNameObject();
+        ObjectName objectName = getGBeanInstance().getObjectNameObject();
         Set patterns = getPatterns();
         if (!patterns.isEmpty()) {
             kernel.getDependencyManager().removeStartHolds(objectName, patterns);
@@ -104,9 +104,9 @@
 
     public synchronized void targetAdded(ObjectName target) {
         // if we are running, and we now have two valid targets, which is an illegal state so we need to fail
-        GBeanMBean gbeanMBean = getGBeanMBean();
-        if (gbeanMBean.getStateInstance() == State.RUNNING) {
-            gbeanMBean.fail();
+        GBeanInstance gbeanInstance = getGBeanInstance();
+        if (gbeanInstance.getStateInstance() == State.RUNNING) {
+            gbeanInstance.fail();
         } else if (waitingForMe) {
             Set targets = getTargets();
             if (targets.size() == 1) {
@@ -117,10 +117,10 @@
     }
 
     public synchronized void targetRemoved(ObjectName target) {
-        GBeanMBean gbeanMBean = getGBeanMBean();
-        if (gbeanMBean.getStateInstance() == State.RUNNING) {
+        GBeanInstance gbeanInstance = getGBeanInstance();
+        if (gbeanInstance.getStateInstance() == State.RUNNING) {
             // we no longer have a valid target, which is an illegal state so we need to fail
-            gbeanMBean.fail();
+            gbeanInstance.fail();
         } else if (waitingForMe) {
             Set targets = getTargets();
             if (targets.size() == 1) {
@@ -136,9 +136,9 @@
             // component never reached the starting phase... then a target registers and we automatically
             // attempt to restart
             waitingForMe = false;
-            getGBeanMBean().attemptFullStart();
+            getGBeanInstance().start();
         } catch (Exception e) {
-            log.warn("Exception occured while attempting to fully start: objectName=" + getGBeanMBean().getObjectName(), e);
+            log.warn("Exception occured while attempting to fully start: objectName=" + getGBeanInstance().getObjectName(), e);
         }
     }
 

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/MethodInvoker.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/MethodInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/MethodInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/MethodInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/MethodInvoker.java	Thu Nov 25 13:40:42 2004
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 /**
  * @version $Rev$ $Date$

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java (from r106387, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java&r1=106387&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyCollection.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java	Thu Nov 25 13:40:42 2004
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.util.ArrayList;
 import java.util.Collection;

Copied: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/RawInvoker.java (from r106386, geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/RawInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/RawInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/RawInvoker.java	Thu Nov 25 13:40:42 2004
@@ -14,28 +14,25 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
 import java.util.Map;
-import javax.management.JMException;
-import javax.management.JMRuntimeException;
-import javax.management.ReflectionException;
 
 /**
  * The raw invoker provides a raw (fast) access invoke operations, get attribute values, and set
  * attribute values on a GBean.  This class should only be use by GBean proxy generators or carefully
- * crafted container code, because this class maintains a hard reference to a gbean which has a huge
+ * crafted container code, because this class maintains a hard reference to a gbeanInstance which has a huge
  * potential for memory leaks.  USE WITH CAUTION
  *
  * @version $Rev$ $Date$
  */
 public final class RawInvoker {
-    private final GBeanMBean gbean;
+    private final GBeanInstance gbeanInstance;
     private final Map attributeIndex;
     private final Map operationIndex;
 
-    public RawInvoker(GBeanMBean gbean) {
-        this.gbean = gbean;
+    public RawInvoker(GBeanInstance gbean) {
+        this.gbeanInstance = gbean;
         attributeIndex = gbean.getAttributeIndex();
         operationIndex = gbean.getOperationIndex();
     }
@@ -49,56 +46,14 @@
     }
 
     public Object getAttribute(final int index) throws Exception {
-        try {
-            return gbean.getAttribute(index);
-        } catch (ReflectionException e) {
-            Throwable cause = e;
-            while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
-                cause = cause.getCause();
-            }
-            if (cause instanceof Error) {
-                throw (Error) cause;
-            } else if (cause instanceof Exception) {
-                throw (Exception) cause;
-            } else {
-                throw new AssertionError(cause);
-            }
-        }
+        return gbeanInstance.getAttribute(index);
     }
 
     public void setAttribute(final int index, final Object value) throws Exception {
-        try {
-            gbean.setAttribute(index, value);
-        } catch (ReflectionException e) {
-            Throwable cause = e;
-            while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
-                cause = cause.getCause();
-            }
-            if (cause instanceof Error) {
-                throw (Error) cause;
-            } else if (cause instanceof Exception) {
-                throw (Exception) cause;
-            } else {
-                throw new AssertionError(cause);
-            }
-        }
+        gbeanInstance.setAttribute(index, value);
     }
 
     public Object invoke(final int index, final Object[] args) throws Exception {
-        try {
-            return gbean.invoke(index, args);
-        } catch (ReflectionException e) {
-            Throwable cause = e;
-            while ((cause instanceof JMException || cause instanceof JMRuntimeException) && cause.getCause() != null) {
-                cause = cause.getCause();
-            }
-            if (cause instanceof Error) {
-                throw (Error) cause;
-            } else if (cause instanceof Exception) {
-                throw (Exception) cause;
-            } else {
-                throw new AssertionError(cause);
-            }
-        }
+        return gbeanInstance.invoke(index, args);
     }
 }

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/Util.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/Util.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/Util.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,368 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.gbean.runtime;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.gbean.DynamicGAttributeInfo;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GOperationInfo;
+import org.apache.geronimo.gbean.GReferenceInfo;
+import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.kernel.ClassLoading;
+import org.apache.geronimo.kernel.management.NotificationType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class Util {
+    private Util() { }
+
+    public static GBeanInfo perfect(GBeanInfo source, ClassLoader classLoader) {
+        Class gbeanType;
+        try {
+            gbeanType = ClassLoading.loadClass(source.getClassName(), classLoader);
+        } catch (ClassNotFoundException e) {
+            throw new InvalidConfigurationException("Could not load attribute class: " + source.getClassName());
+        }
+
+        Set attributes = new HashSet();
+        for (Iterator iterator = source.getAttributes().iterator(); iterator.hasNext();) {
+            GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
+            attributes.add(perfect(attributeInfo, gbeanType, classLoader));
+        }
+
+        Set operations = new HashSet();
+        for (Iterator iterator = source.getOperations().iterator(); iterator.hasNext();) {
+            GOperationInfo operationInfo = (GOperationInfo) iterator.next();
+            operations.add(perfect(operationInfo));
+        }
+
+        Set constructorArgs = new HashSet(source.getConstructor().getAttributeNames());
+        Set references = new HashSet();
+        for (Iterator iterator = source.getReferences().iterator(); iterator.hasNext();) {
+            GReferenceInfo referenceInfo = (GReferenceInfo) iterator.next();
+            references.add(perfect(referenceInfo, gbeanType, constructorArgs.contains(referenceInfo.getName())));
+        }
+
+        return new GBeanInfo(source.getName(),
+                source.getClassName(),
+                attributes,
+                source.getConstructor(),
+                operations,
+                references,
+                new HashSet(Arrays.asList(NotificationType.TYPES)));
+    }
+
+    private static GAttributeInfo perfect(GAttributeInfo attributeInfo, Class gbeanType, ClassLoader classLoader) {
+        String name = attributeInfo.getName();
+
+        Class type;
+        try {
+            type = ClassLoading.loadClass(attributeInfo.getType(), classLoader);
+        } catch (ClassNotFoundException e) {
+            throw new InvalidConfigurationException("Could not load attribute class: " + attributeInfo.getType());
+        }
+        boolean persistent = attributeInfo.isPersistent();
+
+        // If attribute is persistent or not tagged as unreadable, search for a
+        // getter method
+        if (attributeInfo instanceof DynamicGAttributeInfo) {
+            return new DynamicGAttributeInfo(name, attributeInfo.getType(), persistent, attributeInfo.isReadable().booleanValue(), attributeInfo.isWritable().booleanValue());
+        }
+
+
+        Method getterMethod = searchForGetter(gbeanType, attributeInfo, type);
+        boolean readable;
+        String getterName;
+        if (getterMethod != null) {
+            getterName = getterMethod.getName();
+            // this attribute is readable as long as it was not explicitly
+            // tagged as unreadable
+            readable = attributeInfo.isReadable() != Boolean.FALSE;
+        } else {
+            getterName = null;
+            readable = false;
+        }
+
+        // If attribute is persistent or not tagged as unwritable, search
+        // for a setter method
+        Method setterMethod = searchForSetter(gbeanType, attributeInfo, type);
+        boolean writable;
+        String setterName;
+        if (setterMethod != null) {
+            setterName = setterMethod.getName();
+
+            // this attribute is writable as long as it was not explicitly
+            // tagged as unwritable
+            writable = attributeInfo.isWritable() != Boolean.FALSE;
+        } else {
+            setterName = null;
+            writable = false;
+        }
+
+        return new GAttributeInfo(name, attributeInfo.getType(), persistent, Boolean.valueOf(readable), Boolean.valueOf(writable), getterName, setterName);
+    }
+
+    private static GOperationInfo perfect(GOperationInfo operationInfo) {
+        return new GOperationInfo(operationInfo.getName(), operationInfo.getParameterList());
+    }
+
+    private static GReferenceInfo perfect(GReferenceInfo referenceInfo, Class gbeanType, boolean isConstructorArg) {
+        String name = referenceInfo.getName();
+        String setterName;
+        if (isConstructorArg) {
+            setterName = null;
+        } else {
+            Method setterMethod = searchForSetter(gbeanType, referenceInfo);
+            setterName = setterMethod.getName();
+        }
+
+        return new GReferenceInfo(name, referenceInfo.getType(), setterName);
+    }
+
+    public static boolean isCollectionValuedReference(GBeanInstance gbeanMBean, GReferenceInfo referenceInfo, Class constructorType) {
+        if (constructorType != null) {
+            return Collection.class == constructorType;
+        } else {
+            Method setterMethod = searchForSetter(gbeanMBean.getType(), referenceInfo);
+            return Collection.class == setterMethod.getParameterTypes()[0];
+        }
+    }
+
+    /**
+     * Search for a single valid constructor in the class.  A valid constructor is determined by the
+     * attributes and references declared in the GBeanInfo.  For each, constructor gbean attribute
+     * the parameter must have the exact same type.  For a constructor gbean reference parameter, the
+     * parameter type must either match the reference proxy type, be java.util.Collection, or be
+     * java.util.Set.
+     *
+     * @param beanInfo the metadata describing the constructor, attrbutes and references
+     * @param type the target type in which we search for a constructor
+     * @return the sole matching constructor
+     * @throws org.apache.geronimo.gbean.InvalidConfigurationException if there are no valid constructors or more then one valid
+     * constructors; multiple constructors can match in the case of a gbean reference parameter
+     */
+    public static Constructor searchForConstructor(GBeanInfo beanInfo, Class type) throws InvalidConfigurationException {
+        Set attributes = beanInfo.getAttributes();
+        Map attributeTypes = new HashMap(attributes.size());
+        for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
+            GAttributeInfo attribute = (GAttributeInfo) iterator.next();
+            attributeTypes.put(attribute.getName(), attribute.getType());
+        }
+
+        Set references = beanInfo.getReferences();
+        Map referenceTypes = new HashMap(references.size());
+        for (Iterator iterator = references.iterator(); iterator.hasNext();) {
+            GReferenceInfo reference = (GReferenceInfo) iterator.next();
+            referenceTypes.put(reference.getName(), reference.getType());
+        }
+
+        List arguments = beanInfo.getConstructor().getAttributeNames();
+        String[] argumentTypes = new String[arguments.size()];
+        boolean[] isReference = new boolean[arguments.size()];
+        for (int i = 0; i < argumentTypes.length; i++) {
+            String argumentName = (String) arguments.get(i);
+            if (attributeTypes.containsKey(argumentName)) {
+                argumentTypes[i] = (String) attributeTypes.get(argumentName);
+                isReference[i] = false;
+            } else if (referenceTypes.containsKey(argumentName)) {
+                argumentTypes[i] = (String) referenceTypes.get(argumentName);
+                isReference[i] = true;
+            }
+        }
+
+        Constructor[] constructors = type.getConstructors();
+        Set validConstructors = new HashSet();
+        for (int i = 0; i < constructors.length; i++) {
+            Constructor constructor = constructors[i];
+            if (isValidConstructor(constructor, argumentTypes, isReference)) {
+                validConstructors.add(constructor);
+            }
+        }
+
+        if (validConstructors.isEmpty()) {
+            throw new InvalidConfigurationException("Could not find a valid constructor for GBean: " + beanInfo.getName());
+        }
+        if (validConstructors.size() > 1) {
+            throw new InvalidConfigurationException("More then one valid constructors found for GBean: " + beanInfo.getName());
+        }
+        return (Constructor) validConstructors.iterator().next();
+    }
+
+    /**
+     * Is this a valid constructor for the GBean.  This is determined based on the argument types and
+     * if an argument is a reference, as determined by the boolean array, the argument may also be
+     * java.util.Collection or java.util.Set.
+     *
+     * @param constructor the class constructor
+     * @param argumentTypes types of the attributes and references
+     * @param isReference if the argument is a gbean reference
+     * @return true if this is a valid constructor for gbean; false otherwise
+     */
+    private static boolean isValidConstructor(Constructor constructor, String[] argumentTypes, boolean[] isReference) {
+        Class[] parameterTypes = constructor.getParameterTypes();
+
+        // same number of parameters?
+        if (parameterTypes.length != argumentTypes.length) {
+            return false;
+        }
+
+        // is each parameter the correct type?
+        for (int i = 0; i < parameterTypes.length; i++) {
+            String parameterType = parameterTypes[i].getName();
+            if (isReference[i]) {
+                // reference: does type match
+                // OR is it a java.util.Collection
+                // OR is it a java.util.Set?
+                if (!parameterType.equals(argumentTypes[i]) &&
+                        !parameterType.equals(Collection.class.getName()) &&
+                        !parameterType.equals(Set.class.getName())) {
+                    return false;
+                }
+            } else {
+                // attribute: does type match?
+                if (!parameterType.equals(argumentTypes[i])) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    public static Method searchForGetter(Class gbeanType, GAttributeInfo attributeInfo, Class type) throws InvalidConfigurationException {
+        Method getterMethod = null;
+        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 = gbeanType.getMethods();
+            for (int i = 0; i < methods.length; i++) {
+                if (methods[i].getParameterTypes().length == 0 && methods[i].getReturnType() != Void.TYPE
+                        && (getterName.equalsIgnoreCase(methods[i].getName()) || isName.equalsIgnoreCase(methods[i].getName()))) {
+
+                    // found it
+                    getterMethod = methods[i];
+                    break;
+                }
+            }
+        } else {
+            // we have an explicit name, so no searching is necessary
+            try {
+                getterMethod = gbeanType.getMethod(attributeInfo.getGetterName(), null);
+                if (getterMethod.getReturnType() == Void.TYPE) {
+                    throw new InvalidConfigurationException("Getter method return VOID:" +
+                            " name=" + attributeInfo.getName() +
+                            ", type=" + type.getName() +
+                            ", targetClass=" + gbeanType.getName());
+                }
+            } catch (Exception e) {
+                // we will throw the formatted exception below
+            }
+        }
+
+        // if the return type of the getter doesn't match, throw an exception
+        if (getterMethod != null && !type.equals(getterMethod.getReturnType())) {
+            throw new InvalidConfigurationException("Incorrect return type for getter method:" +
+                    " name=" + attributeInfo.getName() +
+                    ", targetClass=" + gbeanType.getName() +
+                    ", getter type=" + getterMethod.getReturnType() +
+                    ", expected type=" + type.getName());
+        }
+
+        return getterMethod;
+    }
+
+    public static Method searchForSetter(Class gbeanType, GAttributeInfo attributeInfo, Class type) throws InvalidConfigurationException {
+        if (attributeInfo.getSetterName() == null) {
+            // no explicit name give so we must search for a name
+            String setterName = "set" + attributeInfo.getName();
+            Method[] methods = gbeanType.getMethods();
+            for (int i = 0; i < methods.length; i++) {
+                Method method = methods[i];
+                if (method.getParameterTypes().length == 1 &&
+                        method.getParameterTypes()[0].equals(type) &&
+                        method.getReturnType() == Void.TYPE &&
+                        setterName.equalsIgnoreCase(method.getName())) {
+
+                    return method;
+                }
+            }
+        } else {
+            // we have an explicit name, so no searching is necessary
+            try {
+                Method method = gbeanType.getMethod(attributeInfo.getSetterName(), new Class[]{type});
+                if (method.getReturnType() != Void.TYPE) {
+                    throw new InvalidConfigurationException("Setter method must return VOID:" +
+                            " name=" + attributeInfo.getName() +
+                            ", type=" + type.getName() +
+                            ", targetClass=" + gbeanType.getName());
+                }
+                return method;
+            } catch (Exception e) {
+                // we will throw the formatted exception below
+            }
+        }
+
+        // a setter is not necessary for this attribute
+        return null;
+    }
+
+    public static Method searchForSetter(Class gbeanType, GReferenceInfo referenceInfo) throws InvalidConfigurationException {
+        if (referenceInfo.getSetterName() == null) {
+            // no explicit name give so we must search for a name
+            String setterName = "set" + referenceInfo.getName();
+            Method[] methods = gbeanType.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 because
+            // we don't know the parameter type
+            Method[] methods = gbeanType.getMethods();
+            String setterName = referenceInfo.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=" + referenceInfo.getName() +
+                " targetClass=" + gbeanType.getName());
+    }
+}

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanAlreadyExistsException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanAlreadyExistsException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanAlreadyExistsException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GBeanAlreadyExistsException extends KernelException {
+    public GBeanAlreadyExistsException() {
+    }
+
+    public GBeanAlreadyExistsException(String message) {
+        super(message);
+    }
+
+    public GBeanAlreadyExistsException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public GBeanAlreadyExistsException(Throwable cause) {
+        super(cause);
+    }
+}

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanNotFoundException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanNotFoundException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/GBeanNotFoundException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GBeanNotFoundException extends KernelException {
+    public GBeanNotFoundException() {
+    }
+
+    public GBeanNotFoundException(String message) {
+        super(message);
+    }
+
+    public GBeanNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public GBeanNotFoundException(Throwable cause) {
+        super(cause);
+    }
+}

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InternalKernelException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InternalKernelException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InternalKernelException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InternalKernelException extends RuntimeException {
+    public InternalKernelException() {
+    }
+
+    public InternalKernelException(String message) {
+        super(message);
+    }
+
+    public InternalKernelException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public InternalKernelException(Throwable cause) {
+        super(cause);
+    }
+}

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InvalidGBeanException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InvalidGBeanException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/InvalidGBeanException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidGBeanException extends KernelException {
+    public InvalidGBeanException() {
+    }
+
+    public InvalidGBeanException(String message) {
+        super(message);
+    }
+
+    public InvalidGBeanException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public InvalidGBeanException(Throwable cause) {
+        super(cause);
+    }
+}

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	Thu Nov 25 13:40:42 2004
@@ -40,12 +40,15 @@
 import javax.management.MalformedObjectNameException;
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.ObjectName;
+import javax.management.AttributeNotFoundException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
+import org.apache.geronimo.gbean.jmx.JMXLifecycleBroadcaster;
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.config.ConfigurationManagerImpl;
@@ -158,7 +161,7 @@
     /**
      * The GBeanMbean that wraps the configuration manager
      */
-    private GBeanMBean configurationManagerGBean;
+    private GBeanInstance configurationManagerInstance;
 
     /**
      * Monitors the lifecycle of all gbeans.
@@ -285,7 +288,11 @@
             return mbServer.getAttribute(objectName, attributeName);
         } catch (Exception e) {
             Throwable cause = unwrapJMException(e);
-            if (cause instanceof Error) {
+            if (cause instanceof InstanceNotFoundException) {
+                throw new GBeanNotFoundException(objectName.getCanonicalName());
+            } else if (cause instanceof AttributeNotFoundException) {
+                throw new NoSuchAttributeException(cause.getMessage());
+            } else if (cause instanceof Error) {
                 throw (Error) cause;
             } else if (cause instanceof Exception) {
                 throw (Exception) cause;
@@ -300,7 +307,11 @@
             mbServer.setAttribute(objectName, new Attribute(attributeName, attributeValue));
         } catch (Exception e) {
             Throwable cause = unwrapJMException(e);
-            if (cause instanceof Error) {
+            if (cause instanceof InstanceNotFoundException) {
+                throw new GBeanNotFoundException(objectName.getCanonicalName());
+            } else if (cause instanceof AttributeNotFoundException) {
+                throw new NoSuchAttributeException(cause.getMessage());
+            } else if (cause instanceof Error) {
                 throw (Error) cause;
             } else if (cause instanceof Exception) {
                 throw (Exception) cause;
@@ -319,7 +330,11 @@
             return mbServer.invoke(objectName, methodName, args, types);
         } catch (Exception e) {
             Throwable cause = unwrapJMException(e);
-            if (cause instanceof Error) {
+            if (cause instanceof InstanceNotFoundException) {
+                throw new GBeanNotFoundException(objectName.getCanonicalName());
+            } else if (cause instanceof NoSuchMethodException) {
+                throw new NoSuchOperationException(cause.getMessage());
+            } else if (cause instanceof Error) {
                 throw (Error) cause;
             } else if (cause instanceof Exception) {
                 throw (Exception) cause;
@@ -372,7 +387,7 @@
 
     public void loadGBean(GBeanData gbeanData, ClassLoader classLoader) throws InstanceAlreadyExistsException, InvalidConfigException {
         try {
-            GBeanMBean gbean = new GBeanMBean(gbeanData, classLoader);
+            GBeanMBean gbean = new GBeanMBean(this, gbeanData, classLoader);
             mbServer.registerMBean(gbean, gbeanData.getName());
         } catch (JMRuntimeException e) {
             throw new InvalidConfigException("Invalid GBean configuration for " + gbeanData.getName(), unwrapJMException(e));
@@ -521,11 +536,20 @@
         lifecycleMonitor = new LifecycleMonitor(mbServer);
         proxyManager = new ProxyManager(this);
 
-        configurationManagerGBean = new GBeanMBean(ConfigurationManagerImpl.GBEAN_INFO);
-        configurationManagerGBean.setReferencePatterns("Stores", Collections.singleton(CONFIGURATION_STORE_PATTERN));
+        // set up the data for the new configuration manager instance
+        GBeanData configurationData = new GBeanData(CONFIGURATION_MANAGER_NAME, ConfigurationManagerImpl.GBEAN_INFO);
+        configurationData.setReferencePatterns("Stores", Collections.singleton(CONFIGURATION_STORE_PATTERN));
+
+        // create the connfiguration manager instance
+        JMXLifecycleBroadcaster lifecycleBroadcaster = new JMXLifecycleBroadcaster();
+        configurationManagerInstance = new GBeanInstance(this, configurationData, lifecycleBroadcaster, getClass().getClassLoader());
+        configurationManagerInstance.start();
+        configurationManager = (ConfigurationManager) configurationManagerInstance.getTarget();
+
+        // wrap it in an mbean and register it
+        GBeanMBean configurationManagerGBean = new GBeanMBean(this, configurationManagerInstance, lifecycleBroadcaster);
         mbServer.registerMBean(configurationManagerGBean, CONFIGURATION_MANAGER_NAME);
-        configurationManagerGBean.start();
-        configurationManager = (ConfigurationManager) configurationManagerGBean.getTarget();
+
         running = true;
         log.info("Booted");
     }
@@ -599,21 +623,19 @@
 
     private void shutdownConfigManager() {
         configurationManager = null;
-        try {
-            if (configurationManagerGBean != null) {
-                configurationManagerGBean.stop();
+        if (configurationManagerInstance != null) {
+            try {
+                configurationManagerInstance.stop();
+            } catch (Exception e) {
+                // ignore
             }
-        } catch (Exception e) {
-            // ignore
-        }
-        try {
-            if (configurationManagerGBean != null) {
+            try {
                 mbServer.unregisterMBean(CONFIGURATION_MANAGER_NAME);
+            } catch (Exception e) {
+                // ignore
             }
-        } catch (Exception e) {
-            // ignore
+            configurationManagerInstance = null;
         }
-        configurationManagerGBean = null;
     }
 
     public boolean isRunning() {

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class KernelException extends Exception {
+    public KernelException() {
+    }
+
+    public KernelException(String message) {
+        super(message);
+    }
+
+    public KernelException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public KernelException(Throwable cause) {
+        super(cause);
+    }
+}

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleAdapter.java	Thu Nov 25 13:40:42 2004
@@ -22,7 +22,7 @@
  * @version $Rev$ $Date$
  */
 public class LifecycleAdapter implements LifecycleListener {
-    public void created(ObjectName objectName) {
+    public void loaded(ObjectName objectName) {
     }
 
     public void starting(ObjectName objectName) {
@@ -37,6 +37,9 @@
     public void stopped(ObjectName objectName) {
     }
 
-    public void deleted(ObjectName objectName) {
+    public void failed(ObjectName objectName) {
+    }
+
+    public void unloaded(ObjectName objectName) {
     }
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleListener.java	Thu Nov 25 13:40:42 2004
@@ -23,10 +23,11 @@
  * @version $Rev$ $Date$
  */
 public interface LifecycleListener extends EventListener {
-    public void created(ObjectName objectName);
+    public void loaded(ObjectName objectName);
     public void starting(ObjectName objectName);
     public void running(ObjectName objectName);
     public void stopping(ObjectName objectName);
     public void stopped(ObjectName objectName);
-    public void deleted(ObjectName objectName);
+    public void failed(ObjectName objectName);
+    public void unloaded(ObjectName objectName);
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java	Thu Nov 25 13:40:42 2004
@@ -135,6 +135,10 @@
         boundListeners.remove(source);
     }
 
+    public synchronized void addLifecycleListener(LifecycleListener listener, ObjectName pattern) {
+        addLifecycleListener(listener, Collections.singleton(pattern));
+    }
+
     public synchronized void addLifecycleListener(LifecycleListener listener, Set patterns) {
         for (Iterator patternIterator = patterns.iterator(); patternIterator.hasNext();) {
             ObjectName pattern = (ObjectName) patternIterator.next();
@@ -168,12 +172,12 @@
         }
     }
 
-    private void fireCreatedEvent(ObjectName objectName) {
+    private void fireLoadedEvent(ObjectName objectName) {
         Set targets = getTargets(objectName);
         for (Iterator iterator = targets.iterator(); iterator.hasNext();) {
             LifecycleListener listener = (LifecycleListener) iterator.next();
             try {
-                listener.created(objectName);
+                listener.loaded(objectName);
             } catch (Throwable e) {
                 log.warn("Exception occured while notifying listener", e);
             }
@@ -228,12 +232,24 @@
         }
     }
 
-    private void fireDeleteEvent(ObjectName source) {
+    private void fireFailedEvent(ObjectName source) {
         Set targets = getTargets(source);
         for (Iterator iterator = targets.iterator(); iterator.hasNext();) {
             LifecycleListener listener = (LifecycleListener) iterator.next();
             try {
-                listener.deleted(source);
+                listener.failed(source);
+            } catch (Throwable e) {
+                log.warn("Exception occured while notifying listener", e);
+            }
+        }
+    }
+
+    private void fireUnloadedEvent(ObjectName source) {
+        Set targets = getTargets(source);
+        for (Iterator iterator = targets.iterator(); iterator.hasNext();) {
+            LifecycleListener listener = (LifecycleListener) iterator.next();
+            try {
+                listener.unloaded(source);
             } catch (Throwable e) {
                 log.warn("Exception occured while notifying listener", e);
             }
@@ -245,22 +261,25 @@
 
         if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type)) {
             ObjectName source = ((MBeanServerNotification) notification).getMBeanName();
-            addSource(source);
+            if (!boundListeners.containsKey(source)) {
+                // register for state change notifications
+                try {
+                    server.addNotificationListener(source, this, NotificationType.STATE_CHANGE_FILTER, null);
+                } catch (InstanceNotFoundException e) {
+                    // the instance died before we could get going... not a big deal
+                    return;
+                }
 
-            // register for state change notifications
-            try {
-                server.addNotificationListener(source, this, NotificationType.STATE_CHANGE_FILTER, null);
-            } catch (InstanceNotFoundException e) {
-                // the instance died before we could get going... not a big deal
-                return;
+                addSource(source);
+                fireLoadedEvent(source);
             }
         } else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type)) {
-            removeSource(((MBeanServerNotification) notification).getMBeanName());
+            ObjectName source = ((MBeanServerNotification) notification).getMBeanName();
+            fireUnloadedEvent(source);
+            removeSource(source);
         } else {
             final ObjectName source = (ObjectName) notification.getSource();
-            if (NotificationType.OBJECT_CREATED.equals(type)) {
-                fireCreatedEvent(source);
-            } else if (NotificationType.STATE_STARTING.equals(type)) {
+            if (NotificationType.STATE_STARTING.equals(type)) {
                 fireStartingEvent(source);
             } else if (NotificationType.STATE_RUNNING.equals(type)) {
                 fireRunningEvent(source);
@@ -268,8 +287,8 @@
                 fireStoppingEvent(source);
             } else if (NotificationType.STATE_STOPPED.equals(type)) {
                 fireStoppedEvent(source);
-            } else if (NotificationType.OBJECT_DELETED.equals(type)) {
-                fireDeleteEvent(source);
+            } else if (NotificationType.STATE_FAILED.equals(type)) {
+                fireFailedEvent(source);
             }
         }
     }

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchAttributeException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchAttributeException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchAttributeException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoSuchAttributeException extends KernelException {
+    public NoSuchAttributeException() {
+    }
+
+    public NoSuchAttributeException(String message) {
+        super(message);
+    }
+
+    public NoSuchAttributeException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoSuchAttributeException(Throwable cause) {
+        super(cause);
+    }
+}

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchOperationException.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchOperationException.java?view=auto&rev=106610
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/NoSuchOperationException.java	Thu Nov 25 13:40:42 2004
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoSuchOperationException extends KernelException {
+    public NoSuchOperationException() {
+    }
+
+    public NoSuchOperationException(String message) {
+        super(message);
+    }
+
+    public NoSuchOperationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoSuchOperationException(Throwable cause) {
+        super(cause);
+    }
+}

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java	Thu Nov 25 13:40:42 2004
@@ -30,25 +30,24 @@
 import java.net.URLClassLoader;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Collections;
-import javax.management.AttributeNotFoundException;
 import javax.management.JMRuntimeException;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
 import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.jmx.JMXUtil;
@@ -108,9 +107,9 @@
     private final ConfigurationStore configurationStore;
 
     private URL baseURL;
-    private Map gbeans;
+    private Set objectNames;
 
-    private ClassLoader classLoader;
+    private ClassLoader configurationClassLoader;
 
     /**
      * Constructor that can be used to create an offline Configuration, typically
@@ -177,34 +176,34 @@
             // no explicit parent set, so use the class loader of this class as
             // the parent... this class should be in the root geronimo classloader,
             // which is normally the system class loader but not always, so be safe
-            classLoader = new URLClassLoader(urls, getClass().getClassLoader());
+            configurationClassLoader = new URLClassLoader(urls, getClass().getClassLoader());
         } else {
-            classLoader = new URLClassLoader(urls, parent.getClassLoader());
+            configurationClassLoader = new URLClassLoader(urls, parent.getConfigurationClassLoader());
         }
 
         // DSS: why exactally are we doing this?  I bet there is a reason, but
         // we should state why here.
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         try {
-            Thread.currentThread().setContextClassLoader(classLoader);
+            Thread.currentThread().setContextClassLoader(configurationClassLoader);
 
             // create and initialize GBeans
-            gbeans = loadGBeans(gbeanState, classLoader);
+            Collection gbeans = loadGBeans(gbeanState, configurationClassLoader);
 
             // set configurationBaseUrl attribute on each gbean
-            for (Iterator i = gbeans.values().iterator(); i.hasNext();) {
-                GBeanMBean gbean = (GBeanMBean) i.next();
-                setGBeanBaseUrl(gbean, baseURL);
+            for (Iterator i = gbeans.iterator(); i.hasNext();) {
+                GBeanData gbeanData = (GBeanData) i.next();
+                setGBeanBaseUrl(gbeanData, baseURL);
             }
 
             // register all the GBeans
-            for (Iterator i = gbeans.entrySet().iterator(); i.hasNext();) {
-                Map.Entry entry = (Map.Entry) i.next();
-                ObjectName name = (ObjectName) entry.getKey();
-                GBeanMBean gbean = (GBeanMBean) entry.getValue();
+            Set objectNames = new HashSet();
+            for (Iterator i = gbeans.iterator(); i.hasNext();) {
+                GBeanData gbeanData = (GBeanData) i.next();
+                ObjectName name = gbeanData.getName();
                 log.trace("Registering GBean " + name);
                 try {
-                    kernel.loadGBean(name, gbean);
+                    kernel.loadGBean(gbeanData, configurationClassLoader);
                 } catch (JMRuntimeException e) {
                     Throwable cause = e.getCause();
                     if (cause instanceof Exception) {
@@ -214,8 +213,10 @@
                     }
                     throw e;
                 }
+                objectNames.add(name);
                 kernel.getDependencyManager().addDependency(name, objectName);
             }
+            this.objectNames = objectNames;
         } finally {
             Thread.currentThread().setContextClassLoader(oldCl);
         }
@@ -227,13 +228,13 @@
         return objectNameString;
     }
 
-    private static void setGBeanBaseUrl(GBeanMBean gbean, URL baseUrl) throws ReflectionException, AttributeNotFoundException {
-        GBeanInfo gbeanInfo = gbean.getGBeanInfo();
+    private static void setGBeanBaseUrl(GBeanData gbeanData, URL baseUrl) {
+        GBeanInfo gbeanInfo = gbeanData.getGBeanInfo();
         Set attributes = gbeanInfo.getAttributes();
         for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
             GAttributeInfo attribute = (GAttributeInfo) iterator.next();
             if (attribute.getName().equals("configurationBaseUrl") && attribute.getType().equals("java.net.URL")) {
-                gbean.setAttribute("configurationBaseUrl", baseUrl);
+                gbeanData.setAttribute("configurationBaseUrl", baseUrl);
                 return;
             }
         }
@@ -241,12 +242,19 @@
 
     public void doStop() throws Exception {
         log.info("Stopping configuration " + id);
-        if (gbeans == null) {
+        if (objectNames == null) {
             return;
         }
 
+        // save state
+        try {
+            gbeanState = storeGBeans(kernel, objectNames);
+        } catch (InvalidConfigException e) {
+            log.info(e);
+        }
+
         // unregister all GBeans
-        for (Iterator i = gbeans.keySet().iterator(); i.hasNext();) {
+        for (Iterator i = objectNames.iterator(); i.hasNext();) {
             ObjectName name = (ObjectName) i.next();
             kernel.getDependencyManager().removeDependency(name, objectName);
             try {
@@ -258,18 +266,11 @@
             }
         }
 
-        // save state
-        try {
-            gbeanState = storeGBeans(gbeans);
-        } catch (InvalidConfigException e) {
-            log.info(e);
-        }
-
         if (configurationStore != null) {
             configurationStore.updateConfiguration(this);
         }
 
-        gbeans = null;
+        objectNames = null;
     }
 
     public void doFail() {
@@ -324,8 +325,8 @@
         return gbeanState;
     }
 
-    public ClassLoader getClassLoader() {
-        return classLoader;
+    public ClassLoader getConfigurationClassLoader() {
+        return configurationClassLoader;
     }
 
     private static class ConfigInputStream extends ObjectInputStream {
@@ -354,7 +355,7 @@
      * @return a Map<ObjectName, GBeanMBean> of GBeans loaded from the persisted state
      * @throws InvalidConfigException if there is a problem deserializing the state
      */
-    private static Map loadGBeans(byte[] gbeanState, ClassLoader cl) throws InvalidConfigException {
+    private static Collection loadGBeans(byte[] gbeanState, ClassLoader cl) throws InvalidConfigException {
         Map gbeans = new HashMap();
         try {
             ObjectInputStream ois = new ConfigInputStream(new ByteArrayInputStream(gbeanState), cl);
@@ -362,16 +363,16 @@
                 while (true) {
                     GBeanData gbeanData = new GBeanData();
                     gbeanData.readExternal(ois);
-                    GBeanMBean gbean = new GBeanMBean(gbeanData, cl);
 
-                    gbeans.put(gbeanData.getName(), gbean);
+                    gbeans.put(gbeanData.getName(), gbeanData);
                 }
             } catch (EOFException e) {
                 // ok
             } finally {
                 ois.close();
             }
-            return gbeans;
+            // avoid duplicate object names
+            return gbeans.values();
         } catch (Exception e) {
             throw new InvalidConfigException("Unable to deserialize GBeanState", e);
         }
@@ -415,6 +416,39 @@
         return baos.toByteArray();
     }
 
+    /**
+     * Return a byte array containing the persisted form of the supplied GBeans
+     *
+     * @param objectNames object names of gbeans to store
+     * @return the persisted GBeans
+     * @throws org.apache.geronimo.kernel.config.InvalidConfigException
+     *          if there is a problem serializing the state
+     */
+    private static byte[] storeGBeans(Kernel kernel, Set objectNames) throws InvalidConfigException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos;
+        try {
+            oos = new ObjectOutputStream(baos);
+        } catch (IOException e) {
+            throw (AssertionError) new AssertionError("Unable to initialize ObjectOutputStream").initCause(e);
+        }
+        for (Iterator i = objectNames.iterator(); i.hasNext();) {
+            ObjectName objectName = (ObjectName) i.next();
+            try {
+                GBeanData gbeanData = kernel.getGBeanData(objectName);
+                gbeanData.writeExternal(oos);
+            } catch (Exception e) {
+                throw new InvalidConfigException("Unable to serialize GBeanState for " + objectName, e);
+            }
+        }
+        try {
+            oos.flush();
+        } catch (IOException e) {
+            throw (AssertionError) new AssertionError("Unable to flush ObjectOutputStream").initCause(e);
+        }
+        return baos.toByteArray();
+    }
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {
@@ -428,7 +462,7 @@
         infoFactory.addAttribute("dependencies", List.class, true);
         infoFactory.addAttribute("gBeanState", byte[].class, true);
         infoFactory.addAttribute("baseURL", URL.class, true);
-        infoFactory.addAttribute("classLoader", ClassLoader.class, false);
+        infoFactory.addAttribute("configurationClassLoader", ClassLoader.class, false);
 
         infoFactory.addReference("Parent", ConfigurationParent.class);
         infoFactory.addReference("Repositories", Repository.class);

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java	Thu Nov 25 13:40:42 2004
@@ -23,5 +23,5 @@
  * @version $Rev$ $Date$
  */
 public interface ConfigurationParent {
-    ClassLoader getClassLoader();
+    ClassLoader getConfigurationClassLoader();
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyMethodInterceptor.java	Thu Nov 25 13:40:42 2004
@@ -32,7 +32,8 @@
 import net.sf.cglib.reflect.FastClass;
 import org.apache.geronimo.gbean.GOperationSignature;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
-import org.apache.geronimo.gbean.jmx.RawInvoker;
+import org.apache.geronimo.gbean.runtime.RawInvoker;
+import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.kernel.Kernel;
 import org.objectweb.asm.Type;
 
@@ -94,7 +95,7 @@
     private ProxyInvoker[] createGBeanInvokers(Kernel kernel, ObjectName objectName) {
         ProxyInvoker[] invokers;
         try {
-            RawInvoker rawInvoker = (RawInvoker) kernel.getAttribute(objectName, GBeanMBean.RAW_INVOKER);
+            RawInvoker rawInvoker = (RawInvoker) kernel.getAttribute(objectName, GBeanInstance.RAW_INVOKER);
             invokers = createRawGBeanInvokers(rawInvoker, proxyType);
         } catch (Exception e) {
             invokers = createKernelGBeanInvokers(kernel, objectName, proxyType);

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawGetAttributeInvoker.java	Thu Nov 25 13:40:42 2004
@@ -18,7 +18,7 @@
 
 import javax.management.ObjectName;
 
-import org.apache.geronimo.gbean.jmx.RawInvoker;
+import org.apache.geronimo.gbean.runtime.RawInvoker;
 
 /**
  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawOperationInvoker.java	Thu Nov 25 13:40:42 2004
@@ -18,7 +18,7 @@
 
 import javax.management.ObjectName;
 
-import org.apache.geronimo.gbean.jmx.RawInvoker;
+import org.apache.geronimo.gbean.runtime.RawInvoker;
 
 /**
  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/RawSetAttributeInvoker.java	Thu Nov 25 13:40:42 2004
@@ -18,7 +18,7 @@
 
 import javax.management.ObjectName;
 
-import org.apache.geronimo.gbean.jmx.RawInvoker;
+import org.apache.geronimo.gbean.runtime.RawInvoker;
 
 /**
  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java	(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/Speed.java	Thu Nov 25 13:40:42 2004
@@ -26,7 +26,7 @@
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.MockGBean;
-import org.apache.geronimo.gbean.jmx.RawInvoker;
+import org.apache.geronimo.gbean.runtime.RawInvoker;
 
 /**
  * @version $Rev$ $Date$

Deleted: /geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java?view=auto&rev=106609
==============================================================================

Copied: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java (from r106386, geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java)
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java&r1=106386&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java	(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java	Thu Nov 25 13:40:42 2004
@@ -14,46 +14,38 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.geronimo.gbean.jmx;
+package org.apache.geronimo.gbean.runtime;
 
-import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import junit.framework.TestCase;
 import org.apache.geronimo.gbean.DynamicGAttributeInfo;
 import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.LifecycleAdapter;
 import org.apache.geronimo.kernel.MockDynamicGBean;
 import org.apache.geronimo.kernel.MockGBean;
 
 /**
  * @version $Rev$ $Date$
  */
-public class GBeanMBeanAttributeTest extends TestCase {
+public class GBeanAttributeTest extends TestCase {
 
     private static final String attributeName = "Name";
 
     private static final String persistentPrimitiveAttributeName = "MutableInt";
 
-    private static ObjectName name;
-
-    static {
-        try {
-            name = new ObjectName("test:name=MyMockGBean");
-        } catch (MalformedObjectNameException ignored) {
-        }
-    }
-
     /**
      * Wraps GBean
      */
-    private GBeanMBean gmbean = null;
+    private GBeanInstance gbeanInstance = null;
 
     /**
      * Wraps DynamicGBean
      */
-    private GBeanMBean dynamicGmbean = null;
+    private GBeanInstance dynamicGBeanInstance = null;
 
     private MethodInvoker getInvoker = null;
 
@@ -61,33 +53,34 @@
 
     private GAttributeInfo persistentPrimitiveAttributeInfo = null;
     private GAttributeInfo attributeInfo = null;
+    private Kernel kernel;
 //    private GAttributeInfo throwingExceptionAttributeInfo = null;
 
     public final void testGBeanMBeanAttributeGBeanMBeanStringClassMethodInvokerMethodInvoker() {
         try {
-            GBeanMBeanAttribute.createFrameworkAttribute((GBeanMBean) null, null, null, null);
+            GBeanAttribute.createFrameworkAttribute(null, null, null, null);
             fail("IllegalArgumentException expected");
         } catch (IllegalArgumentException expected) {
         }
 //        try {
-//            GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, null);
+//            GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, null);
 //            fail("InvalidConfigurationException expected");
 //        } catch (InvalidConfigurationException expected) {
 //        }
-        GBeanMBeanAttribute attribute;
-        attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, getInvoker);
+        GBeanAttribute attribute;
+        attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, getInvoker);
         assertEquals(String.class, attribute.getType());
         assertEquals(attributeName, attribute.getName());
         assertTrue(attribute.isReadable());
         assertFalse(attribute.isWritable());
         assertFalse(attribute.isPersistent());
-        attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, null, setInvoker, false, null);
+        attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, null, setInvoker, false, null);
         assertEquals(String.class, attribute.getType());
         assertEquals(attributeName, attribute.getName());
         assertFalse(attribute.isReadable());
         assertTrue(attribute.isWritable());
         assertFalse(attribute.isPersistent());
-        attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, getInvoker, setInvoker, false, null);
+        attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, getInvoker, setInvoker, false, null);
         assertEquals(String.class, attribute.getType());
         assertEquals(attributeName, attribute.getName());
         assertTrue(attribute.isReadable());
@@ -95,18 +88,18 @@
         assertFalse(attribute.isPersistent());
     }
 
-    public final void testGBeanMBeanAttributeGBeanMBeanGAttributeInfoClass() {
+    public final void testGBeanAttributeInfoClass() {
         try {
-            new GBeanMBeanAttribute(null, null, false);
+            new GBeanAttribute(null, null, false);
             fail("IllegalArgumentException expected");
         } catch (IllegalArgumentException expected) {
         }
 
         // 2. @todo BUG An attribute must be readable, writable, or persistent
-        // GBeanMBeanAttribute ctor doesn't check if readable/writable are
+        // GBeanAttribute ctor doesn't check if readable/writable are
         // null's
         try {
-            new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+            new GBeanAttribute(gbeanInstance, attributeInfo, false);
             // till Dain sorts out the question of ctor
             // fail("InvalidConfigurationException expected");
         } catch (InvalidConfigurationException expected) {
@@ -115,21 +108,21 @@
         try {
             GAttributeInfo invalidAttributeInfo = new GAttributeInfo(attributeName, String.class.getName(), false, null, null);
 
-            new GBeanMBeanAttribute(gmbean, invalidAttributeInfo, false);
+            new GBeanAttribute(gbeanInstance, invalidAttributeInfo, false);
             fail("InvalidConfigurationException expected");
         } catch (InvalidConfigurationException expected) {
         }
 
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo(attributeName, String.class.getName(), false, Boolean.TRUE, Boolean.FALSE, null, null);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, attributeInfo, false);
             assertTrue(attribute.isReadable());
             assertFalse(attribute.isWritable());
         }
 
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo(persistentPrimitiveAttributeName, int.class.getName(), false, Boolean.FALSE, Boolean.TRUE, null, null);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, attributeInfo, false);
             assertFalse(attribute.isReadable());
             assertTrue(attribute.isWritable());
         }
@@ -137,7 +130,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("AnotherFinalInt", int.class.getName(), false, Boolean.TRUE, Boolean.TRUE, null, null);
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Getter and setter methods do not have the same types; InvalidConfigurationException expected");
             } catch (InvalidConfigurationException expected) {
             }
@@ -148,14 +141,14 @@
             // exist.
             // getYetAnotherFinalInt doesn't exist
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, "getFinalInt", null);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, attributeInfo, false);
             assertNotNull(attribute);
         }
 
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setCharAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -164,7 +157,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setBooleanAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -173,7 +166,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setByteAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -182,7 +175,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setShortAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -191,7 +184,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setLongAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -200,7 +193,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setFloatAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -209,7 +202,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setDoubleAsYetAnotherFinalInt");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Expected InvalidConfigurationException due to invalid setter parameter type");
             } catch (InvalidConfigurationException expected) {
             }
@@ -218,7 +211,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, "getVoidGetterOfFinalInt", null);
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Getter method not found on target; InvalidConfigurationException expected");
             } catch (InvalidConfigurationException expected) {
             }
@@ -227,7 +220,7 @@
         {
             final GAttributeInfo attributeInfo = new GAttributeInfo("YetAnotherFinalInt", int.class.getName(), true, null, "setThatDoesntExist");
             try {
-                new GBeanMBeanAttribute(gmbean, attributeInfo, false);
+                new GBeanAttribute(gbeanInstance, attributeInfo, false);
                 fail("Setter method not found on target; InvalidConfigurationException expected");
             } catch (InvalidConfigurationException expected) {
             }
@@ -235,7 +228,7 @@
 
         {
             final DynamicGAttributeInfo dynamicAttributeInfo = new DynamicGAttributeInfo(attributeName);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, dynamicAttributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, dynamicAttributeInfo, false);
             assertFalse(attribute.isPersistent());
             assertEquals(dynamicAttributeInfo.isPersistent(), attribute.isPersistent());
             assertTrue(attribute.isReadable());
@@ -247,7 +240,7 @@
 
         {
             final DynamicGAttributeInfo dynamicAttributeInfo = new DynamicGAttributeInfo(attributeName, true);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, dynamicAttributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, dynamicAttributeInfo, false);
             assertTrue(attribute.isPersistent());
             assertEquals(dynamicAttributeInfo.isPersistent(), attribute.isPersistent());
             assertTrue(attribute.isReadable());
@@ -260,7 +253,7 @@
         {
             final DynamicGAttributeInfo dynamicAttributeInfo = new DynamicGAttributeInfo(attributeName, true, false,
                     true);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, dynamicAttributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, dynamicAttributeInfo, false);
             assertTrue(attribute.isPersistent());
             assertEquals(dynamicAttributeInfo.isPersistent(), attribute.isPersistent());
             assertFalse(attribute.isReadable());
@@ -273,7 +266,7 @@
         {
             final DynamicGAttributeInfo dynamicAttributeInfo = new DynamicGAttributeInfo(attributeName, true, false,
                     false);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, dynamicAttributeInfo, false);
+            GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, dynamicAttributeInfo, false);
             assertTrue(attribute.isPersistent());
             assertEquals(dynamicAttributeInfo.isPersistent(), attribute.isPersistent());
             assertFalse(attribute.isReadable());
@@ -290,18 +283,18 @@
 //        {
 //            final Integer valueThatCausesException = new Integer(-1);
 //
-//            final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo);
+//            final GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, throwingExceptionAttributeInfo);
 //            attribute.setValue(valueThatCausesException);
 //
 //            final Kernel kernel = new Kernel("test.kernel");
 //            try {
 //                kernel.boot();
-//                kernel.loadGBean(name, gmbean);
+//                kernel.loadGBean(name, gbeanInstance);
 //                attribute.start();
 //                fail("Setter upon call with " + valueThatCausesException + " should have thrown exception");
 //            } catch (/* IllegalArgument */Exception expected) {
 //            } finally {
-//                // @todo possible BUG: gmbean holds information on being online
+//                // @todo possible BUG: gbeanInstance holds information on being online
 //                // although kernel is shutdown
 //                // explicit unloading GBean
 //                kernel.unloadGBean(name);
@@ -313,13 +306,13 @@
 //        {
 //            final Integer valueThatCausesError = new Integer(-2);
 //
-//            final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo);
+//            final GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, throwingExceptionAttributeInfo);
 //            attribute.setValue(valueThatCausesError);
 //
 //            final Kernel kernel = new Kernel("test.kernel");
 //            try {
 //                kernel.boot();
-//                kernel.loadGBean(name, gmbean);
+//                kernel.loadGBean(name, gbeanInstance);
 //                attribute.start();
 //                fail("Setter upon call with " + valueThatCausesError + " should have thrown error");
 //            } catch (Error expected) {
@@ -334,13 +327,13 @@
 //        {
 //            final Integer valueThatCausesThrowable = new Integer(-3);
 //
-//            final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo);
+//            final GBeanAttribute attribute = new GBeanAttribute(gbeanInstance, throwingExceptionAttributeInfo);
 //            attribute.setValue(valueThatCausesThrowable);
 //
 //            final Kernel kernel = new Kernel("test.kernel");
 //            try {
 //                kernel.boot();
-//                kernel.loadGBean(name, gmbean);
+//                kernel.loadGBean(name, gbeanInstance);
 //                attribute.start();
 //                fail("Setter upon call with " + valueThatCausesThrowable + " should have thrown throwable");
 //            } catch (Throwable expected) {
@@ -352,7 +345,7 @@
 //        {
 //            try {
 //                GBeanMBean gmbean2 = new GBeanMBean(MockGBean.getGBeanInfo());
-//                GBeanMBeanAttribute attribute2 = new GBeanMBeanAttribute(gmbean2, throwingExceptionAttributeInfo);
+//                GBeanAttribute attribute2 = new GBeanAttribute(gmbean2, throwingExceptionAttributeInfo);
 //                attribute2.start();
 //                fail("AssertionError or NullPointerException expected");
 //            } catch (Exception expected) {
@@ -368,7 +361,7 @@
     public final void testGetValue() throws Exception {
         {
             // attribute that isn't readable and persistent
-            final GBeanMBeanAttribute attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, null, setInvoker, false, null);
+            final GBeanAttribute attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, null, setInvoker, false, null);
             try {
                 attribute.getValue();
                 fail("Only persistent attributes can be accessed while offline; exception expected");
@@ -377,34 +370,25 @@
         }
 
         {
-            final GBeanMBeanAttribute attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, null, setInvoker, false, null);
-
-            final ObjectName name = new ObjectName("test:name=MyMockGBean");
+            final GBeanAttribute attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, null, setInvoker, false, null);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, gmbean);
-                kernel.startGBean(name);
+                gbeanInstance.start();
 
                 attribute.getValue();
                 fail("This attribute is not readable; exception expected");
             } catch (/* IllegalArgument */Throwable expected) {
             } finally {
-                kernel.shutdown();
+                gbeanInstance.stop();
             }
         }
 
         {
             final DynamicGAttributeInfo dynamicAttributeInfo = new DynamicGAttributeInfo(MockDynamicGBean.MUTABLE_INT_ATTRIBUTE_NAME, true, true, true);
-            GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(dynamicGmbean, dynamicAttributeInfo, false);
-            final ObjectName name = new ObjectName("test:name=MyMockDynamicGBean");
+            GBeanAttribute attribute = new GBeanAttribute(dynamicGBeanInstance, dynamicAttributeInfo, false);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, dynamicGmbean);
-                kernel.startGBean(name);
+                dynamicGBeanInstance.start();
 
                 final Integer zero = new Integer(0);
                 assertEquals(zero, attribute.getValue());
@@ -413,7 +397,7 @@
                 attribute.setValue(one);
                 assertEquals(one, attribute.getValue());
             } finally {
-                kernel.shutdown();
+                dynamicGBeanInstance.stop();
             }
 
         }
@@ -423,7 +407,7 @@
 
         // 1. (offline) attribute that isn't readable and persistent
         {
-            final GBeanMBeanAttribute attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, null, setInvoker, false, null);
+            final GBeanAttribute attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, null, setInvoker, false, null);
             try {
                 attribute.setValue(null);
                 fail("Only persistent attributes can be modified while offline; exception expected");
@@ -434,7 +418,7 @@
         // 2. (offline) attribute that is of primitive type, writable and
         // persistent, but not readable
         {
-            final GBeanMBeanAttribute persistentAttribute = new GBeanMBeanAttribute(gmbean, persistentPrimitiveAttributeInfo, false);
+            final GBeanAttribute persistentAttribute = new GBeanAttribute(gbeanInstance, persistentPrimitiveAttributeInfo, false);
             try {
                 persistentAttribute.setValue(null);
                 fail("Cannot assign null to a primitive attribute; exception expected");
@@ -444,63 +428,54 @@
 
         // 3. (online) attribute that is immutable and not persistent
         {
-            final GBeanMBeanAttribute immutableAttribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean, attributeName, String.class, getInvoker);
+            final GBeanAttribute immutableAttribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName, String.class, getInvoker);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, gmbean);
-                kernel.startGBean(name);
+                gbeanInstance.start();
 
                 immutableAttribute.setValue(null);
                 fail("This attribute is not writable; exception expected");
             } catch (/* IllegalArgument */Exception expected) {
             } finally {
-                kernel.shutdown();
+                gbeanInstance.stop();
             }
         }
 
         // 4. (online) attribute that is mutable and of primitive type
         {
-            final GBeanMBeanAttribute mutablePersistentAttribute = new GBeanMBeanAttribute(gmbean, persistentPrimitiveAttributeInfo, false);
+            final GBeanAttribute mutablePersistentAttribute = new GBeanAttribute(gbeanInstance, persistentPrimitiveAttributeInfo, false);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, gmbean);
-                kernel.startGBean(name);
+                gbeanInstance.start();
 
                 mutablePersistentAttribute.setValue(null);
                 fail("Cannot assign null to a primitive attribute; exception expected");
             } catch (/* IllegalArgument */Exception expected) {
             } finally {
-                kernel.shutdown();
+                gbeanInstance.stop();
             }
         }
 
         // 4a. @todo BUG: It's possible to set a value to a persistent
         // attribute while online; IllegalStateException expected
         {
-            final GBeanMBeanAttribute mutablePersistentAttribute = new GBeanMBeanAttribute(gmbean, persistentPrimitiveAttributeInfo, false);
+            final GBeanAttribute mutablePersistentAttribute = new GBeanAttribute(gbeanInstance, persistentPrimitiveAttributeInfo, false);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, gmbean);
-                kernel.startGBean(name);
+                gbeanInstance.start();
 
                 mutablePersistentAttribute.setValue(new Integer(4));
                 //fail("Cannot assign a value to a persistent attribute while
                 // online; exception expected");
             } catch (/* IllegalState */Exception expected) {
             } finally {
-                kernel.shutdown();
+                gbeanInstance.stop();
             }
         }
 
         // 5. Invoke setValue so that exception is thrown
         {
-            final GBeanMBeanAttribute attribute = GBeanMBeanAttribute.createFrameworkAttribute(gmbean,
+            final GBeanAttribute attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance,
                     attributeName,
                     int.class,
                     null,
@@ -508,24 +483,30 @@
                     false,
                     null);
 
-            final Kernel kernel = new Kernel("test.kernel");
             try {
-                kernel.boot();
-                kernel.loadGBean(name, gmbean);
-                kernel.startGBean(name);
+                gbeanInstance.start();
 
                 attribute.setValue(new Integer(4));
                 fail("Exception expected upon setValue's call");
             } catch (/* IllegalState */Exception expected) {
             } finally {
-                kernel.shutdown();
+                gbeanInstance.stop();
             }
         }
     }
 
     protected void setUp() throws Exception {
-        gmbean = new GBeanMBean(MockGBean.getGBeanInfo());
-        dynamicGmbean = new GBeanMBean(MockDynamicGBean.getGBeanInfo());
+        kernel = new Kernel("test");
+        kernel.boot();
+
+        gbeanInstance = new GBeanInstance(kernel,
+                new GBeanData(new ObjectName("test:MockGBean=normal"), MockGBean.getGBeanInfo()),
+                new LifecycleAdapter(),
+                MockGBean.class.getClassLoader());
+        dynamicGBeanInstance = new GBeanInstance(kernel,
+                new GBeanData(new ObjectName("test:MockGBean=dynamic"), MockDynamicGBean.getGBeanInfo()),
+                new LifecycleAdapter(),
+                MockGBean.class.getClassLoader());
         getInvoker = new MethodInvoker() {
 
             public Object invoke(Object target, Object[] arguments) throws Exception {
@@ -544,6 +525,7 @@
     }
 
     protected void tearDown() throws Exception {
-        gmbean = null;
+        kernel.shutdown();
+        gbeanInstance = null;
     }
 }

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java	(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java	Thu Nov 25 13:40:42 2004
@@ -60,7 +60,7 @@
         mbServer.invoke(configName, "startRecursive", null, null);
 
         assertEquals(new Integer(State.RUNNING_INDEX), mbServer.getAttribute(configName, "state"));
-        assertNotNull(mbServer.getAttribute(configName, "classLoader"));
+        assertNotNull(mbServer.getAttribute(configName, "configurationClassLoader"));
 
         assertEquals(new Integer(State.RUNNING_INDEX), mbServer.getAttribute(gbeanName1, "state"));
         Object state = mbServer.getAttribute(gbeanName2, "state");

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java	(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java	Thu Nov 25 13:40:42 2004
@@ -51,15 +51,15 @@
 
         assertSame(myCl, kernel.getAttribute(name, "actualClassLoader"));
 
-        // the normal classLoader attribute has been changed in the MockGBean implementation to
-        // return ClassLoader.getSystemClassLoader()
-        assertSame(ClassLoader.getSystemClassLoader(), kernel.getAttribute(name, "classLoader"));
+        // the MockGBean implemmentation of getConfigurationClassLoader will throw an exception, but since the GBean architecture
+        // handles this directly the implementation method will never be called
+        kernel.getAttribute(name, "classLoader");
 
         GBeanLifecycleController gbeanLifecycleController = (GBeanLifecycleController) kernel.getAttribute(name, "gbeanLifecycleController");
         assertNotNull(gbeanLifecycleController);
         assertEquals(State.RUNNING_INDEX, gbeanLifecycleController.getState());
 
-        assertNotSame(kernel, kernel.getAttribute(name, "kernel"));
+        assertSame(kernel, kernel.getAttribute(name, "kernel"));
         assertSame(kernel, kernel.getAttribute(name, "actualKernel"));
 
         kernel.stopGBean(name);

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java?view=diff&rev=106610&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java&r1=106609&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java&r2=106610
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java	(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java	Thu Nov 25 13:40:42 2004
@@ -108,7 +108,7 @@
     }
 
     public String getObjectName() {
-        return "FakePhonyName";
+        throw new RuntimeException("this should never be called");
     }
 
     public ClassLoader getActualClassLoader() {
@@ -116,7 +116,7 @@
     }
 
     public ClassLoader getClassLoader() {
-        return ClassLoader.getSystemClassLoader();
+        throw new RuntimeException("this should never be called");
     }
 
     public GBeanLifecycleController getGBeanLifecycleController() {
@@ -128,7 +128,7 @@
     }
 
     public Kernel getKernel() {
-        return new Kernel("blah424242");
+        throw new RuntimeException("this should never be called");
     }
 
     public void setKernel(Kernel kernel) {

Mime
View raw message