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/20 10:08:41 UTC
svn commit: r379064 - in /cocoon/trunk:
cocoon-core/src/main/java/org/apache/cocoon/
cocoon-core/src/main/java/org/apache/cocoon/bean/
cocoon-core/src/main/java/org/apache/cocoon/core/
cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ ...
Author: cziegeler
Date: Mon Feb 20 01:08:40 2006
New Revision: 379064
URL: http://svn.apache.org/viewcvs?rev=379064&view=rev
Log:
Switch to spring based container
Removed:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/SpringCocoon.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java
Modified:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/Cocoon.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.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/XmlConfigCreator.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/servlet/CocoonServlet.java
cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/environment/portlet/PortletContext.java
cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/Cocoon.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/Cocoon.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/Cocoon.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/Cocoon.java Mon Feb 20 01:08:40 2006
@@ -15,301 +15,97 @@
*/
package org.apache.cocoon;
-import java.io.BufferedInputStream;
-import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import org.apache.avalon.excalibur.logger.LoggerManageable;
-import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.container.CocoonServiceManager;
-import org.apache.cocoon.components.container.ComponentContext;
-import org.apache.cocoon.components.source.SourceUtil;
-import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
-import org.apache.cocoon.configuration.ConfigurationBuilder;
import org.apache.cocoon.core.Core;
-import org.apache.cocoon.core.Settings;
-import org.apache.cocoon.core.container.RoleManager;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.commons.lang.SystemUtils;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.impl.URLSource;
-import org.xml.sax.InputSource;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
/**
* The Cocoon Object is the main Kernel for the entire Cocoon system.
- *
+ *
* @version $Id$
*/
-public class Cocoon
- extends AbstractLogEnabled
- implements ThreadSafe,
- Initializable,
- Disposable,
- Modifiable,
- Processor,
- Contextualizable,
- Serviceable,
- LoggerManageable {
+public class Cocoon implements Processor, BeanFactoryAware {
- static Cocoon instance;
-
- /** The root Cocoon logger */
- private Logger rootLogger;
-
- /** The application context */
- private Context context;
-
- /** The configuration file */
- private Source configurationFile;
-
- /** The logger manager */
- private LoggerManager loggerManager;
-
- /** The parent service manager. */
- private ServiceManager parentServiceManager;
-
- /** Flag for disposed or not */
- private boolean disposed;
-
- /** Active request count */
+ /** Active request count. */
private volatile int activeRequestCount;
- /** the Processor */
- private Processor processor;
+ /** The processor used to process the requests. */
+ protected final Processor processor;
- /** The source resolver */
- protected SourceResolver sourceResolver;
+ /** The environment helper. */
+ protected final EnvironmentHelper environmentHelper;
- /** The environment helper */
- protected EnvironmentHelper environmentHelper;
+ /** Processor attributes. */
+ protected final Map processorAttributes = new HashMap();
- /** A service manager */
- protected CocoonServiceManager serviceManager;
+ /** The service manager. */
+ protected final ServiceManager serviceManager;
- /** An optional Avalon Component that is called before and after processing all requests. */
- protected RequestListener requestListener;
+ /** The logger. */
+ protected final Logger logger;
- /** The Cocoon Core */
- protected Core core;
+ /**
+ * An optional component that is called before and after processing all
+ * requests.
+ */
+ protected RequestListener requestListener;
- /** Processor attributes */
- protected Map processorAttributes = new HashMap();
+ /** Shared Cocoon instance - TODO: we should remove this. */
+ static Cocoon instance;
/**
* Creates a new <code>Cocoon</code> instance.
*/
- public Cocoon() {
+ public Cocoon(Processor processor,
+ ServiceManager serviceManager,
+ Context context,
+ Logger logger)
+ throws Exception {
// HACK: Provide a way to share an instance of Cocoon object between
// several servlets/portlets.
Cocoon.instance = this;
- }
-
- /**
- * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
- */
- public void enableLogging(Logger logger) {
- this.rootLogger = logger;
- super.enableLogging(logger.getChildLogger("cocoon"));
- }
-
- /**
- * Get the parent service manager. For purposes of
- * avoiding extra method calls, the manager parameter may be null.
- *
- * @param manager the parent component manager. May be <code>null</code>
- */
- public void service(ServiceManager manager)
- throws ServiceException {
- this.parentServiceManager = manager;
- this.core = (Core)this.parentServiceManager.lookup(Core.ROLE);
- }
-
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
- public void contextualize(Context context) throws ContextException {
- this.context = new ComponentContext(context);
- ((DefaultContext)this.context).makeReadOnly();
- }
-
- /**
- * The <code>setLoggerManager</code> method will get a <code>LoggerManager</code>
- * for further use.
- *
- * @param loggerManager a <code>LoggerManager</code> value
- */
- public void setLoggerManager(LoggerManager loggerManager) {
- this.loggerManager = loggerManager;
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() throws Exception {
- getLogger().debug("Initializing new Cocoon object.");
- final Settings settings = this.core.getSettings();
- try {
- URLSource urlSource = new URLSource();
- urlSource.init(new URL(settings.getConfiguration()), null);
- this.configurationFile = new DelayedRefreshSourceWrapper(urlSource,
- settings.getReloadDelay("config"));
-
- } catch (IOException e) {
- throw new ConfigurationException(
- "Could not open configuration file: " + settings.getConfiguration(), e);
- }
-
- this.serviceManager = new CocoonServiceManager(this.parentServiceManager);
- ContainerUtil.enableLogging(this.serviceManager, this.rootLogger.getChildLogger("manager"));
- ContainerUtil.contextualize(this.serviceManager, this.context);
-
- this.configure();
-
- // add the logger manager to the component locator
-
- ContainerUtil.initialize(this.serviceManager);
-
- // Get the Processor and keep it
- this.processor = (Processor)this.serviceManager.lookup(Processor.ROLE);
-
- this.environmentHelper = new EnvironmentHelper(
- (URL) this.context.get(ContextHelper.CONTEXT_ROOT_URL));
- ContainerUtil.enableLogging(this.environmentHelper, this.rootLogger);
+ this.processor = processor;
+ this.logger = logger;
+ this.serviceManager = serviceManager;
+ this.environmentHelper = new EnvironmentHelper((URL) context
+ .get(ContextHelper.CONTEXT_ROOT_URL));
+ ContainerUtil.enableLogging(this.environmentHelper, logger);
ContainerUtil.service(this.environmentHelper, this.serviceManager);
-
- this.sourceResolver = (SourceResolver)this.serviceManager.lookup(SourceResolver.ROLE);
-
- if (this.serviceManager.hasService(RequestListener.ROLE)){
- this.requestListener = (RequestListener) this.serviceManager.lookup(RequestListener.ROLE);
- }
- Core.cleanup();
- }
-
- /**
- * Configure this <code>Cocoon</code> instance.
- *
- * @exception ConfigurationException if an error occurs
- * @exception ContextException if an error occurs
- */
- private void configure() throws Exception {
- InputSource is = SourceUtil.getInputSource(this.configurationFile);
-
- final Settings settings = this.core.getSettings();
- ConfigurationBuilder builder = new ConfigurationBuilder(settings);
- Configuration conf = builder.build(is);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Root configuration: " + conf.getName());
- }
- if (!"cocoon".equals(conf.getName())) {
- throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Configuration version: " + conf.getAttribute("version"));
- }
- if (!Constants.CONF_VERSION.equals(conf.getAttribute("version"))) {
- throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
- }
-
- RoleManager drm = null;
- String userRoles = conf.getAttribute("user-roles", "");
- if (!"".equals(userRoles)) {
- Configuration roles;
- try {
- org.apache.cocoon.environment.Context context =
- (org.apache.cocoon.environment.Context) this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
- URL url = context.getResource(userRoles);
- if (url == null) {
- throw new ConfigurationException("User-roles configuration '"+userRoles+"' cannot be found.");
- }
- is = new InputSource(new BufferedInputStream(url.openStream()));
- is.setSystemId(url.toString());
- roles = builder.build(is);
- } catch (Exception e) {
- throw new ConfigurationException("Error trying to load user-roles configuration", e);
- }
-
- RoleManager urm = new RoleManager(drm);
- ContainerUtil.enableLogging(urm, this.rootLogger.getChildLogger("roles").getChildLogger("user"));
- ContainerUtil.configure(urm, roles);
- roles = null;
- drm = urm;
- }
-
- this.serviceManager.setRoleManager(drm);
- this.serviceManager.setLoggerManager(this.loggerManager);
-
- getLogger().debug("Setting up components...");
- ContainerUtil.configure(this.serviceManager, conf);
- }
-
- /**
- * Queries the class to estimate its ergodic period termination.
- *
- * @param date a <code>long</code> value
- * @return a <code>boolean</code> value
- */
- public boolean modifiedSince(long date) {
- return date < this.configurationFile.getLastModified();
}
/**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
*/
- public void dispose() {
- if (this.serviceManager != null) {
- this.serviceManager.release(this.requestListener);
- this.requestListener = null;
-
- this.serviceManager.release(this.processor);
- this.processor = null;
-
- this.serviceManager.release(this.sourceResolver);
- this.sourceResolver = null;
-
- ContainerUtil.dispose(this.serviceManager);
- this.serviceManager = null;
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ // get the optional request listener
+ if (factory.containsBean(RequestListener.ROLE)) {
+ this.requestListener = (RequestListener) factory.getBean(RequestListener.ROLE);
}
- if ( this.parentServiceManager != null ) {
- this.parentServiceManager.release(this.core);
- this.core = null;
- this.parentServiceManager = null;
- }
- this.context = null;
- if (Cocoon.instance == this) {
- Cocoon.instance = null;
- }
- this.disposed = true;
}
/**
* Log debug information about the current environment.
- *
- * @param environment an <code>Environment</code> value
+ *
+ * @param environment
+ * an <code>Environment</code> value
*/
protected void debug(Environment environment, boolean internal) {
String lineSeparator = SystemUtils.LINE_SEPARATOR;
@@ -321,24 +117,30 @@
if (internal) {
msg.append("INTERNAL ");
}
- msg.append("REQUEST: ").append(request.getRequestURI()).append(lineSeparator).append(lineSeparator);
+ msg.append("REQUEST: ").append(request.getRequestURI()).append(lineSeparator).append(
+ lineSeparator);
msg.append("CONTEXT PATH: ").append(request.getContextPath()).append(lineSeparator);
msg.append("SERVLET PATH: ").append(request.getServletPath()).append(lineSeparator);
- msg.append("PATH INFO: ").append(request.getPathInfo()).append(lineSeparator).append(lineSeparator);
+ msg.append("PATH INFO: ").append(request.getPathInfo()).append(lineSeparator).append(
+ lineSeparator);
msg.append("REMOTE HOST: ").append(request.getRemoteHost()).append(lineSeparator);
msg.append("REMOTE ADDRESS: ").append(request.getRemoteAddr()).append(lineSeparator);
msg.append("REMOTE USER: ").append(request.getRemoteUser()).append(lineSeparator);
- msg.append("REQUEST SESSION ID: ").append(request.getRequestedSessionId()).append(lineSeparator);
- msg.append("REQUEST PREFERRED LOCALE: ").append(request.getLocale().toString()).append(lineSeparator);
+ msg.append("REQUEST SESSION ID: ").append(request.getRequestedSessionId()).append(
+ lineSeparator);
+ msg.append("REQUEST PREFERRED LOCALE: ").append(request.getLocale().toString()).append(
+ lineSeparator);
msg.append("SERVER HOST: ").append(request.getServerName()).append(lineSeparator);
- msg.append("SERVER PORT: ").append(request.getServerPort()).append(lineSeparator).append(lineSeparator);
+ msg.append("SERVER PORT: ").append(request.getServerPort()).append(lineSeparator).append(
+ lineSeparator);
msg.append("METHOD: ").append(request.getMethod()).append(lineSeparator);
msg.append("CONTENT LENGTH: ").append(request.getContentLength()).append(lineSeparator);
msg.append("PROTOCOL: ").append(request.getProtocol()).append(lineSeparator);
msg.append("SCHEME: ").append(request.getScheme()).append(lineSeparator);
- msg.append("AUTH TYPE: ").append(request.getAuthType()).append(lineSeparator).append(lineSeparator);
+ msg.append("AUTH TYPE: ").append(request.getAuthType()).append(lineSeparator).append(
+ lineSeparator);
msg.append("CURRENT ACTIVE REQUESTS: ").append(activeRequestCount).append(lineSeparator);
// log all of the request parameters
@@ -349,8 +151,7 @@
while (e.hasMoreElements()) {
String p = (String) e.nextElement();
- msg.append("PARAM: '").append(p).append("' ")
- .append("VALUES: '");
+ msg.append("PARAM: '").append(p).append("' ").append("VALUES: '");
String[] params = request.getParameterValues(p);
for (int i = 0; i < params.length; i++) {
msg.append("[" + params[i] + "]");
@@ -370,8 +171,7 @@
while (e2.hasMoreElements()) {
String p = (String) e2.nextElement();
- msg.append("PARAM: '").append(p).append("' ")
- .append("VALUES: '");
+ msg.append("PARAM: '").append(p).append("' ").append("VALUES: '");
Enumeration e3 = request.getHeaders(p);
while (e3.hasMoreElements()) {
msg.append("[" + e3.nextElement() + "]");
@@ -383,7 +183,8 @@
msg.append("'").append(lineSeparator);
}
- msg.append(lineSeparator).append("SESSION ATTRIBUTES:").append(lineSeparator).append(lineSeparator);
+ msg.append(lineSeparator).append("SESSION ATTRIBUTES:").append(lineSeparator).append(
+ lineSeparator);
// log all of the session attributes
if (session != null) {
@@ -393,42 +194,35 @@
e = session.getAttributeNames();
while (e.hasMoreElements()) {
String p = (String) e.nextElement();
- msg.append("PARAM: '").append(p).append("' ")
- .append("VALUE: '").append(session.getAttribute(p)).append("'")
- .append(lineSeparator);
+ msg.append("PARAM: '").append(p).append("' ").append("VALUE: '").append(
+ session.getAttribute(p)).append("'").append(lineSeparator);
}
}
}
- getLogger().debug(msg.toString());
+ this.logger.debug(msg.toString());
}
/**
* @see org.apache.cocoon.Processor#process(org.apache.cocoon.environment.Environment)
*/
- public boolean process(Environment environment)
- throws Exception {
-
- if (this.disposed) {
- throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
- }
-
+ public boolean process(Environment environment) throws Exception {
environment.startingProcessing();
final int environmentDepth = EnvironmentHelper.markEnvironment();
EnvironmentHelper.enterProcessor(this, this.serviceManager, environment);
try {
boolean result;
- if (getLogger().isDebugEnabled()) {
+ if (this.logger.isDebugEnabled()) {
++activeRequestCount;
- debug(environment, false);
+ this.debug(environment, false);
}
-
if (this.requestListener != null) {
try {
requestListener.onRequestStart(environment);
} catch (Exception e) {
- getLogger().error("Error encountered monitoring request start: " + e.getMessage());
+ this.logger.error("Error encountered monitoring request start: "
+ + e.getMessage());
}
}
@@ -438,7 +232,8 @@
try {
requestListener.onRequestEnd(environment);
} catch (Exception e) {
- getLogger().error("Error encountered monitoring request start: " + e.getMessage());
+ this.logger.error("Error encountered monitoring request start: "
+ + e.getMessage());
}
}
@@ -451,7 +246,8 @@
try {
requestListener.onRequestException(environment, any);
} catch (Exception e) {
- getLogger().error("Error encountered monitoring request start: " + e.getMessage());
+ this.logger.error("Error encountered monitoring request start: "
+ + e.getMessage());
}
}
// reset response on error
@@ -460,26 +256,21 @@
} finally {
EnvironmentHelper.leaveProcessor();
environment.finishingProcessing();
- if (getLogger().isDebugEnabled()) {
+ if (this.logger.isDebugEnabled()) {
--activeRequestCount;
}
Core.cleanup();
- EnvironmentHelper.checkEnvironment(environmentDepth, getLogger());
+ EnvironmentHelper.checkEnvironment(environmentDepth, this.logger);
}
}
/**
* @see org.apache.cocoon.Processor#buildPipeline(org.apache.cocoon.environment.Environment)
*/
- public InternalPipelineDescription buildPipeline(Environment environment)
- throws Exception {
- if (disposed) {
- throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
- }
-
+ public InternalPipelineDescription buildPipeline(Environment environment) throws Exception {
try {
- if (getLogger().isDebugEnabled()) {
+ if (this.logger.isDebugEnabled()) {
++activeRequestCount;
debug(environment, true);
}
@@ -487,7 +278,7 @@
return this.processor.buildPipeline(environment);
} finally {
- if (getLogger().isDebugEnabled()) {
+ if (this.logger.isDebugEnabled()) {
--activeRequestCount;
}
}
@@ -502,6 +293,7 @@
/**
* Return this (Cocoon is always at the root of the processing chain).
+ *
* @since 2.1.1
*/
public Processor getRootProcessor() {
@@ -530,13 +322,6 @@
}
/**
- * FIXME - Do we really need this method?
- */
- public ServiceManager getServiceManager() {
- return this.serviceManager;
- }
-
- /**
* @see org.apache.cocoon.Processor#getAttribute(java.lang.String)
*/
public Object getAttribute(String name) {
@@ -551,10 +336,10 @@
}
/**
- * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object)
+ * @see org.apache.cocoon.Processor#setAttribute(java.lang.String,
+ * java.lang.Object)
*/
public void setAttribute(String name, Object value) {
this.processorAttributes.put(name, value);
}
-
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java Mon Feb 20 01:08:40 2006
@@ -93,9 +93,7 @@
if (this.initialized == false) {
super.initialize();
- this.sourceResolver =
- (SourceResolver) getServiceManager().lookup(
- SourceResolver.ROLE);
+ this.sourceResolver = (SourceResolver)this.coreUtil.getCore().getCurrentSitemap().getComponentLocator().getComponent(SourceResolver.ROLE);
initialized = true;
}
@@ -317,12 +315,13 @@
}
}
+ /**
+ * @see org.apache.cocoon.bean.CocoonWrapper#dispose()
+ */
public void dispose() {
if (this.initialized) {
- if (this.sourceResolver != null) {
- getServiceManager().release(this.sourceResolver);
- this.sourceResolver = null;
- }
+ this.coreUtil.getCore().getCurrentSitemap().getComponentLocator().release(this.sourceResolver);
+ this.sourceResolver = null;
super.dispose();
}
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java Mon Feb 20 01:08:40 2006
@@ -33,7 +33,6 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.Cocoon;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
@@ -90,7 +89,7 @@
private boolean initialized = false;
- private CoreUtil coreUtil;
+ protected CoreUtil coreUtil;
/**
* INITIALISATION METHOD.
@@ -120,14 +119,10 @@
env.setLoggingConfiguration(this.logKit);
env.setConfigFile(this.conf);
env.setLoadClassList(this.classList);
- this.coreUtil = new CoreUtil(env);
+ this.coreUtil = new CoreUtil(env, cliContext);
this.cocoon = this.coreUtil.createCocoon();
this.log = env.logger;
this.initialized = true;
- }
-
- protected ServiceManager getServiceManager() {
- return cocoon.getServiceManager();
}
/**
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=379064&r1=379063&r2=379064&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 Mon Feb 20 01:08:40 2006
@@ -31,33 +31,27 @@
import java.util.Map;
import java.util.Properties;
-import org.apache.avalon.excalibur.logger.Log4JConfLoggerManager;
-import org.apache.avalon.excalibur.logger.LoggerManageable;
-import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.configuration.Configurable;
+import javax.servlet.ServletContext;
+
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.Cocoon;
import org.apache.cocoon.Constants;
-import org.apache.cocoon.Modifiable;
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.container.ComponentContext;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
import org.apache.cocoon.configuration.ConfigurationBuilder;
-import org.apache.cocoon.core.container.SingleComponentServiceManager;
-import org.apache.cocoon.core.logging.CocoonLogKitLoggerManager;
-import org.apache.cocoon.core.logging.PerRequestLoggerManager;
-import org.apache.cocoon.core.logging.SettingsContext;
+import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
+import org.apache.cocoon.core.container.spring.AvalonEnvironment;
+import org.apache.cocoon.core.container.spring.ConfigReader;
+import org.apache.cocoon.core.container.spring.ConfigurationInfo;
import org.apache.cocoon.core.source.SimpleSourceResolver;
-import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.matching.helpers.WildcardHelper;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.StringUtils;
import org.apache.cocoon.util.location.Location;
@@ -66,6 +60,9 @@
import org.apache.excalibur.source.Source;
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.xml.sax.InputSource;
/**
* This is an utility class to create a new Cocoon instance.
@@ -89,26 +86,26 @@
/** The settings. */
protected MutableSettings settings;
- /** The parent service manager. */
- protected ServiceManager parentManager;
-
/** The root logger. */
protected Logger log;
- /** The logger manager. */
- protected LoggerManager loggerManager;
-
/** The Root processor instance */
protected Processor processor;
- /** Is this a per request logger manager */
- protected boolean isPerRequestLoggerManager = false;
-
protected ClassLoader classloader;
/** The core object. */
protected Core core;
+ /** The servlet context. */
+ protected final ServletContext servletContext;
+
+ /** The container. */
+ protected ApplicationContext container;
+
+ /** The configuration file */
+ protected Source configurationFile;
+
// Register the location finder for Avalon configuration objects and exceptions
// and keep a strong reference to it.
private static final LocationUtils.LocationFinder confLocFinder = new LocationUtils.LocationFinder() {
@@ -163,11 +160,13 @@
* @param environment The hook back to the environment.
* @throws Exception
*/
- public CoreUtil(BootstrapEnvironment environment)
+ public CoreUtil(BootstrapEnvironment environment,
+ ServletContext context)
throws Exception {
+ this.servletContext = context;
this.env = environment;
this.init();
- this.createClassloader();
+ this.createClassloader();
}
protected void init()
@@ -220,7 +219,7 @@
this.settings.setWorkDirectory(workDir.getAbsolutePath());
// Init logger
- this.initLogger();
+ this.log = ApplicationContextFactory.createRootLogger(servletContext, this.settings.getCocoonLogger());
this.env.setLogger(this.log);
// Output some debug info
@@ -317,9 +316,6 @@
// create the Core object
this.core = this.createCore();
- // create parent service manager
- this.parentManager = new SingleComponentServiceManager(null, this.core, Core.ROLE);
-
// settings can't be changed anymore
settings.makeReadOnly();
@@ -327,6 +323,9 @@
// The Cocoon container fetches the Core object using the context.
// FIXME - We shouldn't need this - check where it is used
this.appContext.put(Core.ROLE, core);
+
+ // test the setup of the spring based container
+ this.container = this.setupSpringContainer();
}
/**
@@ -524,31 +523,6 @@
}
/**
- * Initialize the current request.
- * This method can be used to initialize anything required for processing
- * the request. For example, if the logger manager is a {@link PerRequestLoggerManager}
- * than this manager is invoked to initialize the logging context for the request.
- * This method returns a handle that should be used to clean up everything
- * when the request is finished by calling {@link #cleanUpRequest(Object)}.
- */
- public Object initializeRequest(Environment env) {
- if ( this.isPerRequestLoggerManager ) {
- return ((PerRequestLoggerManager)this.loggerManager).initializePerRequestLoggingContext(env);
- }
- return null;
- }
-
- /**
- * Cleanup everything initialized during the request processing in
- * {@link #initializeRequest(Environment)}.
- */
- public void cleanUpRequest(Object handle) {
- if ( handle != null && this.isPerRequestLoggerManager) {
- ((PerRequestLoggerManager)this.loggerManager).cleanPerRequestLoggingContext(handle);
- }
- }
-
- /**
* Create a simple source resolver.
*/
protected SourceResolver createSourceResolver(Logger logger) {
@@ -564,184 +538,6 @@
return resolver;
}
- protected void initLogger() {
- String logLevel = settings.getBootstrapLogLevel();
- if (logLevel == null) {
- logLevel = "INFO";
- }
-
- String accesslogger = settings.getEnvironmentLogger();
- if (accesslogger == null) {
- accesslogger = "cocoon";
- }
-
- // create bootstrap logger
- final BootstrapEnvironment.LogLevel level = BootstrapEnvironment.LogLevel.getLogLevelForName(logLevel);
- final Logger bootstrapLogger = this.env.getBootstrapLogger(level);
-
- // Create our own resolver
- final SourceResolver resolver = this.createSourceResolver(bootstrapLogger);
-
- // create an own service manager for the logger manager
- final ServiceManager loggerManagerServiceManager = new SingleComponentServiceManager(
- null, resolver, SourceResolver.ROLE);
-
- // create an own context for the logger manager
- final DefaultContext subcontext = new SettingsContext(this.appContext, this.settings);
- subcontext.put("context-work", new File(this.settings.getWorkDirectory()));
- if (this.env.getContextForWriting() == null) {
- File logSCDir = new File(this.settings.getWorkDirectory(), "log");
- logSCDir.mkdirs();
- subcontext.put("context-root", logSCDir.toString());
- } else {
- subcontext.put("context-root", this.env.getContextForWriting().toString());
- }
- this.env.configureLoggingContext(subcontext);
-
- String loggerManagerClass = settings.getLoggerManagerClassName();
-
- // the log4j support requires currently that the log4j system is already
- // configured elsewhere
-
- final LoggerManager loggerManager = this.newLoggerManager(loggerManagerClass);
- ContainerUtil.enableLogging(loggerManager, bootstrapLogger);
-
- try {
- ContainerUtil.contextualize(loggerManager, subcontext);
- ContainerUtil.service(loggerManager, loggerManagerServiceManager);
-
- this.loggerManager = loggerManager;
-
- if (loggerManager instanceof Configurable) {
- //Configure the logkit management
- String logkitConfig = settings.getLoggingConfiguration();
-
- if ( logkitConfig != null ) {
- Source source = null;
- try {
- source = resolver.resolveURI(logkitConfig);
- final ConfigurationBuilder builder = new ConfigurationBuilder(
- settings);
- final Configuration conf = builder.build(source.getInputStream());
- final DefaultConfiguration categories = (DefaultConfiguration) conf
- .getChild("categories");
- final DefaultConfiguration targets = (DefaultConfiguration) conf
- .getChild("targets");
- final DefaultConfiguration factories = (DefaultConfiguration) conf
- .getChild("factories");
-
- // now process includes
- final Configuration[] children = conf
- .getChildren("include");
- for (int i = 0; i < children.length; i++) {
- String directoryURI = children[i].getAttribute("dir");
- final String pattern = children[i].getAttribute(
- "pattern", null);
- int[] parsedPattern = null;
- if (pattern != null) {
- parsedPattern = WildcardHelper
- .compilePattern(pattern);
- }
- Source directory = null;
- try {
- directory = resolver.resolveURI(directoryURI,
- source.getURI(), CONTEXT_PARAMETERS);
- if (directory instanceof TraversableSource) {
- final Iterator c = ((TraversableSource) directory)
- .getChildren().iterator();
- while (c.hasNext()) {
- final Source s = (Source) c.next();
- if (parsedPattern == null
- || this.match(s.getURI(),
- parsedPattern)) {
- final Configuration includeConf = builder
- .build(s.getInputStream());
- // add targets and categories
- categories.addAllChildren(includeConf
- .getChild("categories"));
- targets.addAllChildren(includeConf
- .getChild("targets"));
- factories.addAllChildren(includeConf
- .getChild("factories"));
- }
- }
- } else {
- throw new ConfigurationException(
- "Include.dir must point to a directory, '"
- + directory.getURI()
- + "' is not a directory.'");
- }
- } catch (IOException ioe) {
- throw new ConfigurationException(
- "Unable to read configurations from "
- + directoryURI);
- } finally {
- resolver.release(directory);
- }
-
- // finally remove include
- ((DefaultConfiguration) conf).removeChild(children[i]);
- }
- // override log level?
- if (settings.getOverrideLogLevel() != null) {
- this.overrideLogLevel(conf.getChild("categories"),
- settings.getOverrideLogLevel());
- }
- ContainerUtil.configure(loggerManager, conf);
- } finally {
- resolver.release(source);
- }
- }
- }
- ContainerUtil.initialize(loggerManager);
- } catch (Exception e) {
- bootstrapLogger.error(
- "Could not set up Cocoon Logger, will use screen instead",
- e);
- }
-
- this.log = this.loggerManager.getLoggerForCategory(accesslogger);
- }
-
- /**
- * Create a new logger manager.
- * @param loggerManagerClass The class name or one of the allowed shortcuts.
- * @return A new logger manager.
- */
- private LoggerManager newLoggerManager(String loggerManagerClass) {
- if ("LogKit".equalsIgnoreCase(loggerManagerClass) || loggerManagerClass == null) {
- loggerManagerClass = CocoonLogKitLoggerManager.class.getName();
- } else if ("LOG4J".equalsIgnoreCase(loggerManagerClass)) {
- loggerManagerClass = Log4JConfLoggerManager.class.getName();
- }
- try {
- Class clazz = Class.forName(loggerManagerClass);
- if ( PerRequestLoggerManager.class.isAssignableFrom(clazz) ) {
- this.isPerRequestLoggerManager = true;
- }
- return (LoggerManager) clazz.newInstance();
- } catch (Exception e) {
- this.isPerRequestLoggerManager = true;
- return new CocoonLogKitLoggerManager();
- }
- }
-
- protected void overrideLogLevel(Configuration root, String value) {
- Configuration[] c = root.getChildren("category");
- for(int i=0;i<c.length;i++) {
- ((DefaultConfiguration)c[i]).setAttribute("log-level", value);
- this.overrideLogLevel(c[i], value);
- }
- }
-
- private boolean match(String uri, int[] parsedPattern ) {
- int pos = uri.lastIndexOf('/');
- if ( pos != -1 ) {
- uri = uri.substring(pos+1);
- }
- return WildcardHelper.match(null, uri, parsedPattern);
- }
-
/**
* Create the classloader that inlcudes all the [block]/BLOCK-INF/classes directories.
* @throws Exception
@@ -826,22 +622,12 @@
if (this.log.isInfoEnabled()) {
this.log.info("Reloading from: " + this.settings.getConfiguration());
}
- Processor p = (Processor)ClassUtils.newInstance(this.settings.getProcessorClassName());
- ContainerUtil.enableLogging(p, getCocoonLogger());
- if (p instanceof LoggerManageable) {
- ((LoggerManageable)p).setLoggerManager(this.loggerManager);
- }
- ContainerUtil.contextualize(p, this.appContext);
+ Processor p = (Processor)this.container.getBean("org.apache.cocoon.Cocoon");
- this.parentManager = new SingleComponentServiceManager(null, this.core, Core.ROLE);
- ContainerUtil.service(p, this.parentManager);
-
- ContainerUtil.initialize(p);
this.settings.setCreationTime(System.currentTimeMillis());
this.processor = p;
} catch (Exception e) {
this.log.error("Exception reloading root processor.", e);
- this.disposeProcessor();
throw e;
}
return this.processor;
@@ -854,7 +640,6 @@
*/
public Processor getProcessor(final String pathInfo, final String reloadParam)
throws Exception {
-
// set the blocks classloader for this thread
Thread.currentThread().setContextClassLoader(this.classloader);
@@ -862,7 +647,7 @@
boolean reload = false;
if (this.processor != null) {
- if (this.processor instanceof Modifiable && ((Modifiable)this.processor).modifiedSince(this.settings.getCreationTime())) {
+ if (this.settings.getCreationTime() < this.configurationFile.getLastModified()) {
if (this.log.isInfoEnabled()) {
this.log.info("Configuration changed reload attempt");
}
@@ -881,6 +666,9 @@
}
if (reload) {
+ if (this.container != null) {
+ this.container = null;
+ }
this.init();
this.createProcessor();
}
@@ -888,27 +676,44 @@
return this.processor;
}
- /**
- * Destroy root processor
- */
- protected final void disposeProcessor() {
- if (this.processor != null) {
- if (this.log.isDebugEnabled()) {
- this.log.debug("Disposing root processor");
- }
- ContainerUtil.dispose(this.processor);
- this.processor = null;
+ protected ApplicationContext setupSpringContainer() throws Exception {
+ if (this.log.isInfoEnabled()) {
+ this.log.info("Reading root configuration: " + this.settings.getConfiguration());
+ }
+
+ URLSource urlSource = new URLSource();
+ urlSource.init(new URL(this.settings.getConfiguration()), null);
+ this.configurationFile = new DelayedRefreshSourceWrapper(urlSource,
+ this.settings.getReloadDelay("config"));
+ final InputSource is = SourceUtil.getInputSource(this.configurationFile);
+
+ final ConfigurationBuilder builder = new ConfigurationBuilder(settings);
+ final Configuration rootConfig = builder.build(is);
+
+ if (!"cocoon".equals(rootConfig.getName())) {
+ throw new ConfigurationException("Invalid configuration file\n" + rootConfig.toString());
+ }
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Configuration version: " + rootConfig.getAttribute("version"));
+ }
+ if (!Constants.CONF_VERSION.equals(rootConfig.getAttribute("version"))) {
+ throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
}
- ContainerUtil.dispose(this.parentManager);
- this.parentManager = null;
- }
- protected Logger getCocoonLogger() {
- final String rootlogger = this.settings.getCocoonLogger();
- if (rootlogger != null) {
- return this.loggerManager.getLoggerForCategory(rootlogger);
+ if (this.log.isInfoEnabled()) {
+ this.log.info("Setting up root Spring container.");
}
- return this.log;
+ AvalonEnvironment env = new AvalonEnvironment();
+ env.context = this.appContext;
+ env.core = this.core;
+ env.logger = this.log;
+ env.servletContext = this.env.getEnvironmentContext();
+ 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);
+
+ return mainContext;
}
/**
@@ -998,7 +803,10 @@
* Dispose the root processor when environment is destroyed
*/
public void destroy() {
- this.disposeProcessor();
+ // FIXME - we have to clean up here!
+ if ( this.container != null ) {
+ this.container = null;
+ }
}
/**
@@ -1130,4 +938,4 @@
// we ignore warn
}
}
-}
+}
\ No newline at end of file
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/XmlConfigCreator.java Mon Feb 20 01:08:40 2006
@@ -27,7 +27,6 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.Cocoon;
import org.apache.cocoon.Processor;
-import org.apache.cocoon.SpringCocoon;
import org.springframework.util.StringUtils;
/**
@@ -161,7 +160,7 @@
if ( addCocoon ) {
buffer.append("<bean");
this.appendAttribute(buffer, "id", Cocoon.class.getName());
- this.appendAttribute(buffer, "class", SpringCocoon.class.getName());
+ this.appendAttribute(buffer, "class", Cocoon.class.getName());
this.appendAttribute(buffer, "singleton", "true");
buffer.append(">\n");
buffer.append(" <constructor-arg ref=\"");
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/servlet/CocoonServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/servlet/CocoonServlet.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/servlet/CocoonServlet.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/servlet/CocoonServlet.java Mon Feb 20 01:08:40 2006
@@ -182,7 +182,7 @@
ServletBootstrapEnvironment env = new ServletBootstrapEnvironment(conf, this.servletContextPath, this.servletContextURL);
try {
- this.coreUtil = new CoreUtil(env);
+ this.coreUtil = new CoreUtil(env, this.servletContext);
this.environmentContext = env.getEnvironmentContext();
this.log = env.logger;
} catch (Exception e) {
@@ -328,7 +328,6 @@
}
String contentType = null;
- Object handle = null;
Environment env;
try{
@@ -350,8 +349,6 @@
try {
try {
- handle = this.coreUtil.initializeRequest(env);
-
if (this.processor.process(env)) {
contentType = env.getContentType();
} else {
@@ -435,8 +432,6 @@
}
}
} finally {
- this.coreUtil.cleanUpRequest(handle);
-
try {
if (request instanceof MultipartHttpServletRequest) {
if (getLogger().isDebugEnabled()) {
Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/environment/portlet/PortletContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/environment/portlet/PortletContext.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/environment/portlet/PortletContext.java (original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/environment/portlet/PortletContext.java Mon Feb 20 01:08:40 2006
@@ -15,7 +15,6 @@
*/
package org.apache.cocoon.environment.portlet;
-import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.NullLogger;
import org.apache.cocoon.environment.impl.AbstractContext;
Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java?rev=379064&r1=379063&r2=379064&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java (original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java Mon Feb 20 01:08:40 2006
@@ -227,7 +227,7 @@
PortletBootstrapEnvironment env = new PortletBootstrapEnvironment(conf, this.portletContextPath, this.portletContextURL);
try {
- this.coreUtil = new CoreUtil(env);
+ this.coreUtil = new CoreUtil(env, env.getEnvironmentContext());
this.environmentContext = env.getEnvironmentContext();
this.log = env.logger;
} catch (Exception e) {