cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r158914 - cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
Date Thu, 24 Mar 2005 13:41:23 GMT
Author: cziegeler
Date: Thu Mar 24 05:41:23 2005
New Revision: 158914

URL: http://svn.apache.org/viewcvs?view=rev&rev=158914
Log:
Correctly chain contexts

Modified:
    cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java

Modified: cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java?view=diff&r1=158913&r2=158914
==============================================================================
--- cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
(original)
+++ cocoon/blocks/spring-app/trunk/java/org/apache/cocoon/spring/SpringComponentLocator.java
Thu Mar 24 05:41:23 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.cocoon.spring;
 
+import java.util.Map;
+
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 
@@ -31,6 +33,7 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.Constants;
+import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.core.Core;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
@@ -44,20 +47,16 @@
 import org.apache.excalibur.source.SourceResolver;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.access.BeanFactoryLocator;
-import org.springframework.beans.factory.access.BeanFactoryReference;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextException;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.util.StringUtils;
 import org.springframework.web.context.ConfigurableWebApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
 
 /**
  * This is the connection between Cocoon and Spring.
  * We create an own web application context.
- * Part of this code is based on Springs ContextLoader class.
  *
  * TODO - we need to store the application context somewhere to use the context
  * of a parent sitemap as the parent of a sub sitemap.
@@ -131,7 +130,7 @@
 
         try {
             // Determine parent for application context, if any.
-            ApplicationContext parent = this.loadParentContext();
+            ApplicationContext parent = this.getParentContext();
 
             // Make the core available as a bean, if not already done by a parent context
             if ( parent == null || !parent.containsBean("cocoon-core") ) {
@@ -163,14 +162,7 @@
         if (this.getLogger().isInfoEnabled()) {
             this.getLogger().info("Closing Spring web application context");
         }
-        try {
-            ((ConfigurableApplicationContext) this.wac).close();
-        } finally {
-            if (this.beanFactoryRef != null) {
-                this.beanFactoryRef.release();
-                this.beanFactoryRef = null;
-            }
-        }
+        this.wac.close();
         if ( this.manager != null ) {
             this.manager.release(this.resolver);
             this.resolver = null;
@@ -202,13 +194,6 @@
     }
 
     /**
-     * Holds BeanFactoryReference when loading parent factory via
-     * ContextSingletonBeanFactoryLocator.
-     */
-    protected BeanFactoryReference beanFactoryRef;
-
-
-    /**
      * Instantiate the web application context for this loader, either a
      * default CocoonApplicationContext or a custom context class if specified.
      * <p>This implementation expects custom contexts to be a subclass of
@@ -261,39 +246,19 @@
     }
 
     /**
-     * Template method with default implementation (which may be overridden by a
-     * subclass), to load or obtain an ApplicationContext instance which will be
-     * used as the parent context of the root WebApplicationContext. If the
-     * return value from the method is null, no parent context is set.
-     * <p>The main reason to load a parent context here is to allow multiple root
-     * web application contexts to all be children of a shared EAR context, or
-     * alternately to also share the same parent context that is visible to
-     * EJBs. For pure web applications, there is usually no need to worry about
-     * having a parent context to the root web application context.
-     * <p>The default implementation uses ContextSingletonBeanFactoryLocator,
-     * configured via {@link #LOCATOR_FACTORY_SELECTOR_PARAM} and
-     * {@link #BEAN_FACTORY_LOCATOR_FACTORY_KEY_PARAM}, to load a parent context
-     * which will be shared by all other users of ContextsingletonBeanFactoryLocator
-     * which also use the same configuration parameters.
-     * @return the parent application context, or null if none
-     * @throws BeansException if the context couldn't be initialized
-     * @see org.springframework.beans.factory.access.BeanFactoryLocator
-     * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
-     */
-    protected ApplicationContext loadParentContext()
-    throws BeansException {
-
-        ApplicationContext parentContext = null;
-        if (this.locatorFactorySelector != null) {
-            BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(this.locatorFactorySelector);
-
-            if (this.getLogger().isInfoEnabled()) {
-                this.getLogger().info("Getting parent context definition: using parent context
key of '"
-                        + parentContextKey + "' with BeanFactoryLocator");
-            }
-
-            this.beanFactoryRef = locator.useBeanFactory(this.parentContextKey);
-            parentContext = (ApplicationContext) this.beanFactoryRef.getFactory();
+     * Get the parent application context: this is either the context of a parent
+     * sitemap or an optional web application context set by the spring servlet (filter).
+     * @return A parent application context or null
+     */
+    protected ApplicationContext getParentContext() {
+        final Map objectModel = ContextHelper.getObjectModel(this.context);
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        ApplicationContext parentContext = (ApplicationContext)request.getAttribute("application-context");
+        
+        if ( parentContext == null ) {
+            // there is no parent sitemap with an application context
+            // let's search for a global one
+            parentContext = (ApplicationContext)this.servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
         }
 
         return parentContext;



Mime
View raw message