geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r385232 [1/2] - in /geronimo/branches/1.1/modules: axis-builder/src/test/org/apache/geronimo/axis/builder/ client-builder/src/java/org/apache/geronimo/client/builder/ connector-builder/src/test/org/apache/geronimo/connector/deployment/ depl...
Date Sun, 12 Mar 2006 01:34:07 GMT
Author: dain
Date: Sat Mar 11 17:34:04 2006
New Revision: 385232

URL: http://svn.apache.org/viewcvs?rev=385232&view=rev
Log:
Deployment context is now backed by a Configuration object.
Moved GBean preprocessing back out of Configuration and into ConfigurationManager so the GBeanData objects would not be modified.
GBeans are now only registered with the kernel when the configuration is started from the configuration manager.
Split out all resolution code from the configuration to an injected strategy object ConfigurationReslver.
Simplified the construction requirements of Configuration and DeploymentContext.

Added:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationResolver.java
Modified:
    geronimo/branches/1.1/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java
    geronimo/branches/1.1/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
    geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
    geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/branches/1.1/modules/deployment/src/test/org/apache/geronimo/deployment/DeploymentContextTest.java
    geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
    geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java
    geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/NamingContext.java
    geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.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/ConfigurationData.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/ConfigurationUtil.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/test/org/apache/geronimo/kernel/ConfigTest.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/repository/ArtifactResolverTest.java
    geronimo/branches/1.1/modules/naming-builder/src/java/org/apache/geronimo/naming/deployment/ENCConfigBuilder.java
    geronimo/branches/1.1/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java
    geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
    geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
    geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java
    geronimo/branches/1.1/modules/web-builder/src/java/org/apache/geronimo/web/deployment/AbstractWebModuleBuilder.java

Modified: geronimo/branches/1.1/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java (original)
+++ geronimo/branches/1.1/modules/axis-builder/src/test/org/apache/geronimo/axis/builder/ServiceReferenceTest.java Sat Mar 11 17:34:04 2006
@@ -78,7 +78,7 @@
 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384686 $ $Date$
  */
 public class ServiceReferenceTest extends TestCase {
     private static final File basedir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
@@ -107,7 +107,7 @@
         Map nameKeys = new HashMap();
         nameKeys.put("domain", "geronimo");
         environment.setProperties(nameKeys);
-        context = new DeploymentContext(tmpbasedir, environment, ConfigurationModuleType.CAR, null, null);
+        context = new DeploymentContext(tmpbasedir, environment, ConfigurationModuleType.CAR, null);
 
         File moduleLocation = new File(tmpbasedir, "ejb");
         moduleLocation.mkdirs();

Modified: geronimo/branches/1.1/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java (original)
+++ geronimo/branches/1.1/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java Sat Mar 11 17:34:04 2006
@@ -85,7 +85,7 @@
 
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384686 $ $Date$
  */
 public class AppClientModuleBuilder implements ModuleBuilder {
 
@@ -272,7 +272,6 @@
             EARContext appClientDeploymentContext = new EARContext(appClientDir,
                     clientEnvironment,
                     ConfigurationModuleType.CAR,
-                    Collections.singleton(repository),
                     kernel,
                     clientApplicationName,
                     transactionContextManagerObjectName,

Modified: geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java Sat Mar 11 17:34:04 2006
@@ -83,7 +83,7 @@
 import java.util.jar.JarFile;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384933 $ $Date$
  */
 public class ConnectorModuleBuilderTest extends TestCase {
     private static final File basedir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
@@ -356,7 +356,6 @@
                 EARContext earContext = new EARContext(tempDir,
                         module.getEnvironment(),
                         module.getType(),
-                        Collections.singleton(repository),
                         kernel,
                         j2eeContext.getJ2eeApplicationName(),
                         null,

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=385232&r1=385231&r2=385232&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 Sat Mar 11 17:34:04 2006
@@ -29,72 +29,78 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.Map;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
-import javax.management.ObjectName;
 
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.util.DeploymentUtil;
-import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationData;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.ConfigurationUtil;
-import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.ArtifactResolver;
-import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
-import org.apache.geronimo.kernel.repository.Dependency;
 import org.apache.geronimo.kernel.repository.Environment;
-import org.apache.geronimo.kernel.repository.ImportType;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384933 $ $Date$
  */
 public class DeploymentContext {
+    private static int deploymentCount = 42;
 
-    private final Environment environment;
-    private final ConfigurationModuleType moduleType;
-    private final LinkedHashSet classpath = new LinkedHashSet();
-    private final Collection repositories;
-    private final Kernel kernel;
-    private final GBeanDataRegistry gbeans = new GBeanDataRegistry();
     private final File baseDir;
     private final URI baseUri;
     private final byte[] buffer = new byte[4096];
-    private final List loadedConfigurations = new ArrayList();
     private final List childConfigurationDatas = new ArrayList();
-    private ConfigurationManager configurationManager;
-    private final ArtifactResolver artifactResolver;
-
-
-    public DeploymentContext(File baseDir, Environment environment, ConfigurationModuleType type, Collection repositories, Kernel kernel) throws DeploymentException {
-        assert baseDir != null: "baseDir is null";
-        assert environment != null: "environment is null";
-        assert type != null: "type is null";
+    private final ConfigurationManager configurationManager;
+    private final Configuration configuration;
+    private final Environment environment;
 
-        this.environment = environment;
-        this.moduleType = type;
-        this.repositories = repositories;
-        this.kernel = kernel;
+    public DeploymentContext(File baseDir, Environment environment, ConfigurationModuleType moduleType, Kernel kernel) throws DeploymentException {
+        this(baseDir,
+                environment,
+                moduleType,
+                ConfigurationUtil.getConfigurationManager(kernel));
+    }
+
+    public DeploymentContext(File baseDir, Environment environment, ConfigurationModuleType moduleType, ConfigurationManager configurationManager) throws DeploymentException {
+        this(createTempConfiguration(environment, moduleType, baseDir, configurationManager),
+                baseDir,
+                environment,
+                moduleType,
+                configurationManager);
+    }
+
+    public DeploymentContext(Configuration configuration, File baseDir) throws DeploymentException {
+        this(configuration,
+                baseDir,
+                configuration.getEnvironment(),
+                configuration.getModuleType(),
+                null);
+    }
+
+    private DeploymentContext(Configuration configuration, File baseDir, Environment environment, ConfigurationModuleType moduleType, ConfigurationManager configurationManager) throws DeploymentException {
+        if (baseDir == null) throw new NullPointerException("baseDir is null");
+        if (environment == null) throw new NullPointerException("environment is null");
+        if (moduleType == null) throw new NullPointerException("type is null");
+        if (configuration == null) throw new NullPointerException("configuration is null");
 
         if (!baseDir.exists()) {
             baseDir.mkdirs();
@@ -105,182 +111,165 @@
         this.baseDir = baseDir;
         this.baseUri = baseDir.toURI();
 
-        if (kernel != null) {
-            configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
-        }
-        artifactResolver = new DefaultArtifactResolver(null, repositories);
-
-        determineNaming();
-        setupParents();
+        this.environment = environment;
+        this.configurationManager = configurationManager;
+        this.configuration = configuration;
     }
 
-    private void determineNaming() throws DeploymentException {
-        if (environment.getProperties() != null && !environment.getProperties().isEmpty()) {
-            return;
-        }
-        Collection dependencies = environment.getDependencies();
-        if (kernel == null ||  dependencies.isEmpty()) {
-            throw new DeploymentException("Neither domain and server nor any way to determine them was provided for configuration " + environment.getConfigId());
+    private static Configuration createTempConfiguration(Environment environment, ConfigurationModuleType moduleType, File baseDir, ConfigurationManager configurationManager) throws DeploymentException {
+        // create a new environment object for use in our temporary configuration
+        // NOTE: the configuration class will resolve all dependencies and set them
+        // back into this environment object, so don't use this environment for the
+        // final configuration data
+        Environment deploymentEnvironment = new Environment(environment);
+
+        // use a modified configuration id for the configuration object in case this
+        // configuation is already running in the server
+        Artifact id = environment.getConfigId();
+        synchronized (DeploymentContext.class) {
+            id = new Artifact("geronimo-deployment", id.getArtifactId(), "" + deploymentCount++, id.getType());
         }
-        ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+        deploymentEnvironment.setConfigId(id);
 
+        // Add a new temporary configuration to hold our data
+        ConfigurationData configurationData = new ConfigurationData(moduleType, null, null, null, deploymentEnvironment, baseDir);
         try {
-            boolean loaded = false;
-
-            Artifact parent = null;
-            for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) {
-                Dependency dependency = (Dependency) iterator.next();
-                Artifact artifact = dependency.getArtifact();
-                if (configurationManager.isConfiguration(artifact)) {
-                    if (!configurationManager.isLoaded(artifact)) {
-                        configurationManager.loadConfiguration(artifact);
-                        loaded = true;
-                    }
-                    parent = artifact;
-                    break;
-                }
-            }
-            if (parent == null) {
-                throw new DeploymentException("Neither domain and server nor any way to determine them was provided for configuration " + environment.getConfigId());
-            }
-
-            try {
-                ObjectName parentName = Configuration.getConfigurationObjectName(parent);
-                Environment environment = (Environment) kernel.getAttribute(parentName, "environment");
-                this.environment.setProperties(environment.getProperties());
-            } catch (Exception e) {
-                throw new DeploymentException("Unable to copy domain and server from parent configuration", e);
-            } finally {
-                if (loaded) {
-//                    we need to unload again so the loadedAncestors list will be in the correct order to start configs.
-                    configurationManager.unloadConfiguration(parent);
-                }
-            }
+            return configurationManager.loadConfiguration(configurationData, new DeploymentContextConfigurationStore(baseDir));
         } catch (Exception e) {
-            throw new DeploymentException("Unable to load first parent of configuration " + environment.getConfigId(), e);
-        } finally {
-            ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
-        }
-
-        //check that domain and server are now known
-        if (environment.getProperties() == null || environment.getProperties().isEmpty()) {
-            throw new IllegalStateException("Properties not be determined from explicit args or parent configuration. ParentID: " + dependencies);
+            throw new DeploymentException("Unable to create configuration for deployment", e);
         }
     }
 
     public Artifact getConfigID() {
-        return environment.getConfigId();
-    }
-
-    public ConfigurationModuleType getType() {
-        return moduleType;
+        return configuration.getId();
     }
 
     public File getBaseDir() {
         return baseDir;
     }
 
-    public void addGBean(GBeanData gbean) {
-        assert gbean.getName() != null: "GBean name is null";
-        gbeans.register(gbean);
+    public void addGBean(GBeanData gbean) throws GBeanAlreadyExistsException {
+        if (gbean == null) throw new NullPointerException("gbean is null");
+        if (gbean.getName() == null) throw new NullPointerException("gbean.getName() is null");
+        configuration.addGBean(gbean);
     }
 
     public Set getGBeanNames() {
-        return gbeans.getGBeanNames();
+        return new HashSet(configuration.getGBeans().keySet());
     }
 
+    /**
+     * @deprecated use findGBeans(pattern)
+     */
     public Set listGBeans(AbstractNameQuery pattern) {
-        return gbeans.listGBeans(pattern);
+        return findGBeans(pattern);
+    }
+
+    public AbstractName findGBean(AbstractNameQuery pattern) throws GBeanNotFoundException {
+        return configuration.findGBean(pattern);
+    }
+
+    public AbstractName findGBean(Set patterns) throws GBeanNotFoundException {
+        return configuration.findGBean(patterns);
+    }
+
+    public LinkedHashSet findGBeans(AbstractNameQuery pattern) {
+        return configuration.findGBeans(pattern);
+    }
+
+    public LinkedHashSet findGBeans(Set patterns) {
+        return configuration.findGBeans(patterns);
     }
 
     public GBeanData getGBeanInstance(AbstractName name) throws GBeanNotFoundException {
-        return gbeans.getGBeanInstance(name);
+        Map gbeans = configuration.getGBeans();
+        GBeanData gbeanData = (GBeanData) gbeans.get(name);
+        if (gbeanData == null) {
+            throw new GBeanNotFoundException(name);
+        }
+        return gbeanData;
     }
 
     /**
      * Copy a packed jar file into the deployment context and place it into the
      * path specified in the target path.  The newly added packed jar is added
      * to the classpath of the configuration.
-     * <p/>
-     * NOTE: The class loader that is obtained from this deployment context
-     * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the packed jar file should be placed
-     * @param jarFile    the jar file to copy
+     * @param jarFile the jar file to copy
      * @throws IOException if there's a problem copying the jar file
      */
     public void addIncludeAsPackedJar(URI targetPath, JarFile jarFile) throws IOException {
+        if (targetPath.getPath().endsWith("/")) throw new IllegalStateException("target path must not end with a '/' character: " + targetPath);
+
         File targetFile = getTargetFile(targetPath);
         DeploymentUtil.copyToPackedJar(jarFile, targetFile);
-        classpath.add(targetPath);
+
+        if (!targetFile.isFile()) throw new IllegalStateException("target file should be a file: " + targetFile);
+        configuration.addToClassPath(targetPath);
     }
 
     /**
      * Copy a ZIP file entry into the deployment context and place it into the
      * path specified in the target path.  The newly added entry is added
      * to the classpath of the configuration.
-     * <p/>
-     * NOTE: The class loader that is obtained from this deployment context
-     * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the ZIP file entry should be placed
-     * @param zipFile    the ZIP file
-     * @param zipEntry   the ZIP file entry
+     * @param zipFile the ZIP file
+     * @param zipEntry the ZIP file entry
      * @throws IOException if there's a problem copying the ZIP entry
      */
     public void addInclude(URI targetPath, ZipFile zipFile, ZipEntry zipEntry) throws IOException {
+        if (!targetPath.getPath().endsWith("/")) throw new IllegalStateException("target path must end with a '/' character: " + targetPath);
+
         File targetFile = getTargetFile(targetPath);
         addFile(targetFile, zipFile, zipEntry);
-        classpath.add(targetPath);
+
+        if (!targetFile.isDirectory()) throw new IllegalStateException("target file should be a directory: " + targetFile);
+        configuration.addToClassPath(targetPath);
     }
 
     /**
      * Copy a file into the deployment context and place it into the
      * path specified in the target path.  The newly added file is added
      * to the classpath of the configuration.
-     * <p/>
-     * NOTE: The class loader that is obtained from this deployment context
-     * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the file should be placed
      * @param source     the URL of file to be copied
      * @throws IOException if there's a problem copying the ZIP entry
      */
     public void addInclude(URI targetPath, URL source) throws IOException {
+        if (targetPath.getPath().endsWith("/")) throw new IllegalStateException("target path must not end with a '/' character: " + targetPath);
+
         File targetFile = getTargetFile(targetPath);
         addFile(targetFile, source);
-        classpath.add(targetPath);
+
+        if (!targetFile.isFile()) throw new IllegalStateException("target file should be a file: " + targetFile);
+        configuration.addToClassPath(targetPath);
     }
 
     /**
      * Copy a file into the deployment context and place it into the
      * path specified in the target path.  The newly added file is added
      * to the classpath of the configuration.
-     * <p/>
-     * NOTE: The class loader that is obtained from this deployment context
-     * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param targetPath where the file should be placed
      * @param source     the file to be copied
      * @throws IOException if there's a problem copying the ZIP entry
      */
     public void addInclude(URI targetPath, File source) throws IOException {
+        if (targetPath.getPath().endsWith("/")) throw new IllegalStateException("target path must not end with a '/' character: " + targetPath);
+
         File targetFile = getTargetFile(targetPath);
         addFile(targetFile, source);
-        classpath.add(targetPath);
+
+        if (!targetFile.isFile()) throw new IllegalStateException("target file should be a file: " + targetFile);
+        configuration.addToClassPath(targetPath);
     }
 
     /**
      * Import the classpath from a jar file's manifest.  The imported classpath
      * is crafted relative to <code>moduleBaseUri</code>.
-     * <p/>
-     * NOTE: The class loader that is obtained from this deployment context
-     * may get out of sync with the newly augmented classpath; obtain a freshly
-     * minted class loader by calling <code>getConfigurationClassLoader</code> method.
      *
      * @param moduleFile    the jar file from which the manifest is obtained.
      * @param moduleBaseUri the base for the imported classpath
@@ -320,11 +309,27 @@
                 throw new DeploymentException("Manifest class path entries must be relative (J2EE 1.4 Section 8.2): moduel=" + moduleBaseUri);
             }
 
-            URI targetUri = moduleBaseUri.resolve(pathUri);
-            classpath.add(targetUri);
+            try {
+                URI targetUri = moduleBaseUri.resolve(pathUri);
+                if (targetUri.getPath().endsWith("/")) throw new IllegalStateException("target path must not end with a '/' character: " + targetUri);
+                configuration.addToClassPath(targetUri);
+            } catch (IOException e) {
+                throw new DeploymentException(e);
+            }
         }
     }
 
+    public void addClass(URI targetPath, String fqcn, byte[] bytes) throws IOException, URISyntaxException {
+        if (!targetPath.getPath().endsWith("/")) throw new IllegalStateException("target path must end with a '/' character: " + targetPath);
+
+        String classFileName = fqcn.replace('.', '/') + ".class";
+
+        File targetFile = getTargetFile(new URI(targetPath.toString() + classFileName));
+        addFile(targetFile, new ByteArrayInputStream(bytes));
+
+        configuration.addToClassPath(targetPath);
+    }
+
     public void addFile(URI targetPath, ZipFile zipFile, ZipEntry zipEntry) throws IOException {
         addFile(getTargetFile(targetPath), zipFile, zipEntry);
     }
@@ -341,14 +346,6 @@
         addFile(getTargetFile(targetPath), new ByteArrayInputStream(source.getBytes()));
     }
 
-    public void addClass(URI location, String fqcn, byte[] bytes) throws IOException, URISyntaxException {
-        assert location.toString().endsWith("/");
-
-        classpath.add(location);
-        String classFileName = fqcn.replace('.', '/') + ".class";
-        addFile(getTargetFile(new URI(location.toString() + classFileName)), new ByteArrayInputStream(bytes));
-    }
-
     private void addFile(File targetFile, ZipFile zipFile, ZipEntry zipEntry) throws IOException {
         if (zipEntry.isDirectory()) {
             targetFile.mkdirs();
@@ -397,251 +394,81 @@
     }
 
     public File getTargetFile(URI targetPath) {
-        assert !targetPath.isAbsolute() : "targetPath is absolute";
-        assert !targetPath.isOpaque() : "targetPath is opaque";
+        if (targetPath == null) throw new NullPointerException("targetPath is null");
+        if (targetPath.isAbsolute()) throw new IllegalArgumentException("targetPath is absolute");
+        if (targetPath.isOpaque()) throw new IllegalArgumentException("targetPath is opaque");
         return new File(baseUri.resolve(targetPath));
     }
 
-//    static interface ParentSource {
-//        Collection getParents(Artifact point) throws DeploymentException;
-//    }
-//
-//    List getExtremalSet(Collection points, ParentSource parentSource) throws DeploymentException {
-//        LinkedHashMap pointToEnvelopeMap = new LinkedHashMap();
-//        for (Iterator iterator = points.iterator(); iterator.hasNext();) {
-//            Artifact newPoint = (Artifact) iterator.next();
-//            Set newEnvelope = new HashSet();
-//            getEnvelope(newPoint, parentSource, newEnvelope);
-//            boolean useMe = true;
-//            for (Iterator iterator1 = pointToEnvelopeMap.entrySet().iterator(); iterator1.hasNext();) {
-//                Map.Entry entry = (Map.Entry) iterator1.next();
-//                Set existingEnvelope = (Set) entry.getValue();
-//                if (existingEnvelope.contains(newPoint)) {
-//                    useMe = false;
-//                } else if (newEnvelope.contains(entry.getKey())) {
-//                    iterator1.remove();
-//                }
-//            }
-//            if (useMe) {
-//                pointToEnvelopeMap.put(newPoint, newEnvelope);
-//            }
-//        }
-//        return new ArrayList(pointToEnvelopeMap.keySet());
-//    }
-//
-//    private void getEnvelope(Artifact point, ParentSource parentSource, Set envelope) throws DeploymentException {
-//        Collection newPoints = parentSource.getParents(point);
-//        envelope.addAll(newPoints);
-//        for (Iterator iterator = newPoints.iterator(); iterator.hasNext();) {
-//            Artifact newPoint = (Artifact) iterator.next();
-//            getEnvelope(newPoint, parentSource, envelope);
-//        }
-//    }
-//
-//    static class ConfigurationParentSource implements ParentSource {
-//
-//        private final Kernel kernel;
-//
-//        public ConfigurationParentSource(Kernel kernel) {
-//            this.kernel = kernel;
-//        }
-//
-//        public Collection getParents(Artifact configID) throws DeploymentException {
-//            ObjectName configName;
-//            try {
-//                configName = Configuration.getConfigurationObjectName(configID);
-//            } catch (InvalidConfigException e) {
-//                throw new DeploymentException("Cannot convert ID to ObjectName: ", e);
-//            }
-//            try {
-//                Environment environment = (Environment) kernel.getAttribute(configName, "environment");
-//                return environment.getImports();
-//            } catch (Exception e) {
-//                throw new DeploymentException("Cannot find parents of alleged config: ", e);
-//            }
-//        }
-//
-//    }
+    public ClassLoader getClassLoader() throws DeploymentException {
+        return configuration.getConfigurationClassLoader();
+    }
 
-    private void setupParents() throws DeploymentException {
-        if (kernel != null) {
+    public Configuration getConfiguration(Configuration knownParent) {
+        return configuration;
+    }
+
+    public void close() throws IOException, DeploymentException {
+        if (configurationManager != null) {
             try {
-                List dependencies = new ArrayList(environment.getDependencies());
-                for (ListIterator iterator = dependencies.listIterator(); iterator.hasNext();) {
-                    Dependency dependency = (Dependency) iterator.next();
-                    Artifact resolvedArtifact = artifactResolver.resolve(dependency.getArtifact());
-                    if (configurationManager != null && configurationManager.isConfiguration(resolvedArtifact)) {
-                        configurationManager.loadConfiguration(resolvedArtifact);
-
-                        // update the dependency list to contain the resolved artifact
-                        dependency = new Dependency(resolvedArtifact, dependency.getImportType());
-                        iterator.set(dependency);
-                    } else if (dependency.getImportType() == ImportType.SERVICES) {
-                        // Service depdendencies require that the depdencency be a configuration
-                        if (configurationManager == null) throw new NullPointerException("configurationManager is null");
-                        throw new DeploymentException("Dependency does not have services: " + resolvedArtifact);
-                    }
-                }
-                environment.setDependencies(dependencies);
-            } catch (DeploymentException e) {
-                throw e;
-            } catch (Exception e) {
-                throw new DeploymentException("Unable to load parents", e);
+                configurationManager.unloadConfiguration(configuration);
+            } catch (NoSuchConfigException ignored) {
             }
         }
     }
 
-    public ClassLoader getClassLoader() throws DeploymentException {
-        return getConfiguration(null).getConfigurationClassLoader();
+    public void addChildConfiguration(ConfigurationData configurationData) {
+        childConfigurationDatas.add(configurationData);
     }
 
-    public ClassLoader getClassLoader(Configuration knownParent) throws DeploymentException {
-        return getConfiguration(knownParent).getConfigurationClassLoader();
+    public ConfigurationData getConfigurationData() {
+        //
+        // DO NOT use the environment in the configuration, it is modifed by the configuration
+        //
+        ConfigurationData configurationData = new ConfigurationData(configuration.getModuleType(),
+                new LinkedHashSet(configuration.getClassPath()),
+                new ArrayList(configuration.getGBeans().values()),
+                childConfigurationDatas,
+                environment,
+                baseDir);
+        return configurationData;
     }
 
-    public Configuration getConfiguration(Configuration knownParent) throws DeploymentException {
-        Environment environmentCopy = new Environment(environment);
-        if (knownParent != null) {
-            environmentCopy.addDependency(knownParent.getId(), ImportType.ALL);
+    private static class DeploymentContextConfigurationStore implements ConfigurationStore {
+        private final File baseDir;
+
+        public DeploymentContextConfigurationStore(File baseDir) {
+            this.baseDir = baseDir;
         }
-        try {
-            List parents = createParentProxies(environmentCopy, knownParent);
-            Configuration configuration = new Configuration(parents,
-                    Configuration.getConfigurationObjectName(environmentCopy.getConfigId()).getCanonicalName(),
-                    moduleType,
-                    environmentCopy,
-                    new ArrayList(classpath),
-                    null,
-                    repositories,
-                    new ConfigurationStore() {
-
-                        public void install(ConfigurationData configurationData) {
-                        }
-
-                        public void uninstall(Artifact configID) {
-                        }
-
-                        public GBeanData loadConfiguration(Artifact configId) {
-                            return null;
-                        }
-
-                        public boolean containsConfiguration(Artifact configID) {
-                            return false;
-                        }
-
-                        public String getObjectName() {
-                            return null;
-                        }
-
-                        public List listConfigurations() {
-                            return null;
-                        }
-
-                        public File createNewConfigurationDir(Artifact configId) {
-                            return null;
-                        }
-
-                        public URL resolve(Artifact configId, URI uri) throws MalformedURLException {
-                            return new File(baseDir, uri.toString()).toURL();
-                        }
-                    },
-                    null,
-                    null);
-            return configuration;
-        } catch (Exception e) {
-            throw new DeploymentException("Could not construct configuration classloader for deployment context", e);
+
+        public void install(ConfigurationData configurationData) {
         }
-    }
 
-    private List createParentProxies(Environment environment, Configuration existingConfiguration) throws InvalidConfigException {
-        List parents = new ArrayList();
-        try {
-            List dependencies = new ArrayList(environment.getDependencies());
-            for (ListIterator iterator = dependencies.listIterator(); iterator.hasNext();) {
-                Dependency dependency = (Dependency) iterator.next();
-                Artifact resolvedArtifact = artifactResolver.resolve(dependency.getArtifact());
-                if (configurationManager != null && isConfiguration(resolvedArtifact, existingConfiguration)) {
-                    // add the parent configuration to the parents collection
-                    Configuration parent = getLoadedConfiguration(resolvedArtifact, existingConfiguration);
-                    parents.add(parent);
-
-                    // update the dependency list to contain the resolved artifact
-                    dependency = new Dependency(resolvedArtifact, dependency.getImportType());
-                    iterator.set(dependency);
-                } else if (dependency.getImportType() == ImportType.SERVICES) {
-                    // Service depdendencies require that the depdencency be a configuration
-                    if (configurationManager == null) throw new NullPointerException("configurationManager is null");
-                    throw new InvalidConfigException("Dependency does not have services: " + resolvedArtifact);
-                }
-            }
-            environment.setDependencies(dependencies);
-        } catch (InvalidConfigException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new InvalidConfigException("Unable to load parents", e);
+        public void uninstall(Artifact configID) {
         }
-        return parents;
-    }
 
-    private boolean isConfiguration(Artifact artifact, Configuration existingConfiguration) {
-        if (configurationManager.isConfiguration(artifact)) {
-            return true;
+        public GBeanData loadConfiguration(Artifact configId) {
+            return null;
         }
-        return existingConfiguration != null && artifact.equals(existingConfiguration.getId());
-    }
 
-    private Configuration getLoadedConfiguration(Artifact artifact, Configuration existingConfiguration) {
-        if (existingConfiguration != null && artifact.equals(existingConfiguration.getId())) {
-            return existingConfiguration;
-        } else {
-            return configurationManager.getConfiguration(artifact);
+        public boolean containsConfiguration(Artifact configID) {
+            return false;
         }
-    }
 
-    public void close() throws IOException, DeploymentException {
-        if (kernel != null) {
-            ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
-            try {
-//                startedAncestors.clear();
-                //TODO configid WE NEED REFERENCE COUNTING ON THIS STUFF!!!
-                //right now it is impossible to deploy 2 app clients in an ear. 
-//                Collections.reverse(loadedAncestors);
-/*
-                for (Iterator iterator = loadedAncestors.iterator(); iterator.hasNext();) {
-                    Artifact configID = (Artifact) iterator.next();
-                    if (configurationManager.isLoaded(configID)) {
-                        try {
-                            configurationManager.unload(configID);
-                        } catch (NoSuchConfigException e) {
-                            throw new DeploymentException("Could not find a configuration we previously loaded! " + configID, e);
-                        }
-                    }
-                }
-*/
-                for (Iterator iterator = loadedConfigurations.iterator(); iterator.hasNext();) {
-                    Artifact artifact = (Artifact) iterator.next();
-                    try {
-                        configurationManager.unloadConfiguration(artifact);
-                    } catch (NoSuchConfigException ignored) {
-                    }
-                }
-                loadedConfigurations.clear();
-            } finally {
-                ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
-            }
+        public String getObjectName() {
+            return null;
         }
-    }
 
-    public void addChildConfiguration(ConfigurationData configurationData) {
-        childConfigurationDatas.add(configurationData);
-    }
+        public List listConfigurations() {
+            return null;
+        }
 
-    public ConfigurationData getConfigurationData() {
-        ConfigurationData configurationData = new ConfigurationData(moduleType, classpath, Arrays.asList(gbeans.getGBeans()), childConfigurationDatas, environment, baseDir);
-        return configurationData;
-    }
+        public File createNewConfigurationDir(Artifact configId) {
+            return null;
+        }
 
-    public Object getAttribute(ObjectName name, String property) throws Exception {
-        return kernel.getAttribute(name, property);
+        public URL resolve(Artifact configId, URI uri) throws MalformedURLException {
+            return new File(baseDir, uri.toString()).toURL();
+        }
     }
 }

Modified: geronimo/branches/1.1/modules/deployment/src/test/org/apache/geronimo/deployment/DeploymentContextTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deployment/src/test/org/apache/geronimo/deployment/DeploymentContextTest.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deployment/src/test/org/apache/geronimo/deployment/DeploymentContextTest.java (original)
+++ geronimo/branches/1.1/modules/deployment/src/test/org/apache/geronimo/deployment/DeploymentContextTest.java Sat Mar 11 17:34:04 2006
@@ -21,19 +21,35 @@
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.MethodInterceptor;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+import org.apache.geronimo.kernel.config.EditableConfigurationManagerImpl;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationResolver;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
+import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelFactory;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.AbstractName;
 
 import javax.sql.DataSource;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Hashtable;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384686 $ $Date$
  */
 public class DeploymentContextTest extends TestCase {
     private byte[] classBytes;
@@ -45,11 +61,18 @@
         try {
             basedir.deleteOnExit();
             Environment environment = new Environment();
-            environment.setConfigId(new Artifact("foo", "artifact", "1", "car"));
+            Artifact configId = new Artifact("foo", "artifact", "1", "car");
+            environment.setConfigId(configId);
             Map nameKeys = new HashMap();
             nameKeys.put("domain", "d");
             environment.setProperties(nameKeys);
-            DeploymentContext context = new DeploymentContext(basedir, environment, ConfigurationModuleType.CAR, null, null);
+            Configuration configuration = new Configuration(null,
+                    ConfigurationModuleType.CAR,
+                    environment,
+                    null,
+                    null,
+                    new ConfigurationResolver(configId, basedir));
+            DeploymentContext context = new DeploymentContext(configuration, basedir);
             Enhancer enhancer = new Enhancer();
             enhancer.setInterfaces(new Class[]{DataSource.class});
             enhancer.setCallbackType(MethodInterceptor.class);

Modified: geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java (original)
+++ geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java Sat Mar 11 17:34:04 2006
@@ -34,6 +34,7 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.j2ee.management.impl.J2EEApplicationImpl;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.config.ConfigurationData;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
@@ -44,7 +45,6 @@
 import org.apache.geronimo.schema.SchemaConversionUtils;
 import org.apache.geronimo.security.deployment.SecurityBuilder;
 import org.apache.geronimo.security.deployment.SecurityConfiguration;
-import org.apache.geronimo.security.jacc.ApplicationPolicyConfigurationManager;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerApplicationDocument;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerApplicationType;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerExtModuleType;
@@ -55,7 +55,6 @@
 import org.apache.xmlbeans.XmlObject;
 
 import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
 import javax.xml.namespace.QName;
 import java.io.File;
 import java.io.IOException;
@@ -75,7 +74,7 @@
 import java.util.zip.ZipEntry;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384686 $ $Date$
  */
 public class EARConfigBuilder implements ConfigurationBuilder {
 
@@ -305,7 +304,6 @@
                 earContext = new EARContext(configurationDir,
                         applicationInfo.getEnvironment(),
                         applicationType,
-                        Collections.singleton(repository),
                         kernel,
                         applicationInfo.getApplicationName(),
                         transactionContextManagerObjectName,
@@ -393,6 +391,8 @@
             }
             earContext.close();
             return earContext.getConfigurationData();
+        } catch (GBeanAlreadyExistsException e) {
+            throw new DeploymentException(e);
         } finally {
             Set modules = applicationInfo.getModules();
             for (Iterator iterator = modules.iterator(); iterator.hasNext();) {

Modified: geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java (original)
+++ geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java Sat Mar 11 17:34:04 2006
@@ -32,7 +32,7 @@
 import org.apache.geronimo.security.deployment.SecurityConfiguration;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384686 $ $Date$
  */
 public class EARContext extends DeploymentContext implements NamingContext {
     private final AbstractName domainObjectName;
@@ -54,8 +54,8 @@
     private AbstractName jaccManagerName;
     private SecurityConfiguration securityConfiguration;
 
-    public EARContext(File baseDir, Environment environment, ConfigurationModuleType moduleType, Collection repositories, Kernel kernel, String j2eeApplicationName, AbstractName transactionContextManagerObjectName, AbstractName connectionTrackerObjectName, AbstractName transactedTimerName, AbstractName nonTransactedTimerName, AbstractName corbaGBeanObjectName, RefContext refContext) throws MalformedObjectNameException, DeploymentException {
-        super(baseDir, environment, moduleType, repositories, kernel);
+    public EARContext(File baseDir, Environment environment, ConfigurationModuleType moduleType, Kernel kernel, String j2eeApplicationName, AbstractName transactionContextManagerObjectName, AbstractName connectionTrackerObjectName, AbstractName transactedTimerName, AbstractName nonTransactedTimerName, AbstractName corbaGBeanObjectName, RefContext refContext) throws MalformedObjectNameException, DeploymentException {
+        super(baseDir, environment, moduleType, kernel);
         if (moduleType.equals(ConfigurationModuleType.EAR)) {
             moduleName = NameFactory.buildApplicationName(environment.getProperties(), environment.getConfigId());
             applicationName = moduleName;

Modified: geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/NamingContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/NamingContext.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/NamingContext.java (original)
+++ geronimo/branches/1.1/modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/NamingContext.java Sat Mar 11 17:34:04 2006
@@ -20,18 +20,19 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.repository.Artifact;
 
 import java.util.Set;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384933 $ $Date$
  */
 public interface NamingContext {
 
     AbstractName getModuleName();
 
-    void addGBean(GBeanData gbean);
+    void addGBean(GBeanData gbean) throws GBeanAlreadyExistsException;
 
     Set getGBeanNames();
 

Modified: geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java Sat Mar 11 17:34:04 2006
@@ -82,7 +82,7 @@
 import org.apache.geronimo.transaction.manager.TransactionManagerImplGBean;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 384933 $ $Date$
  */
 public class JettyModuleBuilderTest extends TestCase {
     private String DOMAIN_NAME = "geronimo.test";
@@ -160,7 +160,6 @@
         EARContext earContext = new EARContext(outputPath,
                 environment,
                 ConfigurationModuleType.WAR,
-                null,
                 kernel,
                 moduleContext.getJ2eeApplicationName(),
                 tcmName,

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=385232&r1=385231&r2=385232&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 Sat Mar 11 17:34:04 2006
@@ -38,34 +38,27 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.gbean.ReferencePatterns;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GReferenceInfo;
-import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.ObjectInputStreamExt;
 import org.apache.geronimo.kernel.jmx.JMXUtil;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.ArtifactManager;
-import org.apache.geronimo.kernel.repository.ArtifactResolver;
-import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
 import org.apache.geronimo.kernel.repository.Dependency;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
-import org.apache.geronimo.kernel.repository.Repository;
 
 /**
  * A Configuration represents a collection of runnable services that can be
@@ -94,7 +87,7 @@
  * 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 $Rev$ $Date$
+ * @version $Rev: 384999 $ $Date$
  */
 public class Configuration implements GBeanLifecycle, ConfigurationParent {
     private static final Log log = LogFactory.getLog(Configuration.class);
@@ -132,17 +125,14 @@
         }
     }
 
-    private final ConfigurationStore configurationStore;
-
     /**
      * The artifact id for this configuration.
      */
     private final Artifact id;
 
     /**
-     * The registered objectName for this configuraion.
+     * The registered abstractName for this configuraion.
      */
-    private final ObjectName objectName;
     private final AbstractName abstractName;
     /**
      * Defines the environment requred for this configuration.
@@ -153,6 +143,7 @@
      * Identifies the type of configuration (WAR, RAR et cetera)
      */
     private final ConfigurationModuleType moduleType;
+    private final ConfigurationResolver configurationResolver;
 
     /**
      * Parent configurations used for class loader.
@@ -172,7 +163,7 @@
     /**
      * Artifacts added to the class loader (non-configuation artifacts).
      */
-    private final LinkedHashSet dependencies;
+    private final LinkedHashSet dependencies = new LinkedHashSet();
 
     /**
      * The GBeanData objects by ObjectName
@@ -185,29 +176,21 @@
     private final MultiParentClassLoader configurationClassLoader;
 
     /**
-     * The repositories used dependencies.
+     * The relative class path (URI) of this configuation.
      */
-    private final Collection repositories;
-
-    /**
-     * The artifact manager in which loaded artifacts are registered.
-     */
-    private final ArtifactManager artifactManager;
+    private final LinkedHashSet classPath;
 
     /**
      * Only used to allow declaration as a reference.
      */
     public Configuration() {
-        environment = null;
-        configurationStore = null;
         id = null;
-        objectName = null;
         abstractName = null;
         moduleType = null;
-        dependencies = null;
+        environment = null;
+        classPath = null;
+        configurationResolver = null;
         configurationClassLoader = null;
-        repositories = null;
-        artifactManager = null;
     }
 
     /**
@@ -217,35 +200,30 @@
      * @param environment
      * @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
-     * @param repositories a Collection<Repository> of repositories used to resolve dependencies
      */
-    public Configuration(Collection parents, String objectName, ConfigurationModuleType moduleType, Environment environment, List classPath, byte[] gbeanState, Collection repositories, ConfigurationStore configurationStore, ArtifactManager artifactManager, ArtifactResolver artifactResolver) throws MissingDependencyException, MalformedURLException, NoSuchConfigException, InvalidConfigException {
+    public Configuration(Collection parents, /*String objectName, */ConfigurationModuleType moduleType, Environment environment, List classPath, byte[] gbeanState, ConfigurationResolver configurationResolver/*, Collection repositories, ConfigurationStore configurationStore, ArtifactManager artifactManager, ArtifactResolver artifactResolver*/) throws MissingDependencyException, MalformedURLException, NoSuchConfigException, InvalidConfigException {
+        if (parents == null) parents = Collections.EMPTY_SET;
+        if (moduleType == null) throw new NullPointerException("moduleType is null");
+        if (environment == null) throw new NullPointerException("environment is null");
+        if (classPath == null) classPath = Collections.EMPTY_LIST;
+        if (configurationResolver == null) throw new NullPointerException("configurationResolver is null");
+
         this.environment = environment;
         this.moduleType = moduleType;
-        this.repositories = repositories;
-        this.configurationStore = configurationStore;
-        this.artifactManager = artifactManager;
+        this.configurationResolver = configurationResolver;
+        this.classPath = new LinkedHashSet(classPath);
 
         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() + ">");
-        }
         abstractName = getConfigurationAbstractName(id);
 
         //
-        // Resolve all artifacts in the environment
+        // Transitively resolve all the dependencies in the environment
         //
-        if (artifactResolver == null) {
-            artifactResolver = new DefaultArtifactResolver(artifactManager, repositories);
-        }
-        environment.setDependencies(resolveDependencies(artifactResolver, parents, environment.getDependencies()));
+        List transtiveDependencies = configurationResolver.resolveTransitiveDependencies(parents, environment.getDependencies());
+        environment.setDependencies(transtiveDependencies);
 
         //
-        // Process environment splitting it into classParents, serviceParents and artifactDependencies
+        // Process transtive dependencies splitting it into classParents, serviceParents and artifactDependencies
         //
         if (parents == null) parents = Collections.EMPTY_SET;
         Map parentsById = new HashMap();
@@ -255,8 +233,7 @@
             parentsById.put(id, configuration);
         }
 
-        LinkedHashSet dependencies = new LinkedHashSet();
-        for (Iterator iterator = environment.getDependencies().iterator(); iterator.hasNext();) {
+        for (Iterator iterator = transtiveDependencies.iterator(); iterator.hasNext();) {
             Dependency dependency = (Dependency) iterator.next();
             Artifact artifact = dependency.getArtifact();
             if (parentsById.containsKey(artifact)) {
@@ -275,11 +252,6 @@
         }
 
         //
-        // recursively resolve the artifact dependencies
-        //
-        this.dependencies = recursiveResolve(parents, artifactResolver, dependencies);
-
-        //
         // Propagate non-overridable classes from class parents
         //
         for (Iterator iterator = classParents.iterator(); iterator.hasNext();) {
@@ -341,43 +313,6 @@
                 Thread.currentThread().setContextClassLoader(oldCl);
             }
         }
-
-        //
-        // Preprocess all of the GBeans resolving the singleton-references, dependencies, and setting a few configuration specific attributes
-        //
-        for (Iterator iterator = gbeans.values().iterator(); iterator.hasNext();) {
-            GBeanData gbeanData = (GBeanData) iterator.next();
-            preprocessGBeanData(gbeanData);
-        }
-    }
-
-    private List resolveDependencies(ArtifactResolver artifactResolver, Collection parents, List dependencies) throws MissingDependencyException {
-        List resolvedDependencies = new ArrayList();
-        for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) {
-            Dependency dependency =  (Dependency) iterator.next();
-            Artifact artifact = dependency.getArtifact();
-            artifact = artifactResolver.resolve(parents, artifact);
-            resolvedDependencies.add(new Dependency(artifact, dependency.getImportType()));
-        }
-        return resolvedDependencies;
-    }
-
-    private LinkedHashSet recursiveResolve(Collection parents, ArtifactResolver artifactResolver, LinkedHashSet dependencies) throws MissingDependencyException {
-        dependencies = artifactResolver.resolve(parents, dependencies);
-        for (Iterator iterator = new ArrayList(dependencies).iterator(); iterator.hasNext();) {
-            Artifact dependency = (Artifact) iterator.next();
-            for (Iterator iterator1 = repositories.iterator(); iterator1.hasNext();) {
-                Repository repository = (Repository) iterator1.next();
-                if (repository.contains(dependency)) {
-                    LinkedHashSet subDependencies = repository.getDependencies(dependency);
-                    if (!subDependencies.isEmpty()) {
-                        subDependencies = recursiveResolve(parents, artifactResolver, subDependencies);
-                        dependencies.addAll(subDependencies);
-                    }
-                }
-            }
-        }
-        return dependencies;
     }
 
     private void getDepthFirstServiceParents(Configuration configuration, List ancestors) {
@@ -392,23 +327,13 @@
         List urls = new ArrayList();
         for (Iterator i = dependencies.iterator(); i.hasNext();) {
             Artifact artifact = (Artifact) i.next();
-            File file = null;
-            for (Iterator j = repositories.iterator(); j.hasNext();) {
-                Repository repository = (Repository) j.next();
-                if (repository.contains(artifact)) {
-                    file = repository.getLocation(artifact);
-                    break;
-                }
-            }
-            if (file == null) {
-                throw new MissingDependencyException("Unable to resolve dependency " + artifact);
-            }
+            File file = configurationResolver.resolve(artifact);
             urls.add(file.toURL());
         }
         if (classPath != null) {
             for (Iterator i = classPath.iterator(); i.hasNext();) {
                 URI uri = (URI) i.next();
-                urls.add(configurationStore.resolve(id, uri));
+                urls.add(configurationResolver.resolve(uri));
             }
         }
         return (URL[]) urls.toArray(new URL[urls.size()]);
@@ -427,7 +352,11 @@
      * @return the unique name of this configuration
      */
     public String getObjectName() {
-        return objectName.getCanonicalName();
+        try {
+            return getConfigurationObjectName(id).getCanonicalName();
+        } catch (InvalidConfigException e) {
+            throw new AssertionError(e);
+        }
     }
 
     public AbstractName getAbstractName() {
@@ -472,6 +401,34 @@
     }
 
     /**
+     * @deprecated this is only exposed temporarily for configuration manager
+     */
+    public ConfigurationResolver getConfigurationResolver() {
+        return configurationResolver;
+    }
+
+    /**
+     * Gets the relative class path (URIs) of this configuration.
+     * @return the relative class path of this configuation
+     */
+    public List getClassPath() {
+        return new ArrayList(classPath);
+    }
+
+    public void addToClassPath(URI path) throws IOException {
+        if (!classPath.contains(path)) {
+            try {
+                configurationResolver.resolve(path);
+                URL url = configurationResolver.resolve(path);
+                configurationClassLoader.addURL(url);
+                classPath.add(path);
+            } catch (Exception e) {
+                throw new IOException("Unable to extend classpath with " + path);
+            }
+        }
+    }
+
+    /**
      * Gets the type of the configuration (WAR, RAR et cetera)
      * @return Type of the configuration.
      */
@@ -487,10 +444,6 @@
         return configurationClassLoader;
     }
 
-    public ConfigurationStore getConfigurationStore() {
-        return configurationStore;
-    }
-
     /**
      * Gets an unmodifiable collection of the GBeanDatas for the GBeans in this configuration.
      * @return the GBeans in this configuration
@@ -508,11 +461,10 @@
         return gbeans.containsKey(gbean);
     }
 
-    public synchronized void addGBean(GBeanData gbean) throws InvalidConfigException, GBeanAlreadyExistsException {
+    public synchronized void addGBean(GBeanData gbean) throws GBeanAlreadyExistsException {
         if (gbeans.containsKey(gbean.getAbstractName())) {
             throw new GBeanAlreadyExistsException(gbean.getName().getCanonicalName());
         }
-        preprocessGBeanData(gbean);
         gbeans.put(gbean.getAbstractName(), gbean);
     }
 
@@ -523,55 +475,6 @@
         gbeans.remove(name);
     }
 
-    private void preprocessGBeanData(GBeanData gbeanData) throws InvalidConfigException {
-        for (Iterator references = gbeanData.getReferencesNames().iterator(); references.hasNext();) {
-            String referenceName = (String) references.next();
-            GReferenceInfo referenceInfo = gbeanData.getGBeanInfo().getReference(referenceName);
-            if (referenceInfo == null) {
-                throw new InvalidConfigException("No reference named " + referenceName + " in gbean " + gbeanData.getAbstractName());
-            }
-            boolean isSingleValued = !referenceInfo.getProxyType().equals(Collection.class.getName());
-            if (isSingleValued) {
-                ReferencePatterns referencePatterns = gbeanData.getReferencePatterns(referenceName);
-                AbstractName abstractName = null;
-                try {
-                    abstractName = findGBean(referencePatterns);
-                } catch (GBeanNotFoundException e) {
-                    throw new InvalidConfigException("Unable to resolve reference named " + referenceName + " in gbean " + gbeanData.getAbstractName(), e);
-                }
-                gbeanData.setReferencePatterns(referenceName, new ReferencePatterns(abstractName));
-            }
-        }
-
-        Set newDependencies = new HashSet();
-        for (Iterator dependencyIterator = gbeanData.getDependencies().iterator(); dependencyIterator.hasNext();) {
-            ReferencePatterns referencePatterns = (ReferencePatterns) dependencyIterator.next();
-            AbstractName abstractName = null;
-            try {
-                abstractName = findGBean(referencePatterns);
-            } catch (GBeanNotFoundException e) {
-                throw new InvalidConfigException("Unable to resolve dependency in gbean " + gbeanData.getAbstractName(), e);
-            }
-            newDependencies.add(new ReferencePatterns(abstractName));
-        }
-        gbeanData.setDependencies(newDependencies);
-
-        // 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")) {
-            try {
-                URL baseURL = configurationStore.resolve(id, URI.create(""));
-                gbeanData.setAttribute("configurationBaseUrl", baseURL);
-            } catch (Exception e) {
-                throw new InvalidConfigException("Unable to set attribute named " + "configurationBaseUrl" + " in gbean " + gbeanData.getAbstractName(), e);
-            }
-        }
-
-        // add a dependency from the gbean to the configuration
-        gbeanData.addDependency(abstractName);
-    }
-
     public AbstractName findGBean(AbstractNameQuery pattern) throws GBeanNotFoundException {
         return findGBean(Collections.singleton(pattern));
     }
@@ -588,32 +491,67 @@
     }
 
     public AbstractName findGBean(Set patterns) throws GBeanNotFoundException {
-        AbstractName result = resolve(this, patterns);
-        if (result != null) {
-            return result;
+        Set result = findGBeans(this, patterns);
+        if (result.size() > 1) {
+            throw new GBeanNotFoundException("More than one match to referencePatterns", patterns);
+        } else if (result.size() == 1) {
+            return (AbstractName) result.iterator().next();
         }
 
         // search all parents
         for (Iterator iterator = allServiceParents.iterator(); iterator.hasNext();) {
             Configuration configuration = (Configuration) iterator.next();
-            AbstractName match = resolve(configuration, patterns);
+            Set match = findGBeans(configuration, patterns);
 
             // if we already found a match we have an ambiguous query
-            if (result != null) {
-                throw new GBeanNotFoundException("More than one match for referencePatterns", patterns);
+            if (match.size() > 1) {
+                throw new GBeanNotFoundException("More than one match to referencePatterns", patterns);
+            } else if (match.size() == 1) {
+                return (AbstractName) result.iterator().next();
             }
             result = match;
         }
 
-        if (result == null) {
+        if (result.isEmpty()) {
             throw new GBeanNotFoundException("No matches for referencePatterns", patterns);
         }
 
+        return (AbstractName) result.iterator().next();
+    }
+
+    public LinkedHashSet findGBeans(AbstractNameQuery pattern) {
+        if (pattern == null) throw new NullPointerException("pattern is null");
+        return findGBeans(Collections.singleton(pattern));
+    }
+
+    public LinkedHashSet findGBeans(ReferencePatterns referencePatterns) {
+        if (referencePatterns.getAbstractName() != null) {
+            // this pattern is already resolved
+            LinkedHashSet result = new LinkedHashSet();
+            result.add(referencePatterns.getAbstractName());
+            return result;
+        }
+
+        // check the local config
+        Set patterns = referencePatterns.getPatterns();
+        return findGBeans(patterns);
+    }
+
+    public LinkedHashSet findGBeans(Set patterns) {
+        LinkedHashSet result = findGBeans(this, patterns);
+
+        // search all parents
+        for (Iterator iterator = allServiceParents.iterator(); iterator.hasNext();) {
+            Configuration configuration = (Configuration) iterator.next();
+            Set match = findGBeans(configuration, patterns);
+            result.addAll(match);
+        }
+
         return result;
     }
 
-    private AbstractName resolve(Configuration configuration, Set patterns) throws GBeanNotFoundException {
-        AbstractName result = null;
+    private LinkedHashSet findGBeans(Configuration configuration, Set patterns) {
+        LinkedHashSet result = new LinkedHashSet();
 
         Set gbeanNames = configuration.getGBeans().keySet();
         for (Iterator abstractNameQueries = patterns.iterator(); abstractNameQueries.hasNext();) {
@@ -627,11 +565,7 @@
                 for (Iterator iterator = gbeanNames.iterator(); iterator.hasNext();) {
                     AbstractName abstractName = (AbstractName) iterator.next();
                     if (abstractNameQuery.matches(abstractName)) {
-                        // if we already found a match we have an ambiguous query
-                        if (result != null ) {
-                            throw new GBeanNotFoundException("More than one match to referencePatterns", patterns);
-                        }
-                        result = abstractName;
+                        result.add(abstractName);
                     }
                 }
             }
@@ -640,13 +574,6 @@
     }
 
     public void doStart() throws Exception {
-        assert objectName != null;
-
-        // declare the artifacts as loaded
-        if (artifactManager != null) {
-            artifactManager.loadArtifacts(id, dependencies);
-        }
-
         log.debug("Started configuration " + id);
     }
 
@@ -669,11 +596,6 @@
         if (configurationClassLoader != null) {
             configurationClassLoader.destroy();
         }
-
-        // declare all artifacts as unloaded
-        if (artifactManager != null) {
-            artifactManager.unloadAllArtifacts(id);
-        }
     }
 
     /**
@@ -722,35 +644,22 @@
 
     static {
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Configuration.class);//does not use jsr-77 naming
-        infoFactory.addAttribute("objectName", String.class, false);
-        infoFactory.addAttribute("environment", Environment.class, true, false);
+        infoFactory.addReference("Parents", Configuration.class);
         infoFactory.addAttribute("type", ConfigurationModuleType.class, true, false);
+        infoFactory.addAttribute("environment", Environment.class, true, false);
         infoFactory.addAttribute("classPath", List.class, true, false);
         infoFactory.addAttribute("gBeanState", byte[].class, true, false);
-        infoFactory.addAttribute("configurationClassLoader", ClassLoader.class, false);
-        //make id readable for convenience
-        infoFactory.addAttribute("id", Artifact.class, false);
-        //NOTE THESE IS NOT REFERENCES
-        infoFactory.addAttribute("configurationStore", ConfigurationStore.class, true);
-        infoFactory.addAttribute("artifactManager", ArtifactManager.class, true);
-        infoFactory.addAttribute("artifactResolver", ArtifactResolver.class, true);
-
-        infoFactory.addReference("Parents", Configuration.class);
-        infoFactory.addReference("Repositories", Repository.class, "Repository");
+        infoFactory.addAttribute("configurationResolver", ConfigurationResolver.class, true);
 
         infoFactory.addInterface(Configuration.class);
 
         infoFactory.setConstructor(new String[]{
                 "Parents",
-                "objectName",
                 "type",
                 "environment",
                 "classPath",
                 "gBeanState",
-                "Repositories",
-                "configurationStore",
-                "artifactManager",
-                "artifactResolver"
+                "configurationResolver",
         });
 
         GBEAN_INFO = infoFactory.getBeanInfo();

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationData.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationData.java?rev=385232&r1=385231&r2=385232&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationData.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationData.java Sat Mar 11 17:34:04 2006
@@ -27,7 +27,7 @@
 import java.io.File;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 382645 $ $Date$
  */
 public class ConfigurationData {
 
@@ -63,6 +63,7 @@
         } else {
             this.classPath = new LinkedHashSet();
         }
+        if (gbeans == null) gbeans = Collections.EMPTY_LIST;
         this.gbeans = gbeans;
         this.childConfigurations = childConfigurations;
         this.environment = environment;



Mime
View raw message