You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/02/26 18:47:21 UTC
svn commit: r381130 - in /cocoon/trunk/cocoon-core/src:
main/java/org/apache/cocoon/components/treeprocessor/
main/java/org/apache/cocoon/components/treeprocessor/sitemap/
main/java/org/apache/cocoon/core/
main/java/org/apache/cocoon/core/container/spr...
Author: cziegeler
Date: Sun Feb 26 09:47:18 2006
New Revision: 381130
URL: http://svn.apache.org/viewcvs?rev=381130&view=rev
Log:
Refactoring: remove dependency on spring applicationcontext and replace it with BeanFactory
Modified:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
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/ApplicationContextFactory.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonXmlWebApplicationContext.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=381130&r1=381129&r2=381130&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Sun Feb 26 09:47:18 2006
@@ -22,6 +22,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Stack;
+
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.container.ContainerUtil;
@@ -31,10 +33,13 @@
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.ChainedConfiguration;
import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
+import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
import org.apache.cocoon.core.container.spring.NameForAliasAware;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ForwardRedirector;
+import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.cocoon.environment.internal.ForwardEnvironmentWrapper;
@@ -276,6 +281,41 @@
}
/**
+ * @see org.apache.cocoon.sitemap.EnterSitemapEventListener#enteredSitemap(org.apache.cocoon.sitemap.EnterSitemapEvent)
+ */
+ protected void enteredSitemap(EnterSitemapEvent event) {
+ final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel());
+ final Object oldContext = request.getAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
+ if ( oldContext != null ) {
+ Stack stack = (Stack)request.getAttribute("ac-stack", Request.REQUEST_SCOPE);
+ if ( stack == null ) {
+ stack = new Stack();
+ request.setAttribute("ac-stack", stack, Request.REQUEST_SCOPE);
+ }
+ stack.push(oldContext);
+ }
+ request.setAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, this.beanFactory, Request.REQUEST_SCOPE);
+ }
+
+ /**
+ * @see org.apache.cocoon.sitemap.LeaveSitemapEventListener#leftSitemap(org.apache.cocoon.sitemap.LeaveSitemapEvent)
+ */
+ protected void leftSitemap(LeaveSitemapEvent event) {
+ final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel());
+ final Stack stack = (Stack)request.getAttribute("ac-stack", Request.REQUEST_SCOPE);
+ if ( stack == null ) {
+ request.removeAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
+ } else {
+ final Object oldContext = stack.pop();
+ request.setAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, oldContext, Request.REQUEST_SCOPE);
+ if ( stack.size() == 0 ) {
+ request.removeAttribute("ac-stack", Request.REQUEST_SCOPE);
+ }
+ }
+ }
+
+
+ /**
* Do the actual processing, be it producing the response or just building the pipeline
* @param environment
* @param context
@@ -297,8 +337,9 @@
try {
// invoke listeners
// only invoke if pipeline is not internally
- if ( !context.isBuildingPipelineOnly() && this.enterSitemapEventListeners.size() > 0 ) {
+ if ( !context.isBuildingPipelineOnly() ) {
final EnterSitemapEvent enterEvent = new EnterSitemapEvent(this, environment);
+ this.enteredSitemap(enterEvent);
final Iterator enterSEI = this.enterSitemapEventListeners.iterator();
while ( enterSEI.hasNext() ) {
final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)enterSEI.next();
@@ -331,8 +372,9 @@
this.sitemapExecutor.leaveSitemap(this, environment.getObjectModel());
// invoke listeners
// only invoke if pipeline is not internally
- if ( !context.isBuildingPipelineOnly() && this.leaveSitemapEventListeners.size() > 0 ) {
+ if ( !context.isBuildingPipelineOnly() ) {
final LeaveSitemapEvent leaveEvent = new LeaveSitemapEvent(this, environment);
+ this.leftSitemap(leaveEvent);
final Iterator leaveSEI = this.leaveSitemapEventListeners.iterator();
while ( leaveSEI.hasNext() ) {
final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)leaveSEI.next();
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=381130&r1=381129&r2=381130&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Sun Feb 26 09:47:18 2006
@@ -34,6 +34,7 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.Constants;
+import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.treeprocessor.CategoryNode;
import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
@@ -46,6 +47,7 @@
import org.apache.cocoon.core.container.spring.ConfigReader;
import org.apache.cocoon.core.container.spring.ConfigurationInfo;
import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.serialization.Serializer;
@@ -60,8 +62,8 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
/**
* The tree builder for the sitemap language.
@@ -70,10 +72,10 @@
*/
public class SitemapLanguage
extends DefaultTreeBuilder
- implements ApplicationContextAware {
+ implements BeanFactoryAware {
/** Spring application context. */
- protected CocoonXmlWebApplicationContext applicationContext;
+ protected ConfigurableBeanFactory beanFactory;
// Regexp's for splitting expressions
private static final String COMMA_SPLIT_REGEXP = "[\\s]*,[\\s]*";
@@ -124,23 +126,26 @@
// setup spring container
// first, get the correct parent
- CocoonXmlWebApplicationContext parentContext = this.applicationContext.getCurrentApplicationContext();
-
+ ConfigurableBeanFactory parentContext = this.beanFactory;
+ final Request request = ContextHelper.getRequest(context);
+ if ( request.getAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE) != null ) {
+ parentContext = (ConfigurableBeanFactory)request.getAttribute(CocoonXmlWebApplicationContext.APPLICATION_CONTEXT_REQUEST_ATTRIBUTE);
+ }
+
final AvalonEnvironment ae = new AvalonEnvironment();
ae.context = context;
- ae.core = (Core)applicationContext.getBean(Core.ROLE);
+ ae.core = (Core)this.beanFactory.getBean(Core.ROLE);
ae.logger = this.getLogger();
ae.servletContext = ((ServletConfig)context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG)).getServletContext();
ae.settings = ae.core.getSettings();
- final ConfigurationInfo ci = ConfigReader.readConfiguration(c, parentContext.getConfigurationInfo(), ae);
+ final ConfigurationInfo parentConfigInfo = (ConfigurationInfo)parentContext.getBean(ConfigurationInfo.class.getName());
+ final ConfigurationInfo ci = ConfigReader.readConfiguration(c, parentConfigInfo, ae);
- final CocoonXmlWebApplicationContext sitemapContext =
+ final ConfigurableBeanFactory sitemapContext =
ApplicationContextFactory.createApplicationContext(ae, ci, parentContext, false);
newManager = (ServiceManager) sitemapContext.getBean(ServiceManager.class.getName());
Logger sitemapLogger = sitemapLogger = (Logger)sitemapContext.getBean(Logger.class.getName());
- this.addListener(new TreeBuilder.EventComponent(sitemapContext, false));
-
// and finally the listeners
final Configuration listenersWrapper = config.getChild("listeners", false);
if ( listenersWrapper != null ) {
@@ -531,12 +536,12 @@
}
/**
- * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+ * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
*/
- public void setApplicationContext(ApplicationContext ae) throws BeansException {
- if ( ! (ae instanceof CocoonXmlWebApplicationContext) ) {
- throw new BeanCreationException("Application context for tree processor must be an instance of " + CocoonXmlWebApplicationContext.class.getName());
+ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+ if ( ! (beanFactory instanceof ConfigurableBeanFactory) ) {
+ throw new BeanCreationException("Bean factory for tree processor must be an instance of " + ConfigurableBeanFactory.class.getName());
}
- this.applicationContext = (CocoonXmlWebApplicationContext)ae;
+ this.beanFactory = (ConfigurableBeanFactory)beanFactory;
}
}
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=381130&r1=381129&r2=381130&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 Sun Feb 26 09:47:18 2006
@@ -47,7 +47,6 @@
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.ComponentContext;
@@ -62,7 +61,7 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.TraversableSource;
import org.apache.excalibur.source.impl.URLSource;
-import org.springframework.context.ApplicationContext;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.xml.sax.InputSource;
/**
@@ -100,7 +99,7 @@
protected final ServletContext servletContext;
/** The container. */
- protected CocoonXmlWebApplicationContext container;
+ protected ConfigurableBeanFactory container;
/** The configuration file */
protected Source configurationFile;
@@ -587,7 +586,7 @@
return this.processor;
}
- protected CocoonXmlWebApplicationContext setupSpringContainer() throws Exception {
+ protected ConfigurableBeanFactory setupSpringContainer() throws Exception {
if (this.log.isInfoEnabled()) {
this.log.info("Reading root configuration: " + this.settings.getConfiguration());
}
@@ -620,9 +619,9 @@
env.logger = this.log;
env.servletContext = this.env.getEnvironmentContext();
env.settings = this.core.getSettings();
- ApplicationContext rootContext = ApplicationContextFactory.createRootApplicationContext(env);
+ ConfigurableBeanFactory rootContext = ApplicationContextFactory.createRootApplicationContext(env);
ConfigurationInfo result = ConfigReader.readConfiguration(settings.getConfiguration(), env);
- CocoonXmlWebApplicationContext mainContext = ApplicationContextFactory.createApplicationContext(env, result, rootContext, true);
+ ConfigurableBeanFactory mainContext = ApplicationContextFactory.createApplicationContext(env, result, rootContext, true);
return mainContext;
}
@@ -688,12 +687,12 @@
*/
public void destroy() {
if ( this.container != null ) {
- this.container.destroy();
+ this.container.destroySingletons();
this.container = null;
}
}
- public CocoonXmlWebApplicationContext getContainer() {
+ public ConfigurableBeanFactory getContainer() {
return this.container;
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java?rev=381130&r1=381129&r2=381130&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ApplicationContextFactory.java Sun Feb 26 09:47:18 2006
@@ -42,6 +42,7 @@
import org.apache.cocoon.selection.Selector;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.transformation.Transformer;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ByteArrayResource;
@@ -66,10 +67,10 @@
* @return A new application context
* @throws Exception
*/
- public static CocoonXmlWebApplicationContext createApplicationContext(AvalonEnvironment env,
- ConfigurationInfo info,
- ApplicationContext parent,
- boolean addCocoon)
+ public static ConfigurableBeanFactory createApplicationContext(AvalonEnvironment env,
+ ConfigurationInfo info,
+ ConfigurableBeanFactory parent,
+ boolean addCocoon)
throws Exception {
final String xmlConfig = (new XmlConfigCreator()).createConfig(info, addCocoon);
Resource rsc = new ByteArrayResource(xmlConfig.getBytes("utf-8"));
@@ -89,8 +90,8 @@
if ( info.rootLogger != null ) {
context.getBeanFactory().registerSingleton(Logger.class.getName(), logger);
}
- prepareApplicationContext(context);
- return context;
+ prepareApplicationContext(context, info);
+ return context.getBeanFactory();
}
/**
@@ -103,7 +104,7 @@
* @return A new root application context.
* @throws Exception
*/
- public static CocoonXmlWebApplicationContext createRootApplicationContext(AvalonEnvironment env)
+ public static ConfigurableBeanFactory createRootApplicationContext(AvalonEnvironment env)
throws Exception {
final ApplicationContext parent = (ApplicationContext)env.servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
CocoonXmlWebApplicationContext context = new CocoonXmlWebApplicationContext(parent);
@@ -113,8 +114,7 @@
factory.registerSingleton(Logger.class.getName(), env.logger);
factory.registerSingleton(Core.class.getName(), env.core);
factory.registerSingleton(Settings.class.getName(), env.settings);
- prepareApplicationContext(context);
- return context;
+ return context.getBeanFactory();
}
/**
@@ -208,37 +208,37 @@
return loggerManager.getLoggerForCategory(accesslogger);
}
- protected static void prepareApplicationContext(CocoonXmlWebApplicationContext context) {
- if ( context.getConfigurationInfo() != null ) {
- // TODO - we should find a better way
- // add ProcessorComponentInfo
- ProcessorComponentInfo parentInfo = null;
- if ( context.getParent() != null && context.getParent().containsBean(ProcessorComponentInfo.ROLE) ) {
- parentInfo = (ProcessorComponentInfo)context.getParent().getBean(ProcessorComponentInfo.ROLE);
- }
- ProcessorComponentInfo info = new ProcessorComponentInfo(parentInfo);
- final Iterator i = context.getConfigurationInfo().getComponents().values().iterator();
- while (i.hasNext()) {
- final ComponentInfo current = (ComponentInfo)i.next();
- info.componentAdded(current.getRole(), current.getComponentClassName(), current.getConfiguration());
- }
- prepareSelector(info, context, Generator.ROLE);
- prepareSelector(info, context, Transformer.ROLE);
- prepareSelector(info, context, Serializer.ROLE);
- prepareSelector(info, context, ProcessingPipeline.ROLE);
- prepareSelector(info, context, Action.ROLE);
- prepareSelector(info, context, Selector.ROLE);
- prepareSelector(info, context, Matcher.ROLE);
- prepareSelector(info, context, Reader.ROLE);
- info.lock();
- context.getBeanFactory().registerSingleton(ProcessorComponentInfo.ROLE, info);
- }
+ protected static void prepareApplicationContext(CocoonXmlWebApplicationContext context,
+ ConfigurationInfo configInfo) {
+ // TODO - we should find a better way
+ // add ProcessorComponentInfo
+ ProcessorComponentInfo parentInfo = null;
+ if ( context.getParent() != null && context.getParent().containsBean(ProcessorComponentInfo.ROLE) ) {
+ parentInfo = (ProcessorComponentInfo)context.getParent().getBean(ProcessorComponentInfo.ROLE);
+ }
+ ProcessorComponentInfo info = new ProcessorComponentInfo(parentInfo);
+ final Iterator i = configInfo.getComponents().values().iterator();
+ while (i.hasNext()) {
+ final ComponentInfo current = (ComponentInfo)i.next();
+ info.componentAdded(current.getRole(), current.getComponentClassName(), current.getConfiguration());
+ }
+ prepareSelector(info, context, configInfo, Generator.ROLE);
+ prepareSelector(info, context, configInfo, Transformer.ROLE);
+ prepareSelector(info, context, configInfo, Serializer.ROLE);
+ prepareSelector(info, context, configInfo, ProcessingPipeline.ROLE);
+ prepareSelector(info, context, configInfo, Action.ROLE);
+ prepareSelector(info, context, configInfo, Selector.ROLE);
+ prepareSelector(info, context, configInfo, Matcher.ROLE);
+ prepareSelector(info, context, configInfo, Reader.ROLE);
+ info.lock();
+ context.getBeanFactory().registerSingleton(ProcessorComponentInfo.ROLE, info);
}
protected static void prepareSelector(ProcessorComponentInfo info,
CocoonXmlWebApplicationContext context,
+ ConfigurationInfo configInfo,
String category) {
- final ComponentInfo component = (ComponentInfo)context.getConfigurationInfo().getComponents().get(category + "Selector");
+ final ComponentInfo component = (ComponentInfo)configInfo.getComponents().get(category + "Selector");
if ( component != null ) {
info.setDefaultType(category, component.getDefaultValue());
}
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=381130&r1=381129&r2=381130&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 Sun Feb 26 09:47:18 2006
@@ -17,7 +17,6 @@
import java.io.IOException;
import java.util.Map;
-import java.util.Stack;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -28,19 +27,13 @@
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.SitemapConfigurable;
import org.apache.cocoon.core.container.util.DefaultSitemapConfigurationHolder;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.sitemap.EnterSitemapEvent;
-import org.apache.cocoon.sitemap.EnterSitemapEventListener;
-import org.apache.cocoon.sitemap.LeaveSitemapEvent;
-import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
@@ -59,7 +52,7 @@
*/
public class CocoonXmlWebApplicationContext
extends XmlWebApplicationContext
- implements EnterSitemapEventListener, LeaveSitemapEventListener, ApplicationListener, NameForAliasAware {
+ implements ApplicationListener, NameForAliasAware {
public static final String APPLICATION_CONTEXT_REQUEST_ATTRIBUTE = "application-context";
@@ -71,16 +64,18 @@
protected boolean destroyed = false;
- public CocoonXmlWebApplicationContext(ApplicationContext parent) {
+ protected final HierarchicalBeanFactory parentFactory;
+
+ public CocoonXmlWebApplicationContext(HierarchicalBeanFactory parent) {
this(null, parent, null, null, null);
}
public CocoonXmlWebApplicationContext(Resource avalonResource,
- ApplicationContext parent,
+ HierarchicalBeanFactory parent,
Logger avalonLogger,
ConfigurationInfo avalonConfiguration,
Context avalonContext) {
- this.setParent(parent);
+ this.parentFactory = parent;
this.avalonResource = avalonResource;
this.avalonLogger = avalonLogger;
this.avalonConfiguration = avalonConfiguration;
@@ -91,13 +86,6 @@
}
}
- /**
- * Get the avalon configuration information.
- */
- public ConfigurationInfo getConfigurationInfo() {
- return this.avalonConfiguration;
- }
-
public String getNameForAlias(String alias) {
if ( this.avalonConfiguration != null ) {
final String value = this.avalonConfiguration.getRoleForName(alias);
@@ -148,12 +136,16 @@
*/
protected DefaultListableBeanFactory createBeanFactory() {
DefaultListableBeanFactory beanFactory = super.createBeanFactory();
+ if ( this.parentFactory != null ) {
+ beanFactory.setParentBeanFactory(this.parentFactory);
+ }
if ( this.avalonConfiguration != null ) {
AvalonPostProcessor processor = new AvalonPostProcessor(this.avalonConfiguration.getComponents(),
this.avalonContext,
this.avalonLogger,
beanFactory);
beanFactory.addBeanPostProcessor(processor);
+ beanFactory.registerSingleton(ConfigurationInfo.class.getName(), this.avalonConfiguration);
}
return beanFactory;
}
@@ -166,51 +158,6 @@
*/
protected String[] getDefaultConfigLocations() {
return new String[]{};
- }
-
- /**
- * @see org.apache.cocoon.sitemap.EnterSitemapEventListener#enteredSitemap(org.apache.cocoon.sitemap.EnterSitemapEvent)
- */
- public void enteredSitemap(EnterSitemapEvent event) {
- final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel());
- final Object oldContext = request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
- if ( oldContext != null ) {
- Stack stack = (Stack)request.getAttribute("ac-stack", Request.REQUEST_SCOPE);
- if ( stack == null ) {
- stack = new Stack();
- request.setAttribute("ac-stack", stack, Request.REQUEST_SCOPE);
- }
- stack.push(oldContext);
- }
- request.setAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, this, Request.REQUEST_SCOPE);
- }
-
- /**
- * @see org.apache.cocoon.sitemap.LeaveSitemapEventListener#leftSitemap(org.apache.cocoon.sitemap.LeaveSitemapEvent)
- */
- public void leftSitemap(LeaveSitemapEvent event) {
- final Request request = ObjectModelHelper.getRequest(event.getEnvironment().getObjectModel());
- final Stack stack = (Stack)request.getAttribute("ac-stack", Request.REQUEST_SCOPE);
- if ( stack == null ) {
- request.removeAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, Request.REQUEST_SCOPE);
- } else {
- final Object oldContext = stack.pop();
- request.setAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, oldContext, Request.REQUEST_SCOPE);
- if ( stack.size() == 0 ) {
- request.removeAttribute("ac-stack", Request.REQUEST_SCOPE);
- }
- }
- }
-
- public CocoonXmlWebApplicationContext getCurrentApplicationContext() {
- final Request request = ContextHelper.getRequest(this.avalonContext);
- if ( this.avalonContext == null ) {
- return this;
- }
- if ( request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE) != null ) {
- return (CocoonXmlWebApplicationContext)request.getAttribute(APPLICATION_CONTEXT_REQUEST_ATTRIBUTE);
- }
- return this;
}
/**
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java?rev=381130&r1=381129&r2=381130&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/SitemapTestCase.java Sun Feb 26 09:47:18 2006
@@ -33,12 +33,12 @@
import org.apache.cocoon.core.CoreUtil;
import org.apache.cocoon.core.TestBootstrapEnvironment;
import org.apache.cocoon.core.TestCoreUtil;
-import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.mock.MockContext;
import org.apache.cocoon.environment.mock.MockEnvironment;
import org.apache.cocoon.environment.mock.MockRequest;
import org.apache.cocoon.environment.mock.MockResponse;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
public class SitemapTestCase extends TestCase {
@@ -51,7 +51,7 @@
private CoreUtil coreUtil;
private Processor processor;
private String classDir;
- private CocoonXmlWebApplicationContext container;
+ private ConfigurableBeanFactory container;
private ServiceManager serviceManager;
protected String processorClassName = Cocoon.class.getName();
Modified: cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java?rev=381130&r1=381129&r2=381130&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java (original)
+++ cocoon/trunk/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java Sun Feb 26 09:47:18 2006
@@ -38,10 +38,10 @@
import org.apache.cocoon.core.MutableSettings;
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.environment.mock.MockContext;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
/**
* JUnit TestCase for Cocoon Components.
@@ -135,7 +135,7 @@
private Context context;
/** The root application context. */
- private CocoonXmlWebApplicationContext rootContext;
+ private ConfigurableBeanFactory rootContext;
/** Return the logger */
protected Logger getLogger() {
@@ -222,7 +222,7 @@
*/
final private void done() {
if( this.rootContext != null ) {
- this.rootContext.destroy();
+ this.rootContext.destroySingletons();
this.rootContext = null;
}
this.manager = null;
@@ -293,12 +293,12 @@
this.rootContext = ApplicationContextFactory.createRootApplicationContext(avalonEnv);
// read roles
ConfigurationInfo rolesInfo = ConfigReader.readConfiguration(confRM, null, avalonEnv);
- CocoonXmlWebApplicationContext rolesContext = ApplicationContextFactory.createApplicationContext(avalonEnv, rolesInfo, rootContext, true);
+ ConfigurableBeanFactory rolesContext = ApplicationContextFactory.createApplicationContext(avalonEnv, rolesInfo, rootContext, true);
// read components
ConfigurationInfo componentsInfo = ConfigReader.readConfiguration(confCM, rolesInfo, avalonEnv);
this.addComponents( componentsInfo );
- CocoonXmlWebApplicationContext componentsContext = ApplicationContextFactory.createApplicationContext(avalonEnv, componentsInfo, rolesContext, false);
+ ConfigurableBeanFactory componentsContext = ApplicationContextFactory.createApplicationContext(avalonEnv, componentsInfo, rolesContext, false);
this.manager = (ServiceManager)componentsContext.getBean(ServiceManager.class.getName());
}