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/12/29 08:55:47 UTC
svn commit: r490947 - in /cocoon/trunk/core:
cocoon-core/src/main/java/org/apache/cocoon/environment/
cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/
cocoon-sitemap/cocoon-sitemap-impl/src/main/java/or...
Author: cziegeler
Date: Thu Dec 28 23:55:46 2006
New Revision: 490947
URL: http://svn.apache.org/viewvc?view=rev&rev=490947
Log:
Move Container class to spring module and give it a better name.
Added:
cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java (with props)
Removed:
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/Container.java
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java Thu Dec 28 23:55:46 2006
@@ -28,7 +28,7 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.components.flow.FlowHelper;
import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.Container;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.apache.commons.jxpath.DynamicPropertyHandler;
import org.apache.commons.jxpath.JXPathBeanInfo;
import org.apache.commons.jxpath.JXPathIntrospector;
@@ -129,7 +129,7 @@
cocoon.put("parameters", new ParametersMap(parameters));
}
- cocoon.put("settings", (Settings)Container.getCurrentWebApplicationContext().getBean(Settings.ROLE));
+ cocoon.put("settings", (Settings)WebAppContextUtils.getCurrentWebApplicationContext().getBean(Settings.ROLE));
final Map map = new HashMap();
map.put("cocoon", cocoon);
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/SettingsInputModule.java Thu Dec 28 23:55:46 2006
@@ -28,8 +28,8 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.Container;
import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.apache.commons.collections.IteratorUtils;
/**
@@ -68,7 +68,7 @@
*/
public Object getAttribute(String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
- final Settings settings = (Settings)Container.getCurrentWebApplicationContext().getBean(Settings.ROLE);
+ final Settings settings = (Settings)WebAppContextUtils.getCurrentWebApplicationContext().getBean(Settings.ROLE);
return settings.getProperty(name);
}
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Thu Dec 28 23:55:46 2006
@@ -29,7 +29,6 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
-import org.apache.cocoon.core.container.spring.Container;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ForwardRedirector;
@@ -44,6 +43,7 @@
import org.apache.cocoon.sitemap.LeaveSitemapEvent;
import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
import org.apache.cocoon.sitemap.SitemapExecutor;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -212,7 +212,7 @@
Thread.currentThread().setContextClassLoader(this.classLoader);
Object handle = null;
try {
- handle = Container.enteringContext(this.webAppContext);
+ handle = WebAppContextUtils.enteringContext(this.webAppContext);
// invoke listeners
// only invoke if pipeline is not internally
if ( !context.isBuildingPipelineOnly() ) {
@@ -246,7 +246,7 @@
} finally {
this.sitemapExecutor.leaveSitemap(this, environment.getObjectModel());
- Container.leavingContext(this.webAppContext, handle);
+ WebAppContextUtils.leavingContext(this.webAppContext, handle);
// invoke listeners
// only invoke if pipeline is not internally
if ( !context.isBuildingPipelineOnly() ) {
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Thu Dec 28 23:55:46 2006
@@ -61,7 +61,6 @@
import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.core.container.spring.Container;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
import org.apache.cocoon.core.container.spring.avalon.SitemapHelper;
import org.apache.cocoon.generation.Generator;
@@ -70,6 +69,7 @@
import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
import org.apache.cocoon.sitemap.PatternException;
import org.apache.cocoon.sitemap.SitemapParameters;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
import org.apache.cocoon.util.location.LocationUtils;
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java Thu Dec 28 23:55:46 2006
@@ -28,10 +28,10 @@
import org.apache.cocoon.classloader.reloading.Monitor;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.core.container.spring.CocoonWebApplicationContext;
-import org.apache.cocoon.core.container.spring.Container;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -154,7 +154,7 @@
}
final String contextUrl = sitemapLocation.substring(0, pos + 1);
- final WebApplicationContext parentContext = Container.getCurrentWebApplicationContext();
+ final WebApplicationContext parentContext = WebAppContextUtils.getCurrentWebApplicationContext();
// get classloader
// TODO rcl
Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java?view=diff&rev=490947&r1=490946&r2=490947
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java Thu Dec 28 23:55:46 2006
@@ -30,10 +30,10 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.source.util.SourceUtil;
-import org.apache.cocoon.core.container.spring.Container;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.spring.WebAppContextUtils;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.excalibur.source.Source;
@@ -392,7 +392,7 @@
static public ServiceManager getSitemapServiceManager() {
final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( stack != null && !stack.isEmpty()) {
- return (ServiceManager)Container.getCurrentWebApplicationContext().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
+ return (ServiceManager)WebAppContextUtils.getCurrentWebApplicationContext().getBean(AvalonUtils.SERVICE_MANAGER_ROLE);
}
return null;
}
Added: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java?view=auto&rev=490947
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java (added)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java Thu Dec 28 23:55:46 2006
@@ -0,0 +1,116 @@
+/*
+ * 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.cocoon.spring;
+
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.spring.impl.ServletContextFactoryBean;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * @version $Id$
+ */
+public abstract class WebAppContextUtils {
+
+ /** The name of the request attribute containing the current bean factory. */
+ public static final String CONTAINER_REQUEST_ATTRIBUTE = WebAppContextUtils.class.getName();
+
+ protected static WebApplicationContext ROOT_CONTAINER;
+
+ /**
+ * Get the current web application context.
+ * @throws IllegalStateException if no WebApplicationContext could not be found
+ * @return
+ */
+ public static WebApplicationContext getCurrentWebApplicationContext() {
+ final RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
+ return getCurrentWebApplicationContext(attributes);
+ }
+
+ /**
+ * Return the current web application context.
+ * @param attributes The request attributes.
+ * @throws IllegalStateException if no WebApplicationContext could not be found
+ * @return The web application context.
+ */
+ protected static WebApplicationContext getCurrentWebApplicationContext(RequestAttributes attributes) {
+ if ( attributes != null ) {
+ if (attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST) != null) {
+ return (WebApplicationContext) attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+ }
+ }
+ if ( ROOT_CONTAINER == null ) {
+ final ServletContext servletContext = ServletContextFactoryBean.getServletContext();
+ final WebApplicationContext parentContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+ ROOT_CONTAINER = parentContext;
+ }
+ return ROOT_CONTAINER;
+ }
+
+ /**
+ * Notify about entering this context.
+ * @return A handle which should be passed to {@link #leavingContext(RequestAttributes, Object)}.
+ */
+ public static Object enteringContext(WebApplicationContext webAppContext) {
+ // get request attributes
+ final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
+ final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ final WebApplicationContext oldContext = (WebApplicationContext)attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+ final ContextInfo info = new ContextInfo(oldContext, oldClassLoader);
+ attributes.setAttribute(CONTAINER_REQUEST_ATTRIBUTE, webAppContext, RequestAttributes.SCOPE_REQUEST);
+ Thread.currentThread().setContextClassLoader(webAppContext.getClassLoader());
+ return info;
+ }
+
+ /**
+ * Notify about leaving this context.
+ * @param handle The returned handle from {@link #enteringContext(RequestAttributes)}.
+ */
+ public static void leavingContext(WebApplicationContext webAppContext, Object handle) {
+ if ( !(handle instanceof ContextInfo) ) {
+ throw new IllegalArgumentException("Handle must be an instance of ContextInfo and not " + handle);
+ }
+ final ContextInfo info = (ContextInfo)handle;
+ // get request attributes
+ final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
+ // restore class loader
+ Thread.currentThread().setContextClassLoader(info.classLoader);
+ // restore previous web application context (or remove attribute)
+ if ( info.webAppContext == null ) {
+ attributes.removeAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+ } else {
+ attributes.setAttribute(CONTAINER_REQUEST_ATTRIBUTE, info.webAppContext, RequestAttributes.SCOPE_REQUEST);
+ }
+ }
+
+ /**
+ * Private bean keeping track of the class loader and web application context.
+ * @version $Id$
+ */
+ protected static final class ContextInfo {
+ public final ClassLoader classLoader;
+ public final WebApplicationContext webAppContext;
+
+ public ContextInfo(WebApplicationContext w, ClassLoader c) {
+ this.classLoader = c;
+ this.webAppContext = w;
+ }
+ }
+}
Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/spring/WebAppContextUtils.java
------------------------------------------------------------------------------
svn:keywords = Id