You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/19 12:11:35 UTC

svn commit: r697025 - in /geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring: BeanContainer.java BeanContainerImpl.java

Author: jdillon
Date: Fri Sep 19 03:11:34 2008
New Revision: 697025

URL: http://svn.apache.org/viewvc?rev=697025&view=rev
Log:
Allow creation of child container w/o additional classpath
Expose start(), stop() and close(); don't auto-start the context when created
Expose getBeanNames() to list all defined bean names

Modified:
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainer.java
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainer.java?rev=697025&r1=697024&r2=697025&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainer.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainer.java Fri Sep 19 03:11:34 2008
@@ -34,6 +34,12 @@
 public interface BeanContainer
 {
     BeanContainer getParent();
+
+    void start();
+
+    void stop();
+
+    void close();
     
     <T> T getBean(Class<T> type);
 
@@ -41,7 +47,11 @@
 
     <T> Map<String,T> getBeans(Class<T> type);
 
+    String[] getBeanNames();
+
     String[] getBeanNames(Class type);
 
-    BeanContainer createChild(String id, List<URL> classPath) throws DuplicateRealmException;
+    BeanContainer createChild(String id, List<URL> classPath);
+
+    BeanContainer createChild(String id);
 }

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java?rev=697025&r1=697024&r2=697025&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java Fri Sep 19 03:11:34 2008
@@ -24,7 +24,7 @@
 import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
 import java.net.URL;
@@ -89,15 +89,30 @@
 
         // Refresh to load things up
         context.refresh();
-
-        // Start components
-        context.start();
     }
 
     public BeanContainer getParent() {
         return parent;
     }
 
+    public void start() {
+        log.debug("Starting");
+
+        context.start();
+    }
+
+    public void stop() {
+        log.debug("Stopping");
+
+        context.stop();
+    }
+
+    public void close() {
+        log.debug("Closing");
+        
+        context.close();
+    }
+
     public <T> T getBean(final Class<T> type) {
         assert type != null;
 
@@ -128,24 +143,42 @@
         return (Map<String,T>)context.getBeansOfType(type);
     }
 
+    public String[] getBeanNames() {
+        return context.getBeanDefinitionNames();
+    }
+
     public String[] getBeanNames(final Class type) {
         assert type != null;
 
         return context.getBeanNamesForType(type);
     }
 
-    public BeanContainer createChild(final String id, final List<URL> classPath) throws DuplicateRealmException {
+    public BeanContainer createChild(final String id, final List<URL> classPath) {
         assert id != null;
-        assert classPath != null;
+        // classPath may be null
 
         log.debug("Creating child container: {}", id);
-        
-        ClassRealm childRealm = classRealm.createChildRealm(id);
 
-        for (URL url : classPath) {
-            childRealm.addURL(url);
+        ClassRealm childRealm = null;
+        try {
+            childRealm = classRealm.createChildRealm(id);
+        }
+        catch (DuplicateRealmException e) {
+            throw new FatalBeanException("Failed to create child container realm: " + id, e);
+        }
+
+        if (classPath != null) {
+            for (URL url : classPath) {
+                childRealm.addURL(url);
+            }
         }
 
         return new BeanContainerImpl(childRealm, this);
     }
+
+    public BeanContainer createChild(final String id) {
+        assert id != null;
+
+        return createChild(id, null);
+    }
 }
\ No newline at end of file