cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r380198 - in /cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core: CoreUtil.java container/spring/CocoonXmlWebApplicationContext.java
Date Thu, 23 Feb 2006 19:09:34 GMT
Author: cziegeler
Date: Thu Feb 23 11:09:30 2006
New Revision: 380198

URL: http://svn.apache.org/viewcvs?rev=380198&view=rev
Log:
Start disposing of container

Modified:
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java?rev=380198&r1=380197&r2=380198&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java Thu Feb 23
11:09:30 2006
@@ -48,6 +48,7 @@
 import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
 import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
 import org.apache.cocoon.core.container.spring.AvalonEnvironment;
+import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
 import org.apache.cocoon.core.container.spring.ConfigReader;
 import org.apache.cocoon.core.container.spring.ConfigurationInfo;
 import org.apache.cocoon.core.container.util.ConfigurationBuilder;
@@ -99,7 +100,7 @@
     protected final ServletContext servletContext;
 
     /** The container. */
-    protected ApplicationContext container;
+    protected CocoonXmlWebApplicationContext container;
 
     /** The configuration file */
     protected Source configurationFile;
@@ -669,7 +670,7 @@
         return this.processor;
     }
 
-    protected ApplicationContext setupSpringContainer() throws Exception {
+    protected CocoonXmlWebApplicationContext setupSpringContainer() throws Exception {
         if (this.log.isInfoEnabled()) {
             this.log.info("Reading root configuration: " + this.settings.getConfiguration());
         }
@@ -704,7 +705,7 @@
         env.settings = this.core.getSettings();
         ApplicationContext rootContext = ApplicationContextFactory.createRootApplicationContext(env);
         ConfigurationInfo result = ConfigReader.readConfiguration(settings.getConfiguration(),
env);
-        ApplicationContext mainContext = ApplicationContextFactory.createApplicationContext(env,
result, rootContext, true);
+        CocoonXmlWebApplicationContext mainContext = ApplicationContextFactory.createApplicationContext(env,
result, rootContext, true);
 
         return mainContext;
     }
@@ -769,8 +770,8 @@
      * Dispose the root processor when environment is destroyed
      */
     public void destroy() {
-        // FIXME - we have to clean up here!
         if ( this.container != null ) {
+            this.container.destroy();
             this.container = null;
         }
     }

Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java?rev=380198&r1=380197&r2=380198&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java
(original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java
Thu Feb 23 11:09:30 2006
@@ -48,6 +48,9 @@
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.UrlResource;
 import org.springframework.web.context.support.XmlWebApplicationContext;
@@ -61,7 +64,7 @@
  */
 public class CocoonXmlWebApplicationContext
     extends XmlWebApplicationContext
-    implements EnterSitemapEventListener, LeaveSitemapEventListener {
+    implements EnterSitemapEventListener, LeaveSitemapEventListener, ApplicationListener
{
 
     public static final String DEFAULT_SPRING_CONFIG = "conf/applicationContext.xml";
     public static final String APPLICATION_CONTEXT_REQUEST_ATTRIBUTE = "application-context";
@@ -74,6 +77,8 @@
     protected final Context avalonContext;
     protected final ConfigurationInfo avalonConfiguration;
 
+    protected boolean destroyed = false;
+
     public CocoonXmlWebApplicationContext(ApplicationContext parent) {
         this(null, parent, null, null, null);
     }
@@ -88,12 +93,30 @@
         this.avalonLogger = avalonLogger;
         this.avalonConfiguration = avalonConfiguration;
         this.avalonContext = avalonContext;
+        if ( parent instanceof CocoonXmlWebApplicationContext) {
+            ((CocoonXmlWebApplicationContext)parent).registerChildContext(this);
+            
+        }
     }
 
     public ConfigurationInfo getConfigurationInfo() {
         return this.avalonConfiguration;
     }
 
+    public void registerChildContext(CocoonXmlWebApplicationContext childContext) {
+        this.addListener(childContext);
+    }
+
+    /**
+     * @see org.springframework.context.support.AbstractApplicationContext#destroy()
+     */
+    public void destroy() {
+        if ( !this.destroyed ) {
+            this.destroyed = true;
+            super.destroy();
+        }
+    }
+
     /**
      * @see org.springframework.web.context.support.XmlWebApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
      */
@@ -218,6 +241,17 @@
             return (CocoonXmlWebApplicationContext)request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE);
         }
         return this;
+    }
+
+    /**
+     * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
+     */
+    public void onApplicationEvent(ApplicationEvent event) {
+        if ( event instanceof ContextClosedEvent ) {
+            if (((ContextClosedEvent)event).getApplicationContext().equals(this.getParent())
) {
+                this.destroy();
+            }
+        }
     }
 
     /**



Mime
View raw message