geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r694137 - in /geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring: BeanContainer.java BeanContainerApplicationContext.java BeanContainerImpl.java
Date Thu, 11 Sep 2008 05:25:59 GMT
Author: jdillon
Date: Wed Sep 10 22:25:58 2008
New Revision: 694137

URL: http://svn.apache.org/viewvc?rev=694137&view=rev
Log:
Fix runtime event processing

Added:
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
  (with props)
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=694137&r1=694136&r2=694137&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
Wed Sep 10 22:25:58 2008
@@ -17,9 +17,16 @@
  * under the License.
  */
 
+
 package org.apache.geronimo.gshell.spring;
 
 import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
+
+import java.net.URL;
+import java.util.List;
 
 /**
  * An abstraction of a container of beans.
@@ -28,9 +35,15 @@
  */
 public interface BeanContainer
 {
+    BeanContainer getParent();
+    
     <T> T getBean(Class<T> type) throws BeansException;
 
     <T> T getBean(String name, Class<T> requiredType) throws BeansException;
 
-    // Create children
+    void publish(ApplicationEvent event);
+
+    void addListener(ApplicationListener listener);
+
+    BeanContainer createChild(String id, List<URL> classPath) throws DuplicateRealmException;
 }

Added: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java?rev=694137&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
Wed Sep 10 22:25:58 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.gshell.spring;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.ApplicationListener;
+
+/**
+ * Custom Spring {@link org.springframework.context.ApplicationContext} for {@link BeanContainer}
instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BeanContainerApplicationContext
+    extends ClassPathXmlApplicationContext
+{
+    public BeanContainerApplicationContext(final String[] configLocations) {
+        super(configLocations, false);
+    }
+
+    public BeanContainerApplicationContext(final String[] configLocations, BeanContainerApplicationContext
parent) {
+        super(configLocations, false, parent);
+    }
+
+    @Override
+    public void addListener(final ApplicationListener listener) {
+        assert listener != null;
+        
+        super.addListener(listener);
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerApplicationContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=694137&r1=694136&r2=694137&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
Wed Sep 10 22:25:58 2008
@@ -24,13 +24,17 @@
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
 import org.codehaus.plexus.classworlds.ClassWorld;
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.URL;
+import java.util.List;
+
 /**
  * Default {@link BeanContainer} implementation.
  *
@@ -48,15 +52,19 @@
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private ClassPathXmlApplicationContext context;
+    private final BeanContainer parent;
+
+    private final BeanContainerApplicationContext context;
 
-    private ClassWorld classWorld;
+    private final ClassWorld classWorld;
 
-    private ClassRealm classRealm;
+    private final ClassRealm classRealm;
     
     public BeanContainerImpl(final ClassLoader classLoader) {
         assert classLoader != null;
 
+        parent = null;
+        
         // Setup classworlds
         classWorld = new ClassWorld();
         try {
@@ -67,7 +75,7 @@
         }
 
         // Construct the container and add customizations
-        context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS, false);
+        context = new BeanContainerApplicationContext(CONFIG_LOCATIONS);
         context.registerShutdownHook();
         context.setClassLoader(classRealm);
         addBeanPostProcessor(new BeanContainerAwareProcessor(this));
@@ -76,6 +84,28 @@
         context.refresh();
     }
 
+    private BeanContainerImpl(final BeanContainerImpl parent, final ClassRealm classRealm)
{
+        assert parent != null;
+        assert classRealm != null;
+
+        this.parent = parent;
+        this.classWorld = classRealm.getWorld();
+        this.classRealm = classRealm;
+
+        // Construct the container and add customizations
+        context = new BeanContainerApplicationContext(CONFIG_LOCATIONS, parent.context);
+        context.registerShutdownHook();
+        context.setClassLoader(classRealm);
+        addBeanPostProcessor(new BeanContainerAwareProcessor(this));
+        
+        // Refresh to load things up
+        context.refresh();
+    }
+
+    public BeanContainer getParent() {
+        return parent;
+    }
+
     private void addBeanPostProcessor(final BeanPostProcessor processor) {
         assert processor != null;
 
@@ -108,4 +138,36 @@
 
         return (T) context.getBean(name, requiredType);
     }
+
+    public void publish(ApplicationEvent event) {
+        assert event != null;
+
+        log.debug("Publishing event: {} ({})", event, this);
+        
+        context.publishEvent(event);
+    }
+
+    public void addListener(ApplicationListener listener) {
+        assert listener != null;
+
+        log.debug("Adding listener: {} ({})", listener, this);
+
+        // addApplicationListener() only adds listeners before refresh(), so use addListener()
+        context.addListener(listener);
+    }
+
+    public BeanContainer createChild(final String id, final List<URL> classPath) throws
DuplicateRealmException {
+        assert id != null;
+        assert classPath != null;
+
+        log.debug("Creating child bean container: " + id);
+        
+        ClassRealm childRealm = classRealm.createChildRealm(id);
+
+        for (URL url : classPath) {
+            childRealm.addURL(url);
+        }
+
+        return new BeanContainerImpl(this, childRealm);
+    }
 }
\ No newline at end of file



Mime
View raw message