Author: cziegeler
Date: Tue Mar 15 11:42:21 2005
New Revision: 157579
URL: http://svn.apache.org/viewcvs?view=rev&rev=157579
Log:
Start prototyp of application container support
Added:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java
(with props)
cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
(with props)
Modified:
cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java?view=diff&r1=157578&r2=157579
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java Tue Mar 15
11:42:21 2005
@@ -16,9 +16,13 @@
*/
package org.apache.cocoon.core;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.context.Context;
@@ -118,4 +122,60 @@
}
}
+ /**
+ * Get the settings for Cocoon
+ * @param env This provides access to various parts of the used
environment.
+ */
+ public static Settings createSettings(BootstrapEnvironment env) {
+ // create an empty settings objects
+ final Settings s = new Settings();
+
+ String additionalPropertyFile =
System.getProperty(Settings.PROPERTY_USER_SETTINGS);
+
+ // read cocoon-settings.properties - if available
+ InputStream propsIS = env.getInputStream("cocoon-settings.properties");
+ if ( propsIS != null ) {
+ env.log("Reading settings from 'cocoon-settings.properties'");
+ final Properties p = new Properties();
+ try {
+ p.load(propsIS);
+ propsIS.close();
+ s.fill(p);
+ additionalPropertyFile =
p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
+ } catch (IOException ignore) {
+ env.log("Unable to read 'cocoon-settings.properties'.",
ignore);
+ env.log("Continuing initialization.");
+ }
+ }
+ // fill from the environment configuration, like web.xml etc.
+ env.configure(s);
+
+ // read additional properties file
+ if ( additionalPropertyFile != null ) {
+ env.log("Reading user settings from '" + additionalPropertyFile +
"'");
+ final Properties p = new Properties();
+ try {
+ FileInputStream fis = new
FileInputStream(additionalPropertyFile);
+ p.load(fis);
+ fis.close();
+ } catch (IOException ignore) {
+ env.log("Unable to read '" + additionalPropertyFile + "'.",
ignore);
+ env.log("Continuing initialization.");
+ }
+ }
+ // now overwrite with system properties
+ s.fill(System.getProperties());
+
+ return s;
+ }
+
+ public static interface BootstrapEnvironment {
+
+ void log(String message);
+ void log(String message, Throwable error);
+
+ InputStream getInputStream(String path);
+
+ void configure(Settings settings);
+ }
}
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&r1=157578&r2=157579
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Tue Mar 15 11:42:21 2005
@@ -27,6 +27,7 @@
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.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.service.ServiceManager;
@@ -40,7 +41,10 @@
import org.apache.cocoon.environment.internal.EnvironmentHelper;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.sitemap.ComponentLocator;
import org.apache.cocoon.sitemap.PatternException;
+import org.apache.cocoon.sitemap.impl.ComponentManager;
+import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.StringUtils;
import org.apache.regexp.RE;
@@ -93,16 +97,32 @@
Thread currentThread = Thread.currentThread();
ClassLoader oldClassLoader = currentThread.getContextClassLoader();
currentThread.setContextClassLoader(newClassLoader);
- CocoonServiceManager newManager;
+ ServiceManager newManager;
try {
newManager = new CocoonServiceManager(this.parentProcessorManager,
newClassLoader);
// Go through the component lifecycle
- newManager.enableLogging(getLogger());
- newManager.contextualize(context);
- newManager.configure(config);
- newManager.initialize();
+ ContainerUtil.enableLogging(newManager, this.getLogger());
+ ContainerUtil.contextualize(newManager, context);
+ ContainerUtil.configure(newManager, config);
+ ContainerUtil.initialize(newManager);
+
+ // check for an application specific container
+ Configuration appContainer =
config.getChild("application-container", false);
+ if ( appContainer != null ) {
+ final String clazzName = appContainer.getAttribute("class");
+
+ ComponentLocator cl =
(ComponentLocator)ClassUtils.newInstance(clazzName);
+ // Go through the component lifecycle
+ ContainerUtil.enableLogging(cl, this.getLogger());
+ ContainerUtil.contextualize(cl, context);
+ ContainerUtil.service(cl, newManager);
+ ContainerUtil.configure(cl, appContainer);
+ ContainerUtil.initialize(cl);
+
+ newManager = new ComponentManager(newManager, cl);
+ }
} finally {
currentThread.setContextClassLoader(oldClassLoader);
}
Modified: cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java?view=diff&r1=157578&r2=157579
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/servlet/CocoonServlet.java Tue Mar
15 11:42:21 2005
@@ -16,7 +16,6 @@
package org.apache.cocoon.servlet;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -158,55 +157,7 @@
/** Settings */
protected Settings settings;
-
- /**
- * Get the settings for Cocoon
- * If a subclass uses different default values for settings, this method
- * can be overwritten
- */
- protected Settings getSettings() {
- // create an empty settings objects
- final Settings s = new Settings();
- String additionalPropertyFile =
System.getProperty(Settings.PROPERTY_USER_SETTINGS);
-
- // read cocoon-settings.properties - if available
- InputStream propsIS =
this.getServletContext().getResourceAsStream("cocoon-settings.properties");
- if ( propsIS != null ) {
- this.servletContext.log("Reading settings from
'cocoon-settings.properties'");
- final Properties p = new Properties();
- try {
- p.load(propsIS);
- propsIS.close();
- s.fill(p);
- additionalPropertyFile =
p.getProperty(Settings.PROPERTY_USER_SETTINGS, additionalPropertyFile);
- } catch (IOException ignore) {
- this.servletContext.log("Unable to read
'cocoon-settings.properties'.", ignore);
- this.servletContext.log("Continuing initialization.");
- }
- }
- // fill from the servlet parameters
- SettingsHelper.fill(s, this.getServletConfig());
-
- // read additional properties file
- if ( additionalPropertyFile != null ) {
- this.servletContext.log("Reading user settings from '" +
additionalPropertyFile + "'");
- final Properties p = new Properties();
- try {
- FileInputStream fis = new
FileInputStream(additionalPropertyFile);
- p.load(fis);
- fis.close();
- } catch (IOException ignore) {
- this.servletContext.log("Unable to read '" +
additionalPropertyFile + "'.", ignore);
- this.servletContext.log("Continuing initialization.");
- }
- }
- // now overwrite with system properties
- s.fill(System.getProperties());
-
- return s;
- }
-
/**
* Initialize this <code>CocoonServlet</code> instance. You will
* notice that I have broken the init into sub methods to make it
@@ -227,7 +178,10 @@
super.init(conf);
// initialize settings
- this.settings = this.getSettings();
+ Core.BootstrapEnvironment env = new ServletBootstrapEnvironment(conf);
+
+ this.settings = Core.createSettings(env);
+
this.appContext.put(Core.CONTEXT_SETTINGS, this.settings);
if (this.settings.isInitClassloader()) {
@@ -1340,4 +1294,32 @@
protected LoggerManager getLoggerManager() {
return this.loggerManager;
}
+
+ protected static final class ServletBootstrapEnvironment
+ implements Core.BootstrapEnvironment {
+
+ private final ServletConfig config;
+
+ public ServletBootstrapEnvironment(ServletConfig config) {
+ this.config = config;
+ }
+
+ public void log(String message) {
+ this.config.getServletContext().log(message);
+ }
+
+ public void log(String message, Throwable error) {
+ this.config.getServletContext().log(message, error);
+ }
+
+ public InputStream getInputStream(String path) {
+ return this.config.getServletContext().getResourceAsStream(path);
+ }
+
+ public void configure(Settings settings) {
+ // fill from the servlet parameters
+ SettingsHelper.fill(settings, this.config);
+ }
+ }
+
}
Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java?view=auto&rev=157579
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java
(added)
+++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java Tue
Mar 15 11:42:21 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sitemap;
+
+
+/**
+ * TODO WORK IN PROGRESS!!
+ *
+ * This interface is the connection between the Cocoon core components
+ * and an optional application/sitemap container.
+ *
+ * @since 2.2
+ * @version $Id:$
+ */
+public interface ComponentLocator {
+
+ Object lookup(String key);
+
+ void release(Object component);
+
+ boolean hasComponent(String key);
+}
Propchange:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/ComponentLocator.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java?view=auto&rev=157579
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
(added)
+++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
Tue Mar 15 11:42:21 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sitemap.impl;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.sitemap.ComponentLocator;
+
+
+/**
+ * This is the connection between the Cocoon core components
+ * and an optional application/sitemap container.
+ *
+ * It acts as a service manager and as a component locator at the same time.
+ * A component manager is initialized with both, a service manager for a
sitemap
+ * and an optional component locator for the sitemap. Each operation (lookup
etc.)
+ * is first performed on the component locator. If the locator does not have
+ * the component in question, the service manager is asked.
+ *
+ * @since 2.2
+ * @version $Id:$
+ */
+public class ComponentManager implements ServiceManager, ComponentLocator {
+
+ final protected ServiceManager serviceManager;
+ final protected ComponentLocator componentLocator;
+
+ public ComponentManager(final ServiceManager sm, final ComponentLocator
cl) {
+ this.serviceManager = sm;
+ this.componentLocator = cl;
+ }
+
+ /**
+ * @see
org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
+ */
+ public boolean hasService(String key) {
+ boolean result = false;
+ if ( this.componentLocator != null ) {
+ result = this.componentLocator.hasComponent(key);
+ }
+ if ( !result ) {
+ result = this.serviceManager.hasService(key);
+ }
+ return result;
+ }
+
+ /**
+ * @see
org.apache.cocoon.sitemap.ComponentLocator#release(java.lang.Object)
+ * @see
org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
+ */
+ public void release(Object component) {
+ // FIXME - we should optimize this
+ if ( this.componentLocator != null ) {
+ this.componentLocator.release(component);
+ }
+ this.serviceManager.release(component);
+ }
+
+ /**
+ * @see
org.apache.cocoon.sitemap.ComponentLocator#hasComponent(java.lang.String)
+ */
+ public boolean hasComponent(String key) {
+ return this.hasService(key);
+ }
+ /**
+ * @see org.apache.cocoon.sitemap.ComponentLocator#lookup(java.lang.String)
+ * @see
org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
+ */
+ public Object lookup(String key) {
+ Object component = null;
+ if ( this.componentLocator != null ) {
+ if ( this.componentLocator.hasComponent(key) ) {
+ component = this.componentLocator.lookup(key);
+ }
+ }
+ if ( component == null && this.serviceManager.hasService(key) ) {
+ try {
+ component = this.serviceManager.lookup(key);
+ } catch (ServiceException se) {
+ throw new CascadingRuntimeException("Unable to lookup
component: " + key, se);
+ }
+ }
+ return component;
+ }
+}
Propchange:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cocoon/trunk/src/java/org/apache/cocoon/sitemap/impl/ComponentManager.java
------------------------------------------------------------------------------
svn:keywords = Id