geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config Configuration.java ConfigurationParent.java ConfigurationStore.java InvalidConfigException.java LocalConfigStore.java NoSuchConfigException.java
Date Mon, 12 Jan 2004 01:39:46 GMT
jboynes     2004/01/11 17:39:46

  Added:       modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java KernelMBean.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        Configuration.java ConfigurationParent.java
                        ConfigurationStore.java InvalidConfigException.java
                        LocalConfigStore.java NoSuchConfigException.java
  Log:
  Initial checkin of config code
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
  
  Index: Kernel.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.URI;
  import java.net.URL;
  import java.net.URISyntaxException;
  import javax.management.InstanceNotFoundException;
  import javax.management.MBeanRegistrationException;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.config.ConfigurationStore;
  import org.apache.geronimo.kernel.config.InvalidConfigException;
  import org.apache.geronimo.kernel.config.NoSuchConfigException;
  import org.apache.geronimo.kernel.config.LocalConfigStore;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  import org.apache.geronimo.kernel.service.DependencyService2;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.jmx.GMBean;
  import org.apache.commons.logging.impl.LogFactoryImpl;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * The core of a Geronimo instance.
   * A Kernel is responsible for managing the Configurations that comprise a
   * Geronimo system and exposing them using JMX. Each Kernel is associated
   * with an MBeanServer that is used to register the Configurations themselves
   * and the MBeans they define.
   *
   * Dependencies between MBeans are handled by a dedicated DependencyService
   * that is responsible for tracking those dependencies and ensuring that the
   * dependent objects follow the appropriate lifecycle and receive appropriate
   * notifications.
   *
   * The Kernel also provides a ConfigurationStore which is used to stage
   * installed Configurations (providing a local filesystem based classpath) and
   * used hold the persistent state of each Configuration. This allows
   * Configurations to restart in he event of system failure.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public class Kernel implements Serializable, KernelMBean {
      /**
       * The JMX name used by a Kernel to register itself when it boots.
       */
      public static final ObjectName KERNEL = JMXUtil.getObjectName("geronimo.boot:role=Kernel");
  
      /**
       * The JMX name of the DependencyService.
       */
      public static final ObjectName DEPENDENCY_SERVICE = JMXUtil.getObjectName("geronimo.boot:role=DependencyService2");
  
      /**
       * The JMX name of the ConfigurationStore.
       */
      public static final ObjectName CONFIG_STORE = JMXUtil.getObjectName("geronimo.boot:role=ConfigurationStore");
  
      private final String domainName;
      private final GBeanInfo storeInfo;
      private final File configStore;
  
      private transient Log log;
      private transient boolean running;
      private transient MBeanServer mbServer;
      private transient GMBean storeGBean;
      private transient ConfigurationStore store;
  
      /**
       * Construct a Kernel using the specified JMX domain and supply the
       * information needed to create the ConfigurationStore.
       * @param domainName the domain name to be used for the JMX MBeanServer
       * @param storeInfo the info for the GMBean to be used for the ConfigurationStore
       * @param configStore a local directory to be used by the ConfigurationStore;
       *                    this must be present and writable when the kernel is booted
       */
      public Kernel(String domainName, GBeanInfo storeInfo, File configStore) {
          this.domainName = domainName;
          this.storeInfo = storeInfo;
          this.configStore = configStore;
      }
  
      /**
       * Get the MBeanServer used by this kernel
       * @return the MBeanServer used by this kernel
       */
      public MBeanServer getMBeanServer() {
          return mbServer;
      }
  
      /**
       * Load the specified Configuration from the store into this Kernel
       * @param configID the unique id of the Configuration to load
       * @return the JMX ObjectName the Kernel registered the Configuration under
       * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if the store does not contain the specified Configuratoin
       * @throws java.io.IOException if the Configuration could not be read from the store
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is not valid
       */
      public ObjectName load(URI configID) throws NoSuchConfigException, IOException, InvalidConfigException {
          if (!running) {
              throw new IllegalStateException("Kernel is not running");
          }
          GMBean config = store.getConfig(configID);
          URL baseURL = store.getBaseURL(configID);
          return load(config, baseURL);
      }
  
      /**
       * Load the supplied Configuration into the Kernel and define its root using the specified URL.
       * @param config the GMBean representing the Configuration
       * @param rootURL the URL to be used to resolve relative paths in the configuration
       * @return the JMX ObjectName the Kernel registered the Configuration under
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is not valid
       */
      public ObjectName load(GMBean config, URL rootURL) throws InvalidConfigException {
          URI configID;
          try {
              configID = (URI) config.getAttribute("ID");
          } catch (Exception e) {
              throw new InvalidConfigException("Cannot get config ID", e);
          }
          ObjectName configName;
          try {
              configName = new ObjectName("geronimo.config:name="+ObjectName.quote(configID.toString()));
          } catch (MalformedObjectNameException e) {
              throw new InvalidConfigException("Cannot convert ID to ObjectName: ", e);
          }
          load(config, rootURL, configName);
          return configName;
      }
  
      /**
       * Load the supplied Configuration into the Kernel and override the default JMX name.
       * This method should be used with discretion as it is possible to create
       * Configurations that cannot be located by management or monitoring tools.
       * @param config the GMBean representing the Configuration
       * @param rootURL the URL to be used to resolve relative paths in the configuration
       * @param configName the JMX ObjectName to register the Configuration under
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is not valid
       */
      public void load(GMBean config, URL rootURL, ObjectName configName) throws InvalidConfigException {
          if (!running) {
              throw new IllegalStateException("Kernel is not running");
          }
          try {
              mbServer.registerMBean(config, configName);
          } catch (Exception e) {
              throw new InvalidConfigException("Unable to register configuraton", e);
          }
  
          try {
              config.setAttribute("BaseURL", rootURL);
          } catch (Exception e) {
              try {
                  mbServer.unregisterMBean(configName);
              } catch (Exception e1) {
                  // ignore
              }
              throw new InvalidConfigException("Cannot set BaseURL", e);
          }
  
          // @todo replace this with use of the MBeanContext in the Configuration target
          try {
              config.setAttribute("MBeanServer", mbServer);
              config.setAttribute("ObjectName", configName);
          } catch (Exception e) {
              try {
                  mbServer.unregisterMBean(configName);
              } catch (Exception e1) {
                  // ignore
              }
              throw new InvalidConfigException("Cannot set MBeanServer info", e);
          }
          log.info("Loaded Configuration "+configName);
      }
  
      /**
       * Unload the specified Configuration from the Kernel
       * @param configName the JMX name of the Configuration that should be unloaded
       * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if the specified Configuration is not loaded
       */
      public void unload(ObjectName configName) throws NoSuchConfigException {
          if (!running) {
              throw new IllegalStateException("Kernel is not running");
          }
          try {
              mbServer.unregisterMBean(configName);
          } catch (InstanceNotFoundException e) {
              throw new NoSuchConfigException("No config registered: "+configName, e);
          } catch (MBeanRegistrationException e) {
              throw (IllegalStateException) new IllegalStateException("Error deregistering configuration "+configName).initCause(e);
          }
          log.info("Unloaded Configuration "+configName);
      }
  
      /**
       * Boot this Kernel, triggering the instanciation of the MBeanServer and
       * the registration of the DependencyService and ConfigurationStore
       * @throws java.lang.Exception if the boot fails
       */
      public void boot() throws Exception {
          if (running) {
              return;
          }
          log = LogFactory.getLog(Kernel.class.getName());
          log.info("Starting boot");
          mbServer = MBeanServerFactory.createMBeanServer(domainName);
          mbServer.registerMBean(this, KERNEL);
          mbServer.registerMBean(new DependencyService2(), DEPENDENCY_SERVICE);
          storeGBean = new GMBean(storeInfo);
          storeGBean.setAttribute("root", configStore);
          mbServer.registerMBean(storeGBean, CONFIG_STORE);
          storeGBean.start();
          store = (ConfigurationStore) storeGBean.getTarget();
          running = true;
          log.info("Booted");
      }
  
      /**
       * Shut down this kernel instance, unregistering the MBeans and releasing
       * the MBeanServer.
       */
      public void shutdown() {
          if (!running) {
              return;
          }
          running = false;
          log.info("Starting kernel shutdown");
  
          store = null;
          try {
              storeGBean.stop();
          } catch (Exception e) {
              // ignore
          }
          try {
              mbServer.unregisterMBean(CONFIG_STORE);
          } catch (Exception e) {
              // ignore
          }
          try {
              mbServer.unregisterMBean(DEPENDENCY_SERVICE);
          } catch (Exception e) {
              // ignore
          }
          try {
              mbServer.unregisterMBean(KERNEL);
          } catch (Exception e) {
              // ignore
          }
          MBeanServerFactory.releaseMBeanServer(mbServer);
          mbServer = null;
          synchronized (this) {
              notify();
          }
          log.info("Kernel shutdown complete");
      }
  
      public boolean isRunning() {
          return running;
      }
  
      /**
       * Static entry point allowing a Kernel to be run from the command line.
       * Arguments are:
       * <li>the filename of the directory to use for the configuration store.
       *     This will be created if it does not exist.</li>
       * <li>the id of a configuation to load</li>
       * Once the Kernel is booted and the configuration is loaded, the process
       * will remain running until the shutdown() method on the kernel is
       * invoked or until the JVM exits.
       * @param args
       */
      public static void main(String[] args) {
          if (args.length < 2) {
              System.err.println("usage: "+Kernel.class.getName()+" <config-store-dir> <config-id>");
              System.exit(1);
          }
          File storeDir = new File(args[0]);
          URI configID = null;
          try {
              configID = new URI(args[1]);
          } catch (URISyntaxException e) {
              e.printStackTrace();
              System.exit(1);
          }
  
          String domain = "geronimo";
          if (storeDir.exists()) {
              if (!storeDir.isDirectory() || !storeDir.canWrite()) {
                  System.err.println("Store location is not a writable directory: "+storeDir);
                  System.exit(1);
              }
          } else {
              if (!storeDir.mkdirs()) {
                  System.err.println("Could not create store directory: "+storeDir);
                  System.exit(1);
              }
          }
  
          final Kernel kernel = new Kernel(domain, LocalConfigStore.GBEAN_INFO, storeDir);
          Runtime.getRuntime().addShutdownHook(new Thread("Shutdown Thread") {
              public void run() {
                  kernel.shutdown();
              }
          });
          try {
              kernel.boot();
          } catch (Exception e) {
              e.printStackTrace();
              System.exit(2);
          }
          try {
              kernel.load(configID);
          } catch (Exception e) {
              kernel.shutdown();
              e.printStackTrace();
              System.exit(2);
          }
          while (kernel.isRunning()) {
              try {
                  synchronized (kernel) {
                      kernel.wait();
                  }
              } catch (InterruptedException e) {
                  // continue
              }
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java
  
  Index: KernelMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel;
  
  import java.io.IOException;
  import java.net.URI;
  import java.net.URL;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.config.InvalidConfigException;
  import org.apache.geronimo.kernel.config.NoSuchConfigException;
  import org.apache.geronimo.gbean.jmx.GMBean;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public interface KernelMBean {
      public MBeanServer getMBeanServer();
  
      public ObjectName load(GMBean config, URL baseURL) throws InvalidConfigException;
  
      public void unload(ObjectName configName) throws NoSuchConfigException;
  
      public ObjectName load(URI configID) throws IOException, NoSuchConfigException, InvalidConfigException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.EOFException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.ObjectStreamClass;
  import java.net.URI;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.ArrayList;
  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.MBeanServer;
  import javax.management.ObjectName;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GConstructorInfo;
  import org.apache.geronimo.gbean.GEndpointInfo;
  import org.apache.geronimo.gbean.GOperationInfo;
  import org.apache.geronimo.gbean.jmx.GMBean;
  import org.apache.geronimo.gbean.jmx.GMBeanTarget;
  
  /**
   * A Configuration represents a collection of runnable services that can be
   * loaded into a Geronimo Kernel and brought online. The primary components in
   * a Configuration are a codebase, represented by a collection of URLs that
   * is used to locate classes, and a collection of GBean instances that define
   * its state.
   *
   * The persistent attributes of the Configuration are:
   * <ul>
   * <li>its unique configID used to identify this specific config</li>
   * <li>the configID of a parent Configuration on which this one is dependent</li>
   * <li>a List<URI> of code locations (which may be absolute or relative to a baseURL)</li>
   * <li>a byte[] holding the state of the GBeans instances in Serialized form</li>
   * </ul>
   * When a configuration is started, it converts the URIs into a set of absolute
   * URLs by resolving them against the specified baseURL (this would typically
   * be the root of the CAR file which contains the configuration) and then
   * constructs a ClassLoader for that codebase. That ClassLoader is then used
   * to de-serialize the persisted GBeans, ensuring the GBeans can be recycled
   * as necessary. Once the GBeans have been restored, they are brought online
   * by registering them with the MBeanServer.
   *
   * A dependency on the Configuration is created for every GBean it loads. As a
   * result, a startRecursive() operation on the configuration will result in
   * a startRecursive() for all the GBeans it contains. Similarly, if the
   * Configuration is stopped then all of its GBeans will be stopped as well.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public class Configuration implements GMBeanTarget {
      private static final Log log = LogFactory.getLog(Configuration.class);
  
      private final URI id;
      private final ConfigurationParent parent;
      private final List classPath;
      private final byte[] gbeanState;
  
      private URL baseURL;
      private Map gbeans;
      private MBeanServer mbServer;
      private ObjectName objectName;
  
      private ClassLoader classLoader;
  
      /**
       * Constructor that can be used to create an offline Configuration, typically
       * only used publically during the deployment process for initial configuration.
       * @param id the unique ID of this Configuration
       * @param parent the parent Configuration; may be null
       * @param classPath a List<URI> of locations that define the codebase for this Configuration
       * @param gbeanState a byte array contain the Java Serialized form of the GBeans in this Configuration
       */
      public Configuration(URI id, ConfigurationParent parent, List classPath, byte[] gbeanState) {
          this.id = id;
          this.parent = parent;
          this.gbeanState = gbeanState;
          this.classPath = classPath;
      }
  
      public void doStart() throws Exception {
          // build classpath
          URL[] urls = new URL[classPath.size()];
          for (int i = 0; i < urls.length; i++) {
              URI path =  (URI) classPath.get(i);
              urls[i] = new URL(baseURL, path.toString());
          }
          if (parent == null) {
              classLoader = new URLClassLoader(urls);
          } else {
              classLoader = new URLClassLoader(urls, parent.getClassLoader());
          }
  
          // create and initialize GBeans
          gbeans = loadGBeans(gbeanState, classLoader);
  
          // register all the GBeans
          for (Iterator i = gbeans.entrySet().iterator(); i.hasNext();) {
              Map.Entry entry = (Map.Entry) i.next();
              ObjectName name = (ObjectName) entry.getKey();
              GMBean gbean = (GMBean) entry.getValue();
              mbServer.registerMBean(gbean, name);
              mbServer.invoke(Kernel.DEPENDENCY_SERVICE, "addDependency", new Object[] { name, objectName}, new String[] {ObjectName.class.getName(), ObjectName.class.getName()});
          }
      }
  
      public void doStop() {
          // unregister all GBeans
          for (Iterator i = gbeans.keySet().iterator(); i.hasNext();) {
              ObjectName name = (ObjectName) i.next();
              try {
                  mbServer.invoke(Kernel.DEPENDENCY_SERVICE, "removeDependency", new Object[] { name, objectName}, new String[] {ObjectName.class.getName(), ObjectName.class.getName()});
              } catch (Exception e) {
                  // ignore
                  log.warn("Could not remove dependency for child "+name, e);
              }
              try {
                  mbServer.unregisterMBean(name);
              } catch (Exception e) {
                  // ignore
                  log.warn("Could not unregister child "+name, e);
              }
          }
  
          // save state
          gbeans = null;
      }
  
      public void doFail() {
      }
  
      /**
       * Return the unique ID
       * @return the unique ID
       */
      public URI getID() {
          return id;
      }
  
      /**
       * Return the URL that is used to resolve relative classpath locations
       * @return the base URL for the classpath
       */
      public URL getBaseURL() {
          return baseURL;
      }
  
      /**
       * Set the URL that should be used to resolve relative class locations
       * @param baseURL the base URL for the classpath
       */
      public void setBaseURL(URL baseURL) {
          this.baseURL = baseURL;
      }
  
      public ClassLoader getClassLoader() {
          return classLoader;
      }
  
      public MBeanServer getMBeanServer() {
          return mbServer;
      }
  
      public void setMBeanServer(MBeanServer mbServer) {
          this.mbServer = mbServer;
      }
  
      public ObjectName getObjectName() {
          return objectName;
      }
  
      public void setObjectName(ObjectName objectName) {
          this.objectName = objectName;
      }
  
      private static class ConfigInputStream extends ObjectInputStream {
          private final ClassLoader cl;
  
          public ConfigInputStream(InputStream in, ClassLoader cl) throws IOException {
              super(in);
              this.cl = cl;
          }
  
          protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
              return cl.loadClass(desc.getName());
          }
      }
  
      /**
       * Load GBeans from the supplied byte array using the supplied ClassLoader
       * @param gbeanState the serialized form of the GBeans
       * @param cl the ClassLoader used to locate classes needed during deserialization
       * @return a Map<ObjectName, GMBean> of GBeans loaded from the persisted state
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem deserializing the state
       */
      public static Map loadGBeans(byte[] gbeanState, ClassLoader cl) throws InvalidConfigException {
          Map gbeans = new HashMap();
          try {
              ObjectInputStream ois = new ConfigInputStream(new ByteArrayInputStream(gbeanState), cl);
              try {
                  while (true) {
                      ObjectName objectName = (ObjectName) ois.readObject();
                      GBeanInfo info = (GBeanInfo) ois.readObject();
                      GMBean gbean = new GMBean(info, cl);
                      for (Iterator iterator = info.getPersistentAttributes().iterator(); iterator.hasNext();) {
                          GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
                          gbean.setAttribute(attributeInfo.getName(), ois.readObject());
                      }
                      gbeans.put(objectName, gbean);
                  }
              } catch (EOFException e) {
                  // ok
              } finally {
                  ois.close();
              }
              return gbeans;
          } catch (Exception e) {
              throw new InvalidConfigException("Unable to deserialize GBeanState", e);
          }
      }
  
      /**
       * Return a byte array containing the persisted form of the supplied GBeans
       * @param gbeans a Map<ObjectName, GMBean> of GBeans to store
       * @return the persisted GBeans
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem serializing the state
       */
      public static byte[] storeGBeans(Map gbeans) throws InvalidConfigException {
          ByteArrayOutputStream baos = null;
          try {
              baos = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(baos);
              for (Iterator i = gbeans.entrySet().iterator(); i.hasNext();) {
                  Map.Entry entry = (Map.Entry) i.next();
                  ObjectName objectName = (ObjectName) entry.getKey();
                  GMBean gbean = (GMBean) entry.getValue();
                  oos.writeObject(objectName);
                  oos.writeObject(gbean.getGBeanInfo());
                  for (Iterator j = gbean.getGBeanInfo().getPersistentAttributes().iterator(); j.hasNext();) {
                      GAttributeInfo attributeInfo = (GAttributeInfo) j.next();
                      oos.writeObject(gbean.getAttribute(attributeInfo.getName()));
                  }
              }
          } catch (Exception e) {
              throw new InvalidConfigException("Unable to serialize GBeanState", e);
          }
          return baos.toByteArray();
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          Set attrs = new HashSet();
          attrs.add(new GAttributeInfo("ID", true));
          attrs.add(new GAttributeInfo("ClassPath", true));
          attrs.add(new GAttributeInfo("GBeanState", true));
          attrs.add(new GAttributeInfo("BaseURL"));
          attrs.add(new GAttributeInfo("MBeanServer"));
          attrs.add(new GAttributeInfo("ObjectName"));
          attrs.add(new GAttributeInfo("ClassLoader"));
          List ctrNames = new ArrayList();
          ctrNames.add("ID");
          ctrNames.add("Parent");
          ctrNames.add("ClassPath");
          ctrNames.add("GBeanState");
          List ctrTypes = new ArrayList();
          ctrTypes.add(URI.class);
          ctrTypes.add(ConfigurationParent.class);
          ctrTypes.add(List.class);
          ctrTypes.add(byte[].class);
          GConstructorInfo ctr = new GConstructorInfo(ctrNames, ctrTypes);
          Set endpoints = new HashSet();
          endpoints.add(new GEndpointInfo("Parent", ConfigurationParent.class.getName()));
          Set operations = Collections.EMPTY_SET;
          GBEAN_INFO = new GBeanInfo(Configuration.class.getName(), attrs, ctr, operations, endpoints, Collections.EMPTY_SET);
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java
  
  Index: ConfigurationParent.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public interface ConfigurationParent {
      ClassLoader getClassLoader();
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java
  
  Index: ConfigurationStore.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.URI;
  import java.net.URL;
  
  import org.apache.geronimo.gbean.jmx.GMBean;
  
  /**
   * Interface to a store for Configurations.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public interface ConfigurationStore {
      /**
       * Add the CAR at the supplied URL into this store
       * @param source the URL of a CAR format archive
       * @throws java.io.IOException if the CAR could not be read
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a configuration problem with the CAR
       */
      void install(URL source) throws IOException, InvalidConfigException;
  
      /**
       * Return the Configuration GBean for the specified ID
       * @param id the unique ID of a Configuration
       * @return the GMBean for that configuration
       * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if the store does not contain a Configuration with that id
       * @throws java.io.IOException if there was a problem loading the Configuration from the store
       * @throws org.apache.geronimo.kernel.config.InvalidConfigException if the Configuration is invalid
       */
      GMBean getConfig(URI id) throws NoSuchConfigException, IOException, InvalidConfigException;
  
      /**
       * Return the base URL for the specified ID
       * @param id the unique ID for a Configuration
       * @return the URL of the base location for the Configuration that should be used for resolution
       * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if the store does not contain a Configuration with that id
       */
      URL getBaseURL(URI id) throws NoSuchConfigException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/InvalidConfigException.java
  
  Index: InvalidConfigException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  /**
   * Indicates a invalid Configuration instance.
   * 
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public class InvalidConfigException extends Exception {
      public InvalidConfigException() {
      }
  
      public InvalidConfigException(Throwable cause) {
          super(cause);
      }
  
      public InvalidConfigException(String message) {
          super(message);
      }
  
      public InvalidConfigException(String message, Throwable cause) {
          super(message, cause);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/LocalConfigStore.java
  
  Index: LocalConfigStore.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  import java.io.BufferedInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.OutputStream;
  import java.net.MalformedURLException;
  import java.net.URI;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Properties;
  import java.util.Set;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipInputStream;
  
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GConstructorInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.gbean.jmx.GMBean;
  import org.apache.geronimo.gbean.jmx.GMBeanTarget;
  import org.apache.geronimo.gbean.WaitingException;
  
  /**
   * Implementation of ConfigurationStore using the local filesystem.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public class LocalConfigStore implements ConfigurationStore, GMBeanTarget {
      private static final String INDEX_NAME = "index.properties";
      private final File root;
      private final Properties index = new Properties();
      private int maxId;
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          Set attrs = new HashSet();
          attrs.add(new GAttributeInfo("root", true));
          List ctrNames = new ArrayList();
          ctrNames.add("root");
          List ctrTypes = new ArrayList();
          ctrTypes.add(File.class);
          GConstructorInfo ctr = new GConstructorInfo(ctrNames, ctrTypes);
          GBEAN_INFO = new GBeanInfo(LocalConfigStore.class.getName(), attrs, ctr, Collections.EMPTY_SET, Collections.EMPTY_SET, Collections.EMPTY_SET);
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
      public LocalConfigStore(File root) {
          this.root = root;
      }
  
      public void doStart() throws WaitingException, FileNotFoundException, IOException {
          if (!root.isDirectory()) {
              throw new FileNotFoundException("Store root does not exist or is not a directory: " + root);
          }
  
          index.clear();
          File indexfile = new File(root, INDEX_NAME);
          try {
              index.load(new BufferedInputStream(new FileInputStream(indexfile)));
              for (Iterator i = index.values().iterator(); i.hasNext();) {
                  String id = (String) i.next();
                  maxId = Math.max(maxId, Integer.parseInt(id));
              }
          } catch (FileNotFoundException e) {
              maxId = 0;
          }
      }
  
      public void doStop() throws WaitingException {
      }
  
      public void doFail() {
      }
  
      private void saveIndex() throws IOException {
          File indexFile = new File(root, INDEX_NAME);
          File tmpFile = File.createTempFile("index", ".tmp", root);
          tmpFile.renameTo(indexFile);
      }
  
      public void install(URL source) throws IOException, InvalidConfigException {
          String newId;
          synchronized (this) {
              newId = Integer.toString(++maxId);
          }
          File bundleRoot = new File(root, newId);
          bundleRoot.mkdir();
          ZipInputStream zis = new ZipInputStream(source.openStream());
          try {
              ZipEntry entry;
              byte[] buffer = new byte[4096];
              while ((entry = zis.getNextEntry()) != null) {
                  File out = new File(bundleRoot, entry.getName());
                  if (entry.isDirectory()) {
                      out.mkdirs();
                  } else {
                      out.getParentFile().mkdirs();
                      OutputStream os = new FileOutputStream(out);
                      try {
                          int count;
                          while ((count = zis.read(buffer)) > 0) {
                              os.write(buffer, 0, count);
                          }
                      } finally {
                          os.close();
                      }
                      zis.closeEntry();
                  }
              }
              try {
                  GMBean config = loadConfig(bundleRoot);
                  index.setProperty(config.getAttribute("ID").toString(), newId);
              } catch (Exception e) {
                  throw new InvalidConfigException("Unable to get ID from downloaded configuration", e);
              }
              synchronized (this) {
                  saveIndex();
              }
          } catch (IOException e) {
              delete(bundleRoot);
              throw e;
          } catch (InvalidConfigException e) {
              delete(bundleRoot);
              throw e;
          } finally {
              zis.close();
          }
      }
  
      public synchronized GMBean getConfig(URI configID) throws NoSuchConfigException, IOException, InvalidConfigException {
          return loadConfig(getRoot(configID));
      }
  
      public URL getBaseURL(URI configID) throws NoSuchConfigException {
          File root = getRoot(configID);
          try {
              return root.toURL();
          } catch (MalformedURLException e) {
              throw new IllegalStateException("Unable to turn config root into URL: " + root);
          }
      }
  
      private synchronized File getRoot(URI configID) throws NoSuchConfigException {
          String id = index.getProperty(configID.toString());
          if (id == null) {
              throw new NoSuchConfigException("No such config: " + configID);
          }
          return new File(root, id);
      }
  
      private GMBean loadConfig(File configRoot) throws IOException, InvalidConfigException {
          FileInputStream fis = new FileInputStream(new File(configRoot, "META-INF/config.ser"));
          try {
              ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
              GBeanInfo gbeanInfo = Configuration.GBEAN_INFO;
              GMBean config;
              try {
                  config = new GMBean(gbeanInfo);
              } catch (InvalidConfigurationException e) {
                  throw new InvalidConfigException("Unable to instanciate Configuration GMBean", e);
              }
              for (Iterator i = gbeanInfo.getPersistentAttributes().iterator(); i.hasNext();) {
                  GAttributeInfo attr = (GAttributeInfo) i.next();
                  try {
                      config.setAttribute(attr.getName(), ois.readObject());
                  } catch (ClassNotFoundException e) {
                      throw new InvalidConfigException("Unable to read attribute " + attr.getName(), e);
                  } catch (Exception e) {
                      throw new InvalidConfigException("Unable to set attribute " + attr.getName(), e);
                  }
              }
              return config;
          } finally {
              fis.close();
          }
      }
  
      private void delete(File root) throws IOException {
          File[] files = root.listFiles();
          for (int i = 0; i < files.length; i++) {
              File file = files[i];
              if (file.isDirectory()) {
                  delete(file);
              } else {
                  file.delete();
              }
          }
          root.delete();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/NoSuchConfigException.java
  
  Index: NoSuchConfigException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.config;
  
  /**
   * Exception indicating the requestion Configuration could not be located.
   * 
   * @version $Revision: 1.1 $ $Date: 2004/01/12 01:39:46 $
   */
  public class NoSuchConfigException extends Exception {
      public NoSuchConfigException() {
      }
  
      public NoSuchConfigException(Throwable cause) {
          super(cause);
      }
  
      public NoSuchConfigException(String message) {
          super(message);
      }
  
      public NoSuchConfigException(String message, Throwable cause) {
          super(message, cause);
      }
  }
  
  
  

Mime
View raw message