geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r381933 - in /geronimo/branches/1.1/modules: deployment/src/java/org/apache/geronimo/deployment/ jetty/src/test/org/apache/geronimo/jetty/ kernel/src/java/org/apache/geronimo/kernel/config/ kernel/src/java/org/apache/geronimo/kernel/reposit...
Date Wed, 01 Mar 2006 06:54:42 GMT
Author: dain
Date: Tue Feb 28 22:54:40 2006
New Revision: 381933

URL: http://svn.apache.org/viewcvs?rev=381933&view=rev
Log:
Interim commit
Some work to convert configuration to a two phase load and start startup.

Added:
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
Modified:
    geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java

Modified: geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java Tue Feb 28 22:54:40 2006
@@ -524,7 +524,7 @@
             }
             Configuration configuration = new Configuration(parents,
                     kernel,
-                    null,
+                    Configuration.getConfigurationObjectName(environmentCopy.getConfigId()).getCanonicalName(),
                     moduleType,
                     environmentCopy,
                     new ArrayList(classpath),

Modified: geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java (original)
+++ geronimo/branches/1.1/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java Tue Feb 28 22:54:40 2006
@@ -17,10 +17,9 @@
 
 package org.apache.geronimo.jetty;
 
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLClassLoader;
 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 import junit.framework.TestCase;
 import org.apache.geronimo.kernel.config.MultiParentClassLoader;
@@ -40,10 +39,11 @@
     private static final String[] HIDDEN = {"org.apache.geronimo", "org.mortbay", "org.xml", "org.w3c"};
     private static final String[] NON_OVERRIDABLE = {"java.", "javax."};
 
-    public void setUp() throws MalformedURLException {
+    public void setUp() throws Exception {
+        super.setUp();
         URL url = new File("src/test-resources/deployables/cltest/").toURL();
 //        URL url = getClass().getClassLoader().getResource("deployables/cltest/");
-        System.err.println("URL: "+url);
+        System.err.println("URL: " + url);
         urls = new URL[]{url};
     }
 

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java Tue Feb 28 22:54:40 2006
@@ -127,10 +127,15 @@
     private final Kernel kernel;
 
     private final ConfigurationStore configurationStore;
+
+    /**
+     * The artifact id for this configuration.
+     */
+    private final Artifact id;
+
     /**
      * The registered objectName for this configuraion.
      */
-    private final String objectNameString;
     private final ObjectName objectName;
 
     /**
@@ -154,21 +159,14 @@
     private final List classPath;
 
     /**
-     * The names of all GBeans contained in this configuration.
+     * The GBeanData objects by ObjectName
      */
-    private Set objectNames;
+    private final Map gbeans = new HashMap();
 
     /**
      * The classloader used to load the child GBeans contained in this configuration.
      */
-    private MultiParentClassLoader configurationClassLoader;
-
-    /**
-     * The GBeanData for the GBeans contained in this configuration.  These must be persisted as a ByteArray, becuase
-     * the data can only be deserialized in the configurationClassLoader, which is not available until this Configuration
-     * is deserialized and started.
-     */
-    private byte[] gbeanState;
+    private final MultiParentClassLoader configurationClassLoader;
 
     /**
      * The repositories used dependencies.
@@ -187,11 +185,10 @@
         environment = null;
         kernel = null;
         configurationStore = null;
-        objectNameString = null;
+        id = null;
         objectName = null;
         moduleType = null;
         parents = null;
-        objectNames = null;
         configurationClassLoader = null;
         classPath = null;
         repositories = null;
@@ -240,16 +237,22 @@
         return parents;
     }
 
-    public Configuration(ArrayList parents, Kernel kernel, String objectName, ConfigurationModuleType moduleType, Environment environment, List classPath, byte[] gbeanState, Collection repositories, ConfigurationStore configurationStore, ArtifactManager artifactManager, ArtifactResolver artifactResolver) throws MissingDependencyException, MalformedURLException, NoSuchConfigException {
+    public Configuration(ArrayList parents, Kernel kernel, String objectName, ConfigurationModuleType moduleType, Environment environment, List classPath, byte[] gbeanState, Collection repositories, ConfigurationStore configurationStore, ArtifactManager artifactManager, ArtifactResolver artifactResolver) throws MissingDependencyException, MalformedURLException, NoSuchConfigException, InvalidConfigException {
         this.parents = parents;
         this.kernel = kernel;
         this.environment = environment;
-        this.objectNameString = objectName;
-        this.objectName = objectName == null ? null : JMXUtil.getObjectName(objectName);
         this.moduleType = moduleType;
-        this.gbeanState = gbeanState;
         this.repositories = repositories;
 
+        this.id = environment.getConfigId();
+        this.objectName = objectName == null ? null : JMXUtil.getObjectName(objectName);
+        if (objectName.equals(getConfigurationObjectName(id))) {
+            throw new IllegalArgumentException("Expected objectName " +
+                    "<" + getConfigurationObjectName(id).getCanonicalName() + ">" +
+                    ", but actual objectName is " +
+                    "<" + this.objectName.getCanonicalName() + ">");
+        }
+
         if (classPath != null) {
             this.classPath = classPath;
         } else {
@@ -278,8 +281,7 @@
 
         // build configurationClassLoader
         URL[] urls = buildClassPath(configurationStore);
-        log.debug("ClassPath for " + environment.getConfigId() + " resolved to " + Arrays.asList(urls));
-
+        log.debug("ClassPath for " + id + " resolved to " + Arrays.asList(urls));
         if (parents.size() == 0) {
             // no explicit parent set, so use the class loader of this class as
             // the parent... this class should be in the root geronimo classloader,
@@ -293,10 +295,43 @@
             }
             configurationClassLoader = new MultiParentClassLoader(environment.getConfigId(), urls, parentClassLoaders);
         }
+
+        //
+        // Deserialize the GBeans
+        //
+        if (gbeanState != null && gbeanState.length > 0) {
+            // Set the thread context classloader so deserializing classes can grab the cl from the thread
+            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+            try {
+                Thread.currentThread().setContextClassLoader(configurationClassLoader);
+
+                ObjectInputStream ois = new ObjectInputStreamExt(new ByteArrayInputStream(gbeanState), configurationClassLoader);
+                try {
+                    while (true) {
+                        GBeanData gbeanData = new GBeanData();
+                        gbeanData.readExternal(ois);
+
+                        gbeans.put(gbeanData.getName(), gbeanData);
+                    }
+                } catch (EOFException e) {
+                    // ok
+                } finally {
+                    ois.close();
+                }
+
+                // todo consider applying updates from attribute store
+                // if (attributeStore != null) {
+                //    gbeans = attributeStore.setAttributes(environment.getConfigId(), gbeans, configurationClassLoader);
+                //}
+            } catch (Exception e) {
+                throw new InvalidConfigException("Unable to deserialize GBeanState", e);
+            } finally {
+                Thread.currentThread().setContextClassLoader(oldCl);
+            }
+        }
     }
 
     private void determineInherited() {
-
         for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
             Configuration parent = (Configuration) iterator.next();
 
@@ -304,7 +339,6 @@
             Set nonOverridableClasses = parentEnvironment.getNonOverrideableClasses();
             environment.addNonOverrideableClasses(nonOverridableClasses);
         }
-
     }
 
     private LinkedHashSet recursiveResolve(ArtifactResolver artifactResolver, LinkedHashSet dependencies) throws MissingDependencyException {
@@ -323,65 +357,6 @@
         return dependencies;
     }
 
-    public String getObjectName() {
-        return objectNameString;
-    }
-
-    public void loadGBeans(ManageableAttributeStore attributeStore) throws InvalidConfigException, GBeanAlreadyExistsException {
-        // 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(configurationClassLoader);
-
-            // create and initialize GBeans
-            Collection gbeans = loadGBeans();
-            if (attributeStore != null) {
-                gbeans = attributeStore.setAttributes(environment.getConfigId(), gbeans, configurationClassLoader);
-            }
-
-            // register all the GBeans
-            Set objectNames = new HashSet();
-            for (Iterator i = gbeans.iterator(); i.hasNext();) {
-                GBeanData gbeanData = (GBeanData) i.next();
-                // massage the GBeanData and add the GBean to the kernel
-                setGBeanBaseUrl(gbeanData);
-                loadGBean(gbeanData, objectNames);
-            }
-            this.objectNames = objectNames;
-        } catch (MalformedURLException e) {
-            throw new InvalidConfigException(e);
-        } catch (NoSuchConfigException e) {
-            throw new InvalidConfigException(e);
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldCl);
-        }
-    }
-
-    public void startRecursiveGBeans() throws GBeanNotFoundException {
-        for (Iterator iterator = objectNames.iterator(); iterator.hasNext();) {
-            ObjectName gbeanName = (ObjectName) iterator.next();
-            if (kernel.isGBeanEnabled(gbeanName)) {
-                kernel.startRecursiveGBean(gbeanName);
-            }
-        }
-    }
-
-    public void stopGBeans() throws GBeanNotFoundException {
-        for (Iterator iterator = objectNames.iterator(); iterator.hasNext();) {
-            ObjectName gbeanName = (ObjectName) iterator.next();
-            kernel.stopGBean(gbeanName);
-        }
-    }
-
-    public void unloadGBeans() throws GBeanNotFoundException {
-        for (Iterator iterator = objectNames.iterator(); iterator.hasNext();) {
-            ObjectName gbeanName = (ObjectName) iterator.next();
-            kernel.getDependencyManager().removeDependency(gbeanName, objectName);
-            kernel.unloadGBean(gbeanName);
-        }
-    }
-
     private URL[] buildClassPath(ConfigurationStore configurationStore) throws MalformedURLException, MissingDependencyException, NoSuchConfigException {
         LinkedHashSet dependencies = environment.getDependencies();
         List urls = new ArrayList(dependencies.size() + classPath.size());
@@ -402,138 +377,85 @@
         }
         for (Iterator i = classPath.iterator(); i.hasNext();) {
             URI uri = (URI) i.next();
-            urls.add(configurationStore.resolve(environment.getConfigId(), uri));
+            urls.add(configurationStore.resolve(id, uri));
         }
         return (URL[]) urls.toArray(new URL[urls.size()]);
     }
 
-    //TODO remove this when web app cl are config. cl.
-    private void setGBeanBaseUrl(GBeanData gbeanData) throws MalformedURLException, NoSuchConfigException {
-        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")) {
-                URL baseURL = configurationStore.resolve(environment.getConfigId(), URI.create(""));
-                gbeanData.setAttribute("configurationBaseUrl", baseURL);
-                return;
-            }
-        }
-    }
-
-    public void doStart() throws Exception {
-        assert objectName != null;
-
-        // declare dependencies on parents
-        Set parentNames = new HashSet();
-        for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
-            Configuration configuration = (Configuration) iterator.next();
-            ObjectName parentName = getConfigurationObjectName(configuration.getId());
-            parentNames.add(parentName);
-        }
-        DependencyManager dependencyManager = this.kernel.getDependencyManager();
-        dependencyManager.addDependencies(this.objectName, parentNames);
-
-        // declare the artifacts as loaded
-        LinkedHashSet artifacts = new LinkedHashSet();
-        artifacts.addAll(environment.getDependencies());
-        artifacts.addAll(environment.getReferences());
-        if (artifactManager != null) {
-            artifactManager.loadArtifacts(environment.getConfigId(), artifacts);
-        }
-
-        log.debug("Started configuration " + environment.getConfigId());
-    }
-
-    public void doFail() {
-        shutdown();
-    }
-
-    public synchronized void doStop() throws Exception {
-        log.debug("Stopping configuration " + environment.getConfigId());
-        // shutdown the configuration and unload all beans
-        shutdown();
-
+    /**
+     * Return the unique Id
+     * @return the unique Id
+     */
+    public Artifact getId() {
+        return id;
     }
 
-    private void shutdown() {
-        // unregister all GBeans
-        if (objectNames != null) {
-            for (Iterator i = objectNames.iterator(); i.hasNext();) {
-                ObjectName name = (ObjectName) i.next();
-                kernel.getDependencyManager().removeDependency(name, objectName);
-                try {
-                    log.trace("Unregistering GBean " + name);
-                    if (kernel.isLoaded(name)) {
-                        kernel.unloadGBean(name);
-                    }
-                } catch (Exception e) {
-                    // ignore
-                    log.warn("Could not unregister child " + name, e);
-                }
-            }
-        }
-
-        // destroy the class loader
-        if (configurationClassLoader != null) {
-            configurationClassLoader.destroy();
-            configurationClassLoader = null;
-        }
-
-        // declare all artifacts as unloaded
-        if (artifactManager != null) {
-            artifactManager.unloadAllArtifacts(environment.getConfigId());
-        }
+    /**
+     * Gets the unique name of this configuration within the kernel.
+     * @return the unique name of this configuration
+     */
+    public String getObjectName() {
+        return objectName.getCanonicalName();
     }
 
     /**
      * Gets the parent configurations of this configuration.
-     *
      * @return the parents of this configuration
      */
     public List getParents() {
         return parents;
     }
 
-    public Environment getEnvironment() {
-        return environment;
-    }
-
     /**
-     * Return the unique Id
-     *
-     * @return the unique Id
+     * Gets the declaration of the environment in which this configuration runs.
+     * @return the environment of this configuration
      */
-    public Artifact getId() {
-        return environment.getConfigId();
+    public Environment getEnvironment() {
+        return environment;
     }
 
     /**
      * Gets the type of the configuration (WAR, RAR et cetera)
-     *
      * @return Type of the configuration.
      */
     public ConfigurationModuleType getModuleType() {
         return moduleType;
     }
 
-    public byte[] getGBeanState() {
-        return gbeanState;
-    }
-
+    /**
+     * Gets the class loader for this configuration.
+     * @return the class loader for this configuration
+     */
     public ClassLoader getConfigurationClassLoader() {
         return configurationClassLoader;
     }
 
+    public ConfigurationStore getConfigurationStore() {
+        return configurationStore;
+    }
+
+    /**
+     * Gets an unmodifiable map of the GBeanDatas for the GBeans in this configuration by ObjectName.
+     * @return the GBeans in this configuration
+     */
+    public Map getGBeans() {
+        return Collections.unmodifiableMap(gbeans);
+    }
+
+    /**
+     * Determines of this configuration constains the specified GBean.
+     * @param gbean the name of the GBean
+     * @return true if this configuration contains the specified GBean; false otherwise
+     */
     public synchronized boolean containsGBean(ObjectName gbean) {
-        return objectNames.contains(gbean);
+        return gbeans.containsKey(gbean);
     }
 
     public synchronized void addGBean(GBeanData beanData, boolean start) throws InvalidConfigException, GBeanAlreadyExistsException {
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(configurationClassLoader);
-            ObjectName name = loadGBean(beanData, objectNames);
+            ObjectName name = loadGBean(beanData);
             if (start) {
                 try {
                     kernel.startRecursiveGBean(name);
@@ -541,16 +463,16 @@
                     throw new IllegalStateException("How could we not find a GBean that we just loaded ('" + name + "')?");
                 }
             }
+            gbeans.put(name, beanData);
         } finally {
             Thread.currentThread().setContextClassLoader(oldCl);
         }
     }
 
     public synchronized void removeGBean(ObjectName name) throws GBeanNotFoundException {
-        if (!objectNames.contains(name)) {
+        if (!gbeans.containsKey(name)) {
             throw new GBeanNotFoundException(name);
         }
-        kernel.getDependencyManager().removeDependency(name, this.objectName);
         try {
             if (kernel.getGBeanState(name) == State.RUNNING_INDEX) {
                 kernel.stopGBean(name);
@@ -559,77 +481,132 @@
         } catch (GBeanNotFoundException e) {
             // Bean is no longer loaded
         }
-        objectNames.remove(name);
+        gbeans.remove(name);
+    }
+
+    public void loadGBeans(ManageableAttributeStore attributeStore) throws InvalidConfigException, GBeanAlreadyExistsException {
+        try {
+            // create and initialize GBeans
+            Collection gbeans = this.gbeans.values();
+            if (attributeStore != null) {
+                gbeans = attributeStore.setAttributes(id, gbeans, configurationClassLoader);
+            }
+
+            // register all the GBeans
+            for (Iterator i = gbeans.iterator(); i.hasNext();) {
+                GBeanData gbeanData = (GBeanData) i.next();
+
+                // If the GBean has a configurationBaseUrl attribute, set it
+                // todo remove this when web app cl are config. cl.
+                GAttributeInfo attribute = gbeanData.getGBeanInfo().getAttribute("configurationBaseUrl");
+                if (attribute != null && attribute.getType().equals("java.net.URL")) {
+                    URL baseURL = configurationStore.resolve(id, URI.create(""));
+                    gbeanData.setAttribute("configurationBaseUrl", baseURL);
+                }
+
+                loadGBean(gbeanData);
+            }
+        } catch (MalformedURLException e) {
+            throw new InvalidConfigException(e);
+        } catch (NoSuchConfigException e) {
+            throw new InvalidConfigException(e);
+        }
     }
 
-    private ObjectName loadGBean(GBeanData beanData, Set objectNames) throws GBeanAlreadyExistsException {
+    private ObjectName loadGBean(GBeanData beanData) throws GBeanAlreadyExistsException {
         ObjectName name = beanData.getName();
 
         log.trace("Registering GBean " + name);
         kernel.loadGBean(beanData, configurationClassLoader);
-        objectNames.add(name);
-        // todo change this to a dependency on the gbeanData itself as soon as we add that feature
-        kernel.getDependencyManager().addDependency(name, this.objectName);
+
+        beanData.getDependencies().add(objectName);
         return name;
     }
 
 
-    /**
-     * Load GBeans from the supplied byte array using the supplied ClassLoader
-     *
-     * @return a Map<ObjectName, GBeanMBean> of GBeans loaded from the persisted state
-     * @throws InvalidConfigException if there is a problem deserializing the state
-     */
-    public Collection loadGBeans() throws InvalidConfigException {
-        Map gbeans = new HashMap();
-        try {
-            ObjectInputStream ois = new ObjectInputStreamExt(new ByteArrayInputStream(gbeanState), configurationClassLoader);
-            try {
-                while (true) {
-                    GBeanData gbeanData = new GBeanData();
-                    gbeanData.readExternal(ois);
-
-                    gbeans.put(gbeanData.getName(), gbeanData);
-                }
-            } catch (EOFException e) {
-                // ok
-            } finally {
-                ois.close();
+    public void startRecursiveGBeans() throws GBeanNotFoundException {
+        for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+            ObjectName gbeanName = (ObjectName) iterator.next();
+            if (kernel.isGBeanEnabled(gbeanName)) {
+                kernel.startRecursiveGBean(gbeanName);
             }
-            // avoid duplicate object names
-            return gbeans.values();
-        } catch (Exception e) {
-            throw new InvalidConfigException("Unable to deserialize GBeanState", e);
         }
     }
 
-    /**
-     * Return a byte array containing the persisted form of the supplied GBeans
-     *
-     * @return the persisted GBeans
-     * @throws org.apache.geronimo.kernel.config.InvalidConfigException
-     *          if there is a problem serializing the state
-     */
-    public synchronized GBeanData[] storeCurrentGBeans() throws InvalidConfigException {
-        // get the gbean data for all gbeans
-        GBeanData[] gbeans = new GBeanData[objectNames.size()];
-        Iterator iterator = objectNames.iterator();
-        for (int i = 0; i < gbeans.length; i++) {
-            ObjectName objectName = (ObjectName) iterator.next();
+    public void stopGBeans() throws GBeanNotFoundException {
+        for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+            ObjectName gbeanName = (ObjectName) iterator.next();
+            kernel.stopGBean(gbeanName);
+        }
+    }
+
+    public void unloadGBeans() throws GBeanNotFoundException {
+        for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+            ObjectName gbeanName = (ObjectName) iterator.next();
+            kernel.getDependencyManager().removeDependency(gbeanName, objectName);
+            kernel.unloadGBean(gbeanName);
+        }
+    }
+
+    public void doStart() throws Exception {
+        assert objectName != null;
+
+        // declare dependencies on parents
+        Set parentNames = new HashSet();
+        for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+            Configuration configuration = (Configuration) iterator.next();
+            ObjectName parentName = getConfigurationObjectName(configuration.getId());
+            parentNames.add(parentName);
+        }
+        DependencyManager dependencyManager = this.kernel.getDependencyManager();
+        dependencyManager.addDependencies(this.objectName, parentNames);
+
+        // declare the artifacts as loaded
+        LinkedHashSet artifacts = new LinkedHashSet();
+        artifacts.addAll(environment.getDependencies());
+        artifacts.addAll(environment.getReferences());
+        if (artifactManager != null) {
+            artifactManager.loadArtifacts(id, artifacts);
+        }
+
+        log.debug("Started configuration " + id);
+    }
+
+    public synchronized void doStop() throws Exception {
+        log.debug("Stopping configuration " + id);
+        shutdown();
+
+    }
+
+    public void doFail() {
+        log.debug("Failed configuration " + id);
+        shutdown();
+    }
+
+    private void shutdown() {
+        // unregister all GBeans
+        for (Iterator i = gbeans.keySet().iterator(); i.hasNext();) {
+            ObjectName name = (ObjectName) i.next();
             try {
-                gbeans[i] = kernel.getGBeanData(objectName);
+                if (kernel.isLoaded(name)) {
+                    log.trace("Unregistering GBean " + name);
+                    kernel.unloadGBean(name);
+                }
             } catch (Exception e) {
-                throw new InvalidConfigException("Unable to serialize GBeanData for " + objectName, e);
+                log.warn("Could not unregister child " + name, e);
             }
         }
+        gbeans.clear();
 
-        // save state
-        try {
-            gbeanState = storeGBeans(gbeans);
-        } catch (InvalidConfigException e) {
-            log.warn("Unable to update persistent state during shutdown", e);
+        // destroy the class loader
+        if (configurationClassLoader != null) {
+            configurationClassLoader.destroy();
+        }
+
+        // declare all artifacts as unloaded
+        if (artifactManager != null) {
+            artifactManager.unloadAllArtifacts(id);
         }
-        return gbeans;
     }
 
     /**
@@ -637,13 +614,19 @@
      *
      * @param gbeans the gbean data to persist
      * @return the persisted GBeans
-     * @throws org.apache.geronimo.kernel.config.InvalidConfigException
-     *          if there is a problem serializing the state
+     * @throws InvalidConfigException if there is a problem serializing the state
      */
     public static byte[] storeGBeans(GBeanData[] gbeans) throws InvalidConfigException {
         return storeGBeans(Arrays.asList(gbeans));
     }
 
+    /**
+     * Return a byte array containing the persisted form of the supplied GBeans
+     *
+     * @param gbeans the gbean data to persist
+     * @return the persisted GBeans
+     * @throws InvalidConfigException if there is a problem serializing the state
+     */
     public static byte[] storeGBeans(List gbeans) throws InvalidConfigException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream oos;
@@ -686,16 +669,16 @@
 
         infoFactory.addReference("Repositories", Repository.class, "GBean");
         infoFactory.addReference("ArtifactManager", ArtifactManager.class);
-        infoFactory.addReference("ArtifactResolver", ArtifactResolver.class);
+        infoFactory.addReference("ArtifactResolver", ArtifactResolver.class, "ArtifactResolver");
 
-        infoFactory.addOperation("addGBean", new Class[]{GBeanData.class, boolean.class});
-        infoFactory.addOperation("removeGBean", new Class[]{ObjectName.class});
-        infoFactory.addOperation("containsGBean", new Class[]{ObjectName.class});
-        infoFactory.addOperation("loadGBeans", new Class[]{});
-        infoFactory.addOperation("loadGBeans", new Class[]{ManageableAttributeStore.class});
-        infoFactory.addOperation("startRecursiveGBeans");
-        infoFactory.addOperation("stopGBeans");
-        infoFactory.addOperation("unloadGBeans");
+        infoFactory.addInterface(Configuration.class);
+//        infoFactory.addOperation("addGBean", new Class[]{GBeanData.class, boolean.class});
+//        infoFactory.addOperation("removeGBean", new Class[]{ObjectName.class});
+//        infoFactory.addOperation("containsGBean", new Class[]{ObjectName.class});
+//        infoFactory.addOperation("loadGBeans", new Class[]{ManageableAttributeStore.class});
+//        infoFactory.addOperation("startRecursiveGBeans");
+//        infoFactory.addOperation("stopGBeans");
+//        infoFactory.addOperation("unloadGBeans");
 
         infoFactory.setConstructor(new String[]{
                 "kernel",

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java Tue Feb 28 22:54:40 2006
@@ -23,13 +23,17 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.jmx.JMXUtil;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
 
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -40,6 +44,10 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.net.URL;
+import java.net.URI;
 
 /**
  * The standard non-editable ConfigurationManager implementation.  That is,
@@ -56,6 +64,7 @@
     protected final ManageableAttributeStore attributeStore;
     protected final PersistentConfigurationList configurationList;
     private final ShutdownHook shutdownHook;
+    private final ArtifactResolver artifactResolver;
     private static final ObjectName CONFIGURATION_NAME_QUERY;
 
     static {
@@ -66,11 +75,12 @@
         }
     }
 
-    public ConfigurationManagerImpl(Kernel kernel, Collection stores, ManageableAttributeStore attributeStore, PersistentConfigurationList configurationList) {
+    public ConfigurationManagerImpl(Kernel kernel, Collection stores, ManageableAttributeStore attributeStore, PersistentConfigurationList configurationList, ArtifactResolver artifactResolver) {
         this.kernel = kernel;
         this.stores = stores;
         this.attributeStore = attributeStore;
         this.configurationList = configurationList;
+        this.artifactResolver = artifactResolver;
         shutdownHook = new ShutdownHook(kernel);
     }
 
@@ -95,6 +105,16 @@
         throw new NoSuchStoreException("No such store: " + storeName);
     }
 
+    public Configuration getConfiguration(Artifact configId) {
+        try {
+            ObjectName objectName = Configuration.getConfigurationObjectName(configId);
+            Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(objectName, Configuration.class);
+            return configuration;
+        } catch (InvalidConfigException e) {
+            return null;
+        }
+    }
+
     public boolean isLoaded(Artifact configID) {
         try {
             ObjectName name = Configuration.getConfigurationObjectName(configID);
@@ -105,69 +125,7 @@
         }
     }
 
-    public ObjectName load(Artifact configID) throws NoSuchConfigException, IOException, InvalidConfigException {
-        List storeSnapshot = getStores();
-
-        for (int i = 0; i < storeSnapshot.size(); i++) {
-            ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
-            if (store.containsConfiguration(configID)) {
-                GBeanData config = store.loadConfiguration(configID);
-
-                ObjectName name = Configuration.getConfigurationObjectName(configID);
-                config.setName(name);
-                config.setAttribute("configurationStore", store);
-
-                try {
-                    kernel.loadGBean(config, Configuration.class.getClassLoader());
-                } catch (Exception e) {
-                    throw new InvalidConfigException("Unable to register configuration", e);
-                }
-
-                log.debug("Loaded Configuration " + name);
-
-                return name;
-            }
-
-        }
-        throw new NoSuchConfigException("No configuration with id: " + configID);
-    }
-
-    public void loadGBeans(Artifact configID) throws InvalidConfigException {
-        ObjectName configName = Configuration.getConfigurationObjectName(configID);
-        try {
-            kernel.startGBean(configName);
-            kernel.invoke(configName, "loadGBeans", new Object[]{attributeStore}, new String[]{ManageableAttributeStore.class.getName()});
-        } catch (Exception e) {
-            throw new InvalidConfigException("Could not extract gbean data from configuration", e);
-        }
-    }
-
-    public void start(Artifact configID) throws InvalidConfigException {
-        ObjectName configName = Configuration.getConfigurationObjectName(configID);
-        try {
-            kernel.invoke(configName, "startRecursiveGBeans");
-        } catch (Exception e) {
-            throw new InvalidConfigException("Could not start gbeans in configuration", e);
-        }
-        if (configurationList != null) {
-            configurationList.addConfiguration(configID.toString());
-        }
-    }
-
-    public void stop(Artifact configID) throws InvalidConfigException {
-        ObjectName configName = Configuration.getConfigurationObjectName(configID);
-        try {
-            kernel.invoke(configName, "stopGBeans");
-        } catch (Exception e) {
-            throw new InvalidConfigException("Could not stop gbeans in configuration", e);
-        }
-        if (configurationList != null) {
-            configurationList.removeConfiguration(configID.toString());
-        }
-    }
-
     public List loadRecursive(Artifact configID) throws NoSuchConfigException, IOException, InvalidConfigException {
-        LinkedList ancestors = new LinkedList();
         Set preloaded = kernel.listGBeans(CONFIGURATION_NAME_QUERY);
         for (Iterator it = preloaded.iterator(); it.hasNext();) {
             ObjectName name = (ObjectName) it.next();
@@ -179,7 +137,19 @@
                 it.remove();
             }
         }
+
+        // load configurations from the new child to the parents
+        LinkedList ancestors = new LinkedList();
         loadRecursive(configID, ancestors, preloaded);
+
+        // start the unloaded configurations from the prents to the chidren
+        List parentToChild = new LinkedList(ancestors);
+        for (Iterator iterator = parentToChild.iterator(); iterator.hasNext();) {
+            Artifact parent = (Artifact) iterator.next();
+            startConfiguration(parent);
+        }
+
+        // todo clean up after failure
         return ancestors;
     }
 
@@ -192,10 +162,25 @@
             if (!isLoaded(configID)) {
                 load(configID);
             }
+
             //put the earliest ancestors first, even if we have already started them.
             ancestors.remove(configID);
             ancestors.addFirst(configID);
+
             Environment environment = (Environment) kernel.getAttribute(name, "environment");
+            LinkedHashSet imports = environment.getImports();
+            for (Iterator iterator = imports.iterator(); iterator.hasNext();) {
+                Artifact artifact = (Artifact) iterator.next();
+                if (!artifact.isResolved()) {
+                    if (artifactResolver == null) {
+                        throw new IllegalStateException("Parent artifact is not resolved, and no artifact resolver is available: " + artifact);
+                    }
+                    imports = artifactResolver.resolve(imports);
+                    environment.setImports(imports);
+                    break;
+                }
+            }
+
             for (Iterator iterator = environment.getImports().iterator(); iterator.hasNext();) {
                 Artifact parent = (Artifact) iterator.next();
                 loadRecursive(parent, ancestors, preloaded);
@@ -211,16 +196,135 @@
         }
     }
 
-    public void unload(Artifact configID) throws NoSuchConfigException {
+    public ObjectName load(Artifact configId) throws NoSuchConfigException, IOException, InvalidConfigException {
+        List storeSnapshot = getStores();
+
+        for (int i = 0; i < storeSnapshot.size(); i++) {
+            ConfigurationStore store = (ConfigurationStore) storeSnapshot.get(i);
+            if (store.containsConfiguration(configId)) {
+                GBeanData configurationGBean = store.loadConfiguration(configId);
+
+                ObjectName configurationName = Configuration.getConfigurationObjectName(configId);
+                configurationGBean.setName(configurationName);
+                configurationGBean.setAttribute("configurationStore", store);
+
+                try {
+                    kernel.loadGBean(configurationGBean, Configuration.class.getClassLoader());
+                } catch (Exception e) {
+                    throw new InvalidConfigException("Unable to register configuration", e);
+                }
+
+                log.debug("Loaded Configuration " + configurationName);
+                return configurationName;
+            }
+
+        }
+        throw new NoSuchConfigException("No configuration with id: " + configId);
+    }
+
+    public void startConfiguration(Artifact configId) throws NoSuchConfigException, IOException, InvalidConfigException {
+        ObjectName configurationName = Configuration.getConfigurationObjectName(configId);
+
+        Configuration configuration;
+        try {
+            // start and assure it started
+            kernel.startGBean(configurationName);
+            if (State.RUNNING_INDEX != kernel.getGBeanState(configurationName)) {
+                throw new InvalidConfigurationException("Configuration " + configId + " failed to start");
+            }
+
+            // create a proxy to the configuration
+            configuration = (Configuration) kernel.getProxyManager().createProxy(configurationName, Configuration.class);
+        } catch (InvalidConfigurationException e) {
+            throw e;
+        } catch (GBeanNotFoundException e) {
+            throw new InvalidConfigException("Unable to start configuration gbean", e);
+        }
+
+        log.debug("Loaded Configuration " + configurationName);
+
+        // load the attribute overrides from the attribute store
+        Collection gbeans = configuration.getGBeans().values();
+        if (attributeStore != null) {
+            gbeans = attributeStore.setAttributes(configuration.getId(), gbeans, configuration.getConfigurationClassLoader());
+        }
+
+        // register all the GBeans
+        ConfigurationStore configurationStore = configuration.getConfigurationStore();
+        for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+            GBeanData gbeanData = (GBeanData) iterator.next();
+
+            // copy the gbeanData object as not to mutate the original
+            gbeanData = new GBeanData(gbeanData);
+
+            // If the GBean has a configurationBaseUrl attribute, set it
+            // todo remove this when web app cl are config. cl.
+            GAttributeInfo attribute = gbeanData.getGBeanInfo().getAttribute("configurationBaseUrl");
+            if (attribute != null && attribute.getType().equals("java.net.URL")) {
+                URL baseURL = configurationStore.resolve(configuration.getId(), URI.create(""));
+                gbeanData.setAttribute("configurationBaseUrl", baseURL);
+            }
+
+            // add a dependency from the gbean to the configuration
+            gbeanData.getDependencies().add(Configuration.getConfigurationObjectName(configuration.getId()));
+
+            log.trace("Registering GBean " + gbeanData.getName());
+
+            try {
+                kernel.loadGBean(gbeanData, configuration.getConfigurationClassLoader());
+            } catch (GBeanAlreadyExistsException e) {
+                throw new InvalidConfigException(e);
+            }
+        }
+    }
+
+    public void loadGBeans(Artifact configID) throws InvalidConfigException {
+    }
+
+    public void start(Artifact configId) throws InvalidConfigException {
+        ObjectName configurationName = Configuration.getConfigurationObjectName(configId);
+
+        try {
+            // start and assure it started
+            kernel.startGBean(configurationName);
+            if (State.RUNNING_INDEX != kernel.getGBeanState(configurationName)) {
+                throw new InvalidConfigurationException("Configuration " + configId + " failed to start");
+            }
+
+            // create a proxy to the configuration
+            Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(configurationName, Configuration.class);
+
+            startConfiguration(configuration);
+        } catch (Exception e) {
+            throw new InvalidConfigException("Could not start gbeans in configuration", e);
+        }
+
+        if (configurationList != null) {
+            configurationList.addConfiguration(configId.toString());
+        }
+    }
+
+    public void stop(Artifact configId) throws InvalidConfigException {
+        try {
+            Configuration configuration = getConfiguration(configId);
+            stopConfiguration(configuration);
+        } catch (Exception e) {
+            throw new InvalidConfigException("Could not stop gbeans in configuration", e);
+        }
+        if (configurationList != null) {
+            configurationList.removeConfiguration(configId.toString());
+        }
+    }
+
+    public void unload(Artifact configId) throws NoSuchConfigException {
         ObjectName configName;
         try {
-            configName = Configuration.getConfigurationObjectName(configID);
+            configName = Configuration.getConfigurationObjectName(configId);
         } catch (InvalidConfigException e) {
             throw new NoSuchConfigException("Could not construct configuration object name", e);
         }
         try {
             if (State.RUNNING_INDEX == kernel.getGBeanState(configName)) {
-                kernel.invoke(configName, "unloadGBeans");
                 kernel.stopGBean(configName);
             }
             kernel.unloadGBean(configName);
@@ -231,6 +335,48 @@
         }
     }
 
+    private void startConfiguration(Configuration configuration) throws InvalidConfigException  {
+        try {
+            // start the gbeans
+            Map gbeans = configuration.getGBeans();
+            for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+                ObjectName gbeanName = (ObjectName) iterator.next();
+                if (kernel.isGBeanEnabled(gbeanName)) {
+                    kernel.startRecursiveGBean(gbeanName);
+                }
+            }
+
+            // assure all of the gbeans are started
+            for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+                ObjectName gbeanName = (ObjectName) iterator.next();
+                if (State.RUNNING_INDEX != kernel.getGBeanState(gbeanName)) {
+                    throw new InvalidConfigurationException("Configuration " + configuration.getId() + " failed to start because gbean " + gbeanName + " did not start");
+                }
+            }
+        } catch (GBeanNotFoundException e) {
+            throw new InvalidConfigException(e);
+        }
+        // todo clean up after failure
+
+    }
+
+    private void stopConfiguration(Configuration configuration) throws GBeanNotFoundException {
+        Collection gbeans = configuration.getGBeans().values();
+
+        // stop the gbeans
+        for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+            ObjectName gbeanName = (ObjectName) iterator.next();
+            kernel.stopGBean(gbeanName);
+        }
+
+        // unload the gbeans
+        for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+            ObjectName gbeanName = (ObjectName) iterator.next();
+            kernel.unloadGBean(gbeanName);
+        }
+    }
+
+
     private List getStores() {
         return new ArrayList(stores);
     }
@@ -257,8 +403,9 @@
         infoFactory.addReference("Stores", ConfigurationStore.class, "ConfigurationStore");
         infoFactory.addReference("AttributeStore", ManageableAttributeStore.class, ManageableAttributeStore.ATTRIBUTE_STORE);
         infoFactory.addReference("PersistentConfigurationList", PersistentConfigurationList.class, PersistentConfigurationList.PERSISTENT_CONFIGURATION_LIST);
+        infoFactory.addReference("ArtifactResolver", ArtifactResolver.class, "ArtifactResolver");
         infoFactory.addInterface(ConfigurationManager.class);
-        infoFactory.setConstructor(new String[]{"kernel", "Stores", "AttributeStore", "PersistentConfigurationList"});
+        infoFactory.setConstructor(new String[]{"kernel", "Stores", "AttributeStore", "PersistentConfigurationList", "ArtifactResolver"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java Tue Feb 28 22:54:40 2006
@@ -21,6 +21,7 @@
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
@@ -33,8 +34,8 @@
  */
 public class EditableConfigurationManagerImpl extends ConfigurationManagerImpl implements EditableConfigurationManager {
     public EditableConfigurationManagerImpl(Kernel kernel, Collection stores, ManageableAttributeStore attributeStore,
-                                            PersistentConfigurationList configurationList) {
-        super(kernel, stores, attributeStore, configurationList);
+            PersistentConfigurationList configurationList, ArtifactResolver artifactResolver) {
+        super(kernel, stores, attributeStore, configurationList, artifactResolver);
     }
 
     public void addGBeanToConfiguration(Artifact configID, GBeanData gbean, boolean start) throws InvalidConfigException {
@@ -81,7 +82,7 @@
     static {
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(EditableConfigurationManagerImpl.class, ConfigurationManagerImpl.GBEAN_INFO, "ConfigurationManager");
         infoFactory.addInterface(EditableConfigurationManager.class);
-        infoFactory.setConstructor(new String[]{"kernel", "Stores", "AttributeStore", "PersistentConfigurationList"});
+        infoFactory.setConstructor(new String[]{"kernel", "Stores", "AttributeStore", "PersistentConfigurationList", "ArtifactResolver"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java Tue Feb 28 22:54:40 2006
@@ -53,6 +53,7 @@
     private final String[] nonOverridableClasses;
     private final String[] hiddenResources;
     private final String[] nonOverridableResources;
+    private boolean destroyed = false;
 
     /**
      * Creates a named class loader with no parents.
@@ -63,7 +64,7 @@
     public MultiParentClassLoader(Artifact id, URL[] urls) {
         super(urls);
         this.id = id;
-        parents = new ClassLoader[0];
+        parents = new ClassLoader[]{ClassLoader.getSystemClassLoader()};
         inverseClassLoading = false;
         hiddenClasses = new String[0];
         nonOverridableClasses = new String[0];
@@ -141,7 +142,7 @@
     }
 
     public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
-        super(urls, new FilteringParentCL(hiddenClasses));
+        super(urls);
         this.id = id;
         this.parents = copyParents(parents);
         this.inverseClassLoading = inverseClassLoading;
@@ -211,56 +212,74 @@
     }
 
     protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
-        Class clazz = findLoadedClass(name);
-
-        if (null != clazz) {
-            if (resolve) {
-                resolveClass(clazz);
+        //
+        // Check if class is in the loaded classes cache
+        //
+        Class cachedClass = findLoadedClass(name);
+        if (cachedClass != null) {
+            return resolveClass(cachedClass, resolve);
+        }
+
+        //
+        // if we are using inverse class loading, check local urls first
+        //
+        if (inverseClassLoading && !isDestroyed() && !isNonOverridableClass(name)) {
+            try {
+                Class clazz = findClass(name);
+                return resolveClass(clazz, resolve);
+            } catch (ClassNotFoundException ignored) {
             }
-            return clazz;
         }
 
-        if (inverseClassLoading) {
-            boolean checkMe = true;
-            for (int i = 0; i < nonOverridableClasses.length && checkMe; i++) {
-                if (name.startsWith(nonOverridableClasses[i])) {
-                    checkMe = false;
-                }
-            }
-
-            if (checkMe) {
+        //
+        // Check parent class loaders
+        //
+        if (!isHiddenClass(name)) {
+            for (int i = 0; i < parents.length; i++) {
+                ClassLoader parent = parents[i];
                 try {
-                    clazz = findClass(name);
-                    if (resolve) {
-                        resolveClass(clazz);
-                    }
-                    return clazz;
+                    Class clazz = parent.loadClass(name);
+                    return resolveClass(clazz, resolve);
                 } catch (ClassNotFoundException ignored) {
+                    // this parent didn't have the class; try the next one
                 }
             }
         }
 
-        boolean checkParents = true;
-        for (int i = 0; i < hiddenClasses.length && checkParents; i++) {
-            if (name.startsWith(hiddenClasses[i])) {
-                checkParents = false;
+        //
+        // if we are not using inverse class loading, check local urls now
+        //
+        // todo don't we want to exclude non-overridable classes
+        if (/*!inverseClassLoading &&*/ !isDestroyed() /*&& !isNonOverridableClass(name)*/) {
+            try {
+                Class clazz = findClass(name);
+                return resolveClass(clazz, resolve);
+            } catch (ClassNotFoundException ignored) {
             }
         }
-        if (checkParents) {
-            for (int i = 0; i < parents.length && clazz == null; i++) {
-                ClassLoader parent = parents[i];
-                try {
-                    clazz = parent.loadClass(name);
-                } catch (ClassNotFoundException ignored) {
-                    // this parent didn't have the class; try the next one
-                }
+
+        throw new ClassNotFoundException(name);
+    }
+
+    private boolean isNonOverridableClass(String name) {
+        for (int i = 0; i < nonOverridableClasses.length; i++) {
+            if (name.startsWith(nonOverridableClasses[i])) {
+                return true;
             }
         }
+        return false;
+    }
 
-        if (null == clazz) {
-            return super.loadClass(name, resolve);
+    private boolean isHiddenClass(String name) {
+        for (int i = 0; i < hiddenClasses.length; i++) {
+            if (name.startsWith(hiddenClasses[i])) {
+                return true;
+            }
         }
+        return false;
+    }
 
+    private Class resolveClass(Class clazz, boolean resolve) {
         if (resolve) {
             resolveClass(clazz);
         }
@@ -268,68 +287,112 @@
     }
 
     public URL getResource(String name) {
-        URL url = null;
-
-        if (inverseClassLoading) {
-            boolean checkMe = true;
-            for (int i = 0; i < nonOverridableResources.length && checkMe; i++) {
-                if (name.startsWith(nonOverridableResources[i])) {
-                    checkMe = false;
-                }
-            }
-
-            if (checkMe) {
-                url = findResource(name);
-                if (null != url) {
-                    return url;
-                }
-            }
+        if (isDestroyed()) {
+            return null;
         }
 
-        boolean checkParents = true;
-        for (int i = 0; i < hiddenResources.length && checkParents; i++) {
-            if (name.startsWith(hiddenResources[i])) {
-                checkParents = false;
+        //
+        // if we are using inverse class loading, check local urls first
+        //
+        if (inverseClassLoading && !isDestroyed() && !isNonOverridableResource(name)) {
+            URL url = findResource(name);
+            if (url != null) {
+                return url;
             }
         }
-        if (checkParents) {
-            for (int i = 0; i < parents.length && url == null; i++) {
+
+        //
+        // Check parent class loaders
+        //
+        if (!isHiddenResource(name)) {
+            for (int i = 0; i < parents.length; i++) {
                 ClassLoader parent = parents[i];
-                url = parent.getResource(name);
+                URL url = parent.getResource(name);
+                if (url != null) {
+                    return url;
+                }
             }
         }
 
-        if (url == null) {
+        //
+        // if we are not using inverse class loading, check local urls now
+        //
+        // todo don't we want to exclude non-overridable resources
+        if (/*!inverseClassLoading &&*/ !isDestroyed() /*&& !isNonOverridableResource(name)*/) {
             // parents didn't have the resource; attempt to load it from my urls
-            return super.getResource(name);
-        } else {
-            return url;
+            return findResource(name);
         }
+
+        return null;
     }
 
     public Enumeration findResources(String name) throws IOException {
+        if (isDestroyed()) {
+            return Collections.enumeration(Collections.EMPTY_SET);
+        }
+
         List resources = new ArrayList();
 
-        // Add resources from all parents
+        //
+        // if we are using inverse class loading, add the resources from local urls first
+        //
+        if (inverseClassLoading && !isDestroyed()) {
+            List myResources = Collections.list(super.findResources(name));
+            resources.addAll(myResources);
+        }
+
+        //
+        // Add parent resources
+        //
         for (int i = 0; i < parents.length; i++) {
             ClassLoader parent = parents[i];
             List parentResources = Collections.list(parent.getResources(name));
             resources.addAll(parentResources);
         }
 
-        // Add the resources from my urls
-        List myResources = Collections.list(super.findResources(name));
-        resources.addAll(myResources);
+        //
+        // if we are not using inverse class loading, add the resources from local urls now
+        //
+        if (!inverseClassLoading && !isDestroyed()) {
+            List myResources = Collections.list(super.findResources(name));
+            resources.addAll(myResources);
+        }
 
-        // return an enumeration over the list
         return Collections.enumeration(resources);
     }
 
+    private boolean isNonOverridableResource(String name) {
+        for (int i = 0; i < nonOverridableResources.length; i++) {
+            if (name.startsWith(nonOverridableResources[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isHiddenResource(String name) {
+        for (int i = 0; i < hiddenResources.length; i++) {
+            if (name.startsWith(hiddenResources[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public String toString() {
         return "[" + getClass().getName() + " id=" + id + "]";
     }
 
+    public synchronized boolean isDestroyed() {
+        return destroyed;
+    }
+
     public void destroy() {
+        synchronized(this) {
+            if (destroyed) return;
+            destroyed = true;
+        }
+
         LogFactory.release(this);
         clearSoftCache(ObjectInputStream.class, "subclassAudits");
         clearSoftCache(ObjectOutputStream.class, "subclassAudits");
@@ -340,30 +403,6 @@
         // it has introspected. If we don't flush the cache, we may run out of
         // Permanent Generation space.
         Introspector.flushCaches();
-    }
-
-    private static class FilteringParentCL extends ClassLoader {
-        private final String[] hiddenClasses;
-
-        public FilteringParentCL(String[] hiddenClasses) {
-            this.hiddenClasses = hiddenClasses;
-        }
-
-        protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
-            boolean checkParents = true;
-            for (int i = 0; i < hiddenClasses.length && checkParents; i++) {
-                if (name.startsWith(hiddenClasses[i])) {
-                    checkParents = false;
-                }
-            }
-
-            if (checkParents) {
-                return super.loadClass(name, resolve);
-            }
-
-            throw new ClassNotFoundException(name);
-        }
-        //TODO does this need a getResource method too?
     }
 
     private static final Object lock = new Object();

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java Tue Feb 28 22:54:40 2006
@@ -108,6 +108,9 @@
                 list.addAll(repository.list(groupId, artifactId, type));
             }
 
+            if (list.isEmpty()) {
+                return null;
+            }
             Artifact repositoryArtifact = (Artifact) list.last();
             return repositoryArtifact.getVersion();
         }
@@ -177,7 +180,7 @@
     public static final GBeanInfo GBEAN_INFO;
 
     static {
-        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(DefaultArtifactResolver.class, "GBean");
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(DefaultArtifactResolver.class, "ArtifactResolver");
         infoFactory.addReference("ArtifactManager", ArtifactManager.class, "GBean");
         infoFactory.addReference("Repositories", Repository.class, "GBean");
         infoFactory.addInterface(ArtifactResolver.class);

Added: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java?rev=381933&view=auto
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java (added)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java Tue Feb 28 22:54:40 2006
@@ -0,0 +1,185 @@
+/**
+ *
+ * Copyright 2005 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.config;
+
+import java.io.IOException;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.SortedSet;
+import java.util.LinkedHashSet;
+import java.util.TreeSet;
+import java.util.Iterator;
+import java.net.URL;
+import java.net.URI;
+import java.net.MalformedURLException;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
+import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
+import org.apache.geronimo.kernel.repository.ArtifactManager;
+import org.apache.geronimo.kernel.repository.Version;
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.KernelFactory;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.gbean.GBeanData;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConfigurationManagerTest extends TestCase {
+    private Kernel kernel;
+    private Artifact artifact1;
+    private Artifact artifact2;
+    private Artifact artifact3;
+    private Map configurations = new HashMap();
+    private ConfigurationManagerImpl configurationManager;
+
+    public void test() throws Exception {
+        List list = configurationManager.loadRecursive(artifact3);
+        assertTrue(list.contains(artifact3));
+        assertTrue(list.contains(artifact2));
+        assertTrue(list.contains(artifact1));
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact3))) ;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact2))) ;
+        assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact1))) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationObjectName(artifact3))) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationObjectName(artifact2))) ;
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(Configuration.getConfigurationObjectName(artifact1))) ;
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        kernel = KernelFactory.newInstance().createKernel("test");
+        kernel.boot();
+
+        ObjectName artifactManagerName = new ObjectName(":j2eeType=ArtifactManager");
+        GBeanData artifactManagerData = new GBeanData(artifactManagerName, DefaultArtifactManager.GBEAN_INFO);
+        kernel.loadGBean(artifactManagerData, getClass().getClassLoader());
+        kernel.startGBean(artifactManagerName);
+        assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(artifactManagerName));
+        ArtifactManager artifactManager = (ArtifactManager) kernel.getProxyManager().createProxy(artifactManagerName, ArtifactManager.class);
+
+        artifact1 = new Artifact("test", "1", "1.1", "bar");
+        artifact2 = new Artifact("test", "2", "2.2", "bar");
+        artifact3 = new Artifact("test", "3", "3.3", "bar");
+
+        Environment e1 = new Environment();
+        e1.setConfigId(artifact1);
+        GBeanData gbeanData1 = new GBeanData(Configuration.getConfigurationObjectName(artifact1), Configuration.GBEAN_INFO);
+        gbeanData1.setAttribute("environment", e1);
+        gbeanData1.setReferencePattern("ArtifactManager", artifactManagerName);
+        configurations.put(artifact1, gbeanData1);
+
+        Environment e2 = new Environment();
+        e2.setConfigId(artifact2);
+        e2.addImport(new Artifact("test", "1", (Version) null, "bar"));
+        GBeanData gbeanData2 = new GBeanData(Configuration.getConfigurationObjectName(artifact2), Configuration.GBEAN_INFO);
+        gbeanData2.setAttribute("environment", e2);
+        gbeanData2.setReferencePattern("ArtifactManager", artifactManagerName);
+//        gbeanData2.setAttribute("gBeanState", state);
+//        e2.setAttribute("configurationStore", new MockConfigStore(new File("foo").toURL()));
+        configurations.put(artifact2, gbeanData2);
+
+        Environment e3 = new Environment();
+        e3.setConfigId(artifact3);
+        e3.addImport(new Artifact("test", "2", (Version) null, "bar"));
+        GBeanData gbeanData3 = new GBeanData(Configuration.getConfigurationObjectName(artifact3), Configuration.GBEAN_INFO);
+        gbeanData3.setAttribute("environment", e3);
+        gbeanData3.setReferencePattern("ArtifactManager", artifactManagerName);
+        configurations.put(artifact3, gbeanData3);
+
+        TestRepository testRepository = new TestRepository();
+        configurationManager = new ConfigurationManagerImpl(kernel,
+                Collections.singleton(new TestConfigStore()),
+                null,
+                null,
+                new DefaultArtifactResolver(artifactManager, testRepository));
+    }
+
+    private class TestConfigStore implements ConfigurationStore {
+        public void install(ConfigurationData configurationData) throws IOException, InvalidConfigException {
+            throw new UnsupportedOperationException();
+        }
+
+        public void uninstall(Artifact configId) throws NoSuchConfigException, IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        public GBeanData loadConfiguration(Artifact configId) throws IOException, InvalidConfigException, NoSuchConfigException {
+            return (GBeanData) configurations.get(configId);
+        }
+
+        public boolean containsConfiguration(Artifact configId) {
+            return configurations.containsKey(configId);
+        }
+
+        public String getObjectName() {
+            throw new UnsupportedOperationException();
+        }
+
+        public List listConfigurations() {
+            throw new UnsupportedOperationException();
+        }
+
+        public File createNewConfigurationDir(Artifact configId) throws ConfigurationAlreadyExistsException {
+            throw new UnsupportedOperationException();
+        }
+
+        public URL resolve(Artifact configId, URI uri) throws NoSuchConfigException, MalformedURLException {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    private class TestRepository implements ListableRepository {
+        public SortedSet list() {
+            return new TreeSet(configurations.keySet());
+        }
+
+        public SortedSet list(String groupId, String artifactId, String type) {
+            TreeSet artifacts = new TreeSet();
+            for (Iterator iterator = configurations.keySet().iterator(); iterator.hasNext();) {
+                Artifact artifact = (Artifact) iterator.next();
+                if (artifact.getGroupId().equals(groupId) &&
+                        artifact.getArtifactId().equals(artifactId) &&
+                        artifact.getType().equals(type)) {
+                    artifacts.add(artifact);
+                }
+            }
+            return artifacts;
+        }
+
+        public boolean contains(Artifact artifact) {
+            return configurations.containsKey(artifact);
+        }
+
+        public File getLocation(Artifact artifact) {
+            throw new UnsupportedOperationException();
+        }
+
+        public LinkedHashSet getDependencies(Artifact artifact) {
+            throw new UnsupportedOperationException();
+        }
+    }
+}

Modified: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java Tue Feb 28 22:54:40 2006
@@ -88,6 +88,7 @@
 
         // create parent which uses version1 explicitly
         Environment environment = new Environment();
+        environment.setConfigId(loader);
         environment.addDependency(version1);
         Configuration parent = new Configuration(null,
                 Configuration.getConfigurationObjectName(loader).getCanonicalName(),

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java?rev=381933&r1=381932&r2=381933&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java Tue Feb 28 22:54:40 2006
@@ -206,8 +206,8 @@
         }
 
         Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(name, Configuration.class);
-        Collection collection = configuration.loadGBeans();
-        for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
+        Map gbeans = configuration.getGBeans();
+        for (Iterator iterator = gbeans.values().iterator(); iterator.hasNext();) {
             GBeanData gbeanData = (GBeanData) iterator.next();
             out.println();
             out.println();



Mime
View raw message