geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r386907 [2/2] - in /geronimo/branches/1.1/modules: jetty-builder/src/java/org/apache/geronimo/jetty/deployment/ jetty-builder/src/test-resources/deployables/war5/WEB-INF/ jetty-builder/src/test-resources/plans/ jetty-builder/src/test/org/ap...
Date Sun, 19 Mar 2006 00:52:42 GMT
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java?rev=386907&r1=386906&r2=386907&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
Sat Mar 18 16:52:38 2006
@@ -16,21 +16,14 @@
  */
 package org.apache.geronimo.kernel.config;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import javax.management.ObjectName;
-
 import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanQuery;
+import org.apache.geronimo.gbean.GReferenceInfo;
+import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.management.State;
@@ -38,8 +31,23 @@
 import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.repository.Environment;
 
+import javax.management.ObjectName;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
 /**
- * @version $Rev: 384351 $ $Date$
+ * @version $Rev:386276 $ $Date$
  */
 public final class ConfigurationUtil {
     private ConfigurationUtil() {
@@ -63,39 +71,28 @@
         return loadBootstrapConfiguration(kernel, configuration, classLoader);
     }
 
-    private static AbstractName loadBootstrapConfiguration(Kernel kernel, GBeanData configuration,
ClassLoader classLoader) throws Exception {
-        Environment environment = (Environment) configuration.getAttribute("environment");
+    private static AbstractName loadBootstrapConfiguration(Kernel kernel, GBeanData configurationGBeanData,
ClassLoader classLoader) throws Exception {
+        Environment environment = (Environment) configurationGBeanData.getAttribute("environment");
         Artifact configId = environment.getConfigId();
         AbstractName configurationName = Configuration.getConfigurationAbstractName(configId);
-        configuration.setAbstractName(configurationName);
-        configuration.setAttribute("naming", kernel.getNaming());
+        configurationGBeanData.setAbstractName(configurationName);
+        configurationGBeanData.setAttribute("naming", kernel.getNaming());
 
         // for a bootstrap we should have an empty kernel, so clear the references and dependencies
-        configuration.setAttribute("artifactManager", null);
-        configuration.setAttribute("artifactResolver", null);
+        configurationGBeanData.setAttribute("artifactManager", null);
+        configurationGBeanData.setAttribute("artifactResolver", null);
         environment.setDependencies(Collections.EMPTY_LIST);
 
         // load and start the gbean
-        kernel.loadGBean(configuration, classLoader);
+        kernel.loadGBean(configurationGBeanData, classLoader);
         kernel.startGBean(configurationName);
 
+        Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(configurationName,
Configuration.class);
+
         // get the gbeans and classloader
-        Map gbeans = (Map) kernel.getAttribute(configurationName, "GBeans");
-        ClassLoader configurationClassLoader = (ClassLoader) kernel.getAttribute(configurationName,
"configurationClassLoader");
+        Collection gbeans = configuration.getGBeans().values();
 
-        // register all the GBeans
-        for (Iterator i = gbeans.values().iterator(); i.hasNext();) {
-            GBeanData gbeanData = (GBeanData) i.next();
-            gbeanData.addDependency(configurationName);
-
-            // load the gbean into the kernel
-            kernel.loadGBean(gbeanData, configurationClassLoader);
-
-            // start the gbean
-            if (kernel.isGBeanEnabled(gbeanData.getName())) {
-                kernel.startRecursiveGBean(gbeanData.getName());
-            }
-        }
+        startConfigurationGBeans(gbeans, configuration, kernel);
 
         ConfigurationManager configurationManager = getConfigurationManager(kernel);
         configurationManager.loadConfiguration(configId);
@@ -117,6 +114,7 @@
                 try {
                     objectOutputStream.flush();
                 } catch (IOException ignored) {
+                    //TODO really?
                 }
             }
         }
@@ -150,7 +148,6 @@
      * Gets a reference or proxy to the ConfigurationManager running in the specified kernel.
      *
      * @return The ConfigurationManager
-     *
      * @throws IllegalStateException Occurs if a ConfigurationManager cannot be identified
      */
     public static ConfigurationManager getConfigurationManager(Kernel kernel) {
@@ -180,7 +177,6 @@
      * Gets a reference or proxy to an EditableConfigurationManager running in the specified
kernel, if there is one.
      *
      * @return The EdtiableConfigurationManager, or none if there is not one available.
-     *
      * @throws IllegalStateException Occurs if there are multiple EditableConfigurationManagers
in the kernel.
      */
     public static EditableConfigurationManager getEditableConfigurationManager(Kernel kernel)
{
@@ -208,5 +204,95 @@
 
     public static void releaseConfigurationManager(Kernel kernel, ConfigurationManager configurationManager)
{
         kernel.getProxyManager().destroyProxy(configurationManager);
+    }
+
+    static void preprocessGBeanData(Configuration configuration, 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;
+                try {
+                    abstractName = configuration.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;
+            try {
+                abstractName = configuration.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 = configuration.getConfigurationResolver().resolve(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(configuration.getAbstractName());
+    }
+
+    static void startConfigurationGBeans(Collection gbeans, Configuration configuration,
Kernel kernel) throws InvalidConfigException {
+        // register all the GBeans
+        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);
+
+            // preprocess the gbeanData (resolve references, set base url, declare dependency,
etc.)
+            preprocessGBeanData(configuration, gbeanData);
+//            log.trace("Registering GBean " + gbeanData.getName());
+
+            try {
+                kernel.loadGBean(gbeanData, configuration.getConfigurationClassLoader());
+            } catch (GBeanAlreadyExistsException e) {
+                throw new InvalidConfigException(e);
+            }
+        }
+
+        try {
+            // start the gbeans
+            for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+                GBeanData gbeanData = (GBeanData) iterator.next();
+                AbstractName gbeanName = gbeanData.getAbstractName();
+                kernel.startRecursiveGBean(gbeanName);
+            }
+
+            // assure all of the gbeans are started
+            for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+                GBeanData gbeanData = (GBeanData) iterator.next();
+                AbstractName gbeanName = gbeanData.getAbstractName();
+                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
     }
 }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableKernelConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableKernelConfigurationManager.java?rev=386907&r1=386906&r2=386907&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableKernelConfigurationManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableKernelConfigurationManager.java
Sat Mar 18 16:52:38 2006
@@ -33,7 +33,7 @@
 /**
  * Standard implementation of an editable ConfigurationManager.
  *
- * @version $Rev: 384686 $ $Date$
+ * @version $Rev:386276 $ $Date$
  */
 public class EditableKernelConfigurationManager extends KernelConfigurationManager implements
EditableConfigurationManager {
     public EditableKernelConfigurationManager(Kernel kernel,
@@ -83,7 +83,7 @@
 
 
             // preprocess the gbean data before loading it into the kernel
-            preprocessGBeanData(configuration, gbean);
+            ConfigurationUtil.preprocessGBeanData(configuration, gbean);
 
             // register the bean with the kernel
             kernel.loadGBean(gbean, configurationClassLoader);

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/KernelConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/KernelConfigurationManager.java?rev=386907&r1=386906&r2=386907&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/KernelConfigurationManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/KernelConfigurationManager.java
Sat Mar 18 16:52:38 2006
@@ -17,25 +17,12 @@
 
 package org.apache.geronimo.kernel.config;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URI;
-import javax.management.ObjectName;
-
 import org.apache.geronimo.gbean.AbstractName;
 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.InvalidConfigurationException;
-import org.apache.geronimo.gbean.GReferenceInfo;
-import org.apache.geronimo.gbean.ReferencePatterns;
-import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
@@ -46,14 +33,24 @@
 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.Environment;
+import org.apache.geronimo.kernel.repository.MissingDependencyException;
 import org.apache.geronimo.kernel.repository.Repository;
 
+import javax.management.ObjectName;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * The standard non-editable ConfigurationManager implementation.  That is,
  * you can save a lost configurations and stuff, but not change the set of
  * GBeans included in a configuration.
  *
- * @version $Rev: 384999 $ $Date$
+ * @version $Rev:386276 $ $Date$
  * @see EditableConfigurationManager
  */
 public class KernelConfigurationManager extends SimpleConfigurationManager implements GBeanLifecycle
{
@@ -76,10 +73,9 @@
 
         super(stores,
                 createArtifactResolver(artifactResolver, artifactManager, repositories),
-                kernel.getNaming(),
+                kernel == null? null: kernel.getNaming(),
                 repositories);
 
-        if (kernel == null) throw new NullPointerException("kernel is null");
         this.kernel = kernel;
         this.attributeStore = attributeStore;
         this.configurationList = configurationList;
@@ -103,6 +99,8 @@
             Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(Configuration.getConfigurationObjectName(configurationId),
Configuration.class);
             configurationStatus = createConfigurationStatus(configuration);
             configurationStatus.load();
+            //even worse hack
+            configurationStatus.start();
             configurations.put(configurationId, configurationStatus);
             return configurationStatus.getConfiguration();
         }
@@ -113,8 +111,7 @@
     protected Configuration load(GBeanData configurationData, Map loadedConfigurations) throws
InvalidConfigException {
         Artifact configurationId = getConfigurationId(configurationData);
         AbstractName configurationName = Configuration.getConfigurationAbstractName(configurationId);
-
-        // load the configuation
+        // load the configuration
         try {
             kernel.loadGBean(configurationData, classLoader);
         } catch (GBeanAlreadyExistsException e) {
@@ -155,99 +152,11 @@
             gbeans = attributeStore.applyOverrides(getConfigurationId(configuration), gbeans,
configuration.getConfigurationClassLoader());
         }
 
-        // register all the GBeans
-        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);
-
-            // preprocess the gbeanData (resolve references, set base url, declare dependency,
etc.)
-            preprocessGBeanData(configuration, gbeanData);
-            log.trace("Registering GBean " + gbeanData.getName());
-
-            try {
-                kernel.loadGBean(gbeanData, configuration.getConfigurationClassLoader());
-            } catch (GBeanAlreadyExistsException e) {
-                throw new InvalidConfigException(e);
-            }
-        }
-
-        try {
-            // start the gbeans
-            for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
-                GBeanData gbeanData = (GBeanData) iterator.next();
-                AbstractName gbeanName = gbeanData.getAbstractName();
-                if (kernel.isGBeanEnabled(gbeanName)) {
-                    kernel.startRecursiveGBean(gbeanName);
-                }
-            }
-
-            // assure all of the gbeans are started
-            for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
-                GBeanData gbeanData = (GBeanData) iterator.next();
-                AbstractName gbeanName = gbeanData.getAbstractName();
-                if (State.RUNNING_INDEX != kernel.getGBeanState(gbeanName)) {
-                    throw new InvalidConfigurationException("Configuration " + getConfigurationId(configuration)
+ " failed to start because gbean " + gbeanName + " did not start");
-                }
-            }
-        } catch (GBeanNotFoundException e) {
-            throw new InvalidConfigException(e);
-        }
-        // todo clean up after failure
+        ConfigurationUtil.startConfigurationGBeans(gbeans, configuration, kernel);
 
         if (configurationList != null) {
             configurationList.addConfiguration(getConfigurationId(configuration).toString());
         }
-    }
-
-    protected static void preprocessGBeanData(Configuration configuration, 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 = configuration.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 = configuration.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 = configuration.getConfigurationResolver().resolve(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(configuration.getAbstractName());
     }
 
     protected void stop(Configuration configuration) throws InvalidConfigException {

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java?rev=386907&r1=386906&r2=386907&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/SimpleConfigurationManager.java
Sat Mar 18 16:52:38 2006
@@ -16,24 +16,12 @@
  */
 package org.apache.geronimo.kernel.config;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-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.GBeanData;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.kernel.Naming;
 import org.apache.geronimo.kernel.jmx.JMXUtil;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.ArtifactResolver;
@@ -41,7 +29,20 @@
 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.Naming;
+
+import javax.management.ObjectName;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
 
 /**
  * @version $Rev$ $Date$
@@ -185,38 +186,14 @@
         try {
             Environment environment = (Environment) configurationData.getAttribute("environment");
 
-            LinkedHashMap parents = new LinkedHashMap();
-            List dependencies = new ArrayList(environment.getDependencies());
-            for (ListIterator iterator = dependencies.listIterator(); iterator.hasNext();)
{
-                Dependency dependency = (Dependency) iterator.next();
-                Artifact resolvedArtifact = artifactResolver.resolve(dependency.getArtifact());
-
-                Configuration parent = null;
-                if (loadedConfigurations.containsKey(resolvedArtifact)) {
-                    parent = (Configuration) loadedConfigurations.get(resolvedArtifact);
-                } else if (isConfiguration(resolvedArtifact)) {
-                    parent = getConfiguration(resolvedArtifact);
-                } else if (dependency.getImportType() == ImportType.SERVICES) {
-                    // Service depdendencies require that the depdencency be a configuration
-                    throw new InvalidConfigException("Dependency does not have services:
" + resolvedArtifact);
-                }
-
-                if (parent != null) {
-                    parents.put(resolvedArtifact, parent);
-
-                    // update the dependency list to contain the resolved artifact
-                    dependency = new Dependency(resolvedArtifact, dependency.getImportType());
-                    iterator.set(dependency);
-                }
-            }
-            environment.setDependencies(dependencies);
+            Collection parents = resolveParents(environment, loadedConfigurations);
 
             ConfigurationModuleType moduleType = (ConfigurationModuleType) configurationData.getAttribute("moduleType");
             List classPath = (List) configurationData.getAttribute("classPath");
             byte[] gbeanState = (byte[]) configurationData.getAttribute("gBeanState");
             ConfigurationResolver configurationResolver = (ConfigurationResolver) configurationData.getAttribute("configurationResolver");
 
-            Configuration configuration = new Configuration(parents.values(), moduleType,
environment, classPath, gbeanState, configurationResolver, naming);
+            Configuration configuration = new Configuration(parents, moduleType, environment,
classPath, gbeanState, configurationResolver, naming);
             configuration.doStart();
             return configuration;
         } catch (Exception e) {
@@ -224,6 +201,35 @@
         }
     }
 
+    private Collection resolveParents(Environment environment, Map loadedConfigurations)
throws MissingDependencyException, InvalidConfigException {
+        LinkedHashMap parents = new LinkedHashMap();
+        List dependencies = new ArrayList(environment.getDependencies());
+        for (ListIterator iterator = dependencies.listIterator(); iterator.hasNext();) {
+            Dependency dependency = (Dependency) iterator.next();
+            Artifact resolvedArtifact = artifactResolver.resolve(dependency.getArtifact());
+
+            Configuration parent = null;
+            if (loadedConfigurations.containsKey(resolvedArtifact)) {
+                parent = (Configuration) loadedConfigurations.get(resolvedArtifact);
+            } else if (isConfiguration(resolvedArtifact)) {
+                parent = getConfiguration(resolvedArtifact);
+            } else if (dependency.getImportType() == ImportType.SERVICES) {
+                // Service depdendencies require that the depdencency be a configuration
+                throw new InvalidConfigException("Dependency does not have services: " +
resolvedArtifact);
+            }
+
+            if (parent != null) {
+                parents.put(resolvedArtifact, parent);
+
+                // update the dependency list to contain the resolved artifact
+                dependency = new Dependency(resolvedArtifact, dependency.getImportType());
+                iterator.set(dependency);
+            }
+        }
+        environment.setDependencies(dependencies);
+        return parents.values();
+    }
+
 
     protected synchronized ConfigurationStatus createConfigurationStatus(Configuration configuration)
{
         // start parents are just the service parents of the configuration... we want the
services to be running so we can use them
@@ -233,8 +239,7 @@
         LinkedHashSet loadParents = new LinkedHashSet(startParents);
         loadParents.addAll(getParentStatuses(configuration.getClassParents()));
 
-        ConfigurationStatus configurationStatus = new ConfigurationStatus(configuration,
new ArrayList(loadParents), startParents);
-        return configurationStatus;
+        return new ConfigurationStatus(configuration, new ArrayList(loadParents), startParents);
     }
 
     private synchronized List getParentStatuses(List parents) {
@@ -330,7 +335,6 @@
         }
         environment.setDependencies(dependencies);
 
-
         // add parents to the parents reference collection
         gbeanData.addDependencies(parentNames);
         gbeanData.setReferencePatterns("Parents", parentNames);
@@ -428,7 +432,8 @@
         private int startCount = 0;
 
         public ConfigurationStatus(Configuration configuration, List loadParents, List startParents)
{
-            if (!loadParents.containsAll(startParents)) throw new IllegalArgumentException("loadParents
must contain all startParents");
+            if (!loadParents.containsAll(startParents))
+                throw new IllegalArgumentException("loadParents must contain all startParents");
             this.configuration = configuration;
             this.loadParents = loadParents;
             this.startParents = startParents;
@@ -444,7 +449,7 @@
 
         public void load() {
             for (Iterator iterator = loadParents.iterator(); iterator.hasNext();) {
-                KernelConfigurationManager.ConfigurationStatus parent = (KernelConfigurationManager.ConfigurationStatus)
iterator.next();
+                ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
                 parent.load();
             }
             loadCount++;
@@ -458,7 +463,7 @@
 
             LinkedList unloadList = new LinkedList();
             for (Iterator iterator = loadParents.iterator(); iterator.hasNext();) {
-                KernelConfigurationManager.ConfigurationStatus parent = (KernelConfigurationManager.ConfigurationStatus)
iterator.next();
+                ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
                 unloadList.addAll(parent.unload());
             }
             loadCount--;
@@ -476,7 +481,7 @@
         public List start() {
             List startList = new LinkedList();
             for (Iterator iterator = startParents.iterator(); iterator.hasNext();) {
-                KernelConfigurationManager.ConfigurationStatus parent = (KernelConfigurationManager.ConfigurationStatus)
iterator.next();
+                ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
                 startList.addAll(parent.start());
             }
             startCount++;
@@ -489,7 +494,7 @@
         public List stop() {
             LinkedList stopList = new LinkedList();
             for (Iterator iterator = startParents.iterator(); iterator.hasNext();) {
-                KernelConfigurationManager.ConfigurationStatus parent = (KernelConfigurationManager.ConfigurationStatus)
iterator.next();
+                ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
                 stopList.addAll(parent.stop());
             }
             startCount--;

Modified: geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java?rev=386907&r1=386906&r2=386907&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
(original)
+++ geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
Sat Mar 18 16:52:38 2006
@@ -26,6 +26,8 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.ReferencePatterns;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.Naming;
+import org.apache.geronimo.kernel.Jsr77Naming;
 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
 
 import javax.management.ObjectName;
@@ -139,9 +141,11 @@
     }
 
     public void testSetReferences() throws Exception {
-        ObjectName referencePattern1 = new ObjectName(":name=referencePattern1,*");
-        ObjectName referencePattern2 = new ObjectName(":name=referencePattern2,*");
-        ReferencePatterns referencePatterns = new ReferencePatterns(new LinkedHashSet(Arrays.asList(new
ObjectName[] {referencePattern1, referencePattern2})));
+        Naming naming = new Jsr77Naming();
+
+        AbstractName referencePattern1 = naming.createRootName(gbeanName.getArtifact(), "name",
"referencePattern1");
+        AbstractName referencePattern2 = naming.createRootName(gbeanName.getArtifact(), "name",
"referencePattern2");
+        ReferencePatterns referencePatterns = new ReferencePatterns(new LinkedHashSet(Arrays.asList(new
AbstractName[] {referencePattern1, referencePattern2})));
         localAttributeManager.setReferencePatterns(configurationName.toString(), gbeanName,
referenceInfo, referencePatterns);
         Collection gbeanDatas = new ArrayList();
         GBeanData gbeanData = new GBeanData(gbeanName, GBEAN_INFO);



Mime
View raw message