Author: cziegeler
Date: Sat Mar 12 11:17:13 2005
New Revision: 157268
URL: http://svn.apache.org/viewcvs?view=rev&rev=157268
Log:
Move lazyMode configuration into settings object.
Create new Core object.
Code formatting
Modified:
cocoon/blocks/unsupported/profiler/trunk/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java
Modified:
cocoon/blocks/unsupported/profiler/trunk/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
URL:
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/profiler/trunk/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java?view=diff&r1=157267&r2=157268
==============================================================================
---
cocoon/blocks/unsupported/profiler/trunk/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
(original)
+++
cocoon/blocks/unsupported/profiler/trunk/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
Sat Mar 12 11:17:13 2005
@@ -55,7 +55,7 @@
*/
public void service(ServiceManager manager) throws ServiceException {
super.service(manager);
-` this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
+ this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
}
/**
Modified:
cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java?view=diff&r1=157267&r2=157268
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/configuration/Settings.java
Sat Mar 12 11:17:13 2005
@@ -275,6 +275,12 @@
public static final String KEY_CONFIGURATION_RELOAD_DELAY =
"configuration.reloaddelay";
/**
+ * Lazy mode for component loading
+ */
+ protected boolean lazyMode = false;
+ public static final String KEY_LAZY_MODE = "core.LazyMode";
+
+ /**
* Create a new settings object
*/
public Settings() {
@@ -340,6 +346,8 @@
this.formEncoding = value;
} else if ( key.equals(KEY_LOGGING_OVERRIDE_LOGLEVEL) ) {
this.overrideLogLevel = value;
+ } else if ( key.equals(KEY_LAZY_MODE) ) {
+ this.lazyMode = BooleanUtils.toBoolean(value);
}
}
}
@@ -695,6 +703,20 @@
this.configurationReloadDelay = configurationReloadDelay;
}
+ /**
+ * @return Returns the lazyMode.
+ */
+ public boolean isLazyMode() {
+ return this.lazyMode;
+ }
+
+ /**
+ * @param lazyMode The lazyMode to set.
+ */
+ public void setLazyMode(boolean lazyMode) {
+ this.lazyMode = lazyMode;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -725,7 +747,8 @@
KEY_WORK_DIRECTORY + " : " + this.workDirectory + '\n' +
KEY_FORM_ENCODING + " : " + this.formEncoding + '\n' +
KEY_SHOWTIME + " : " + this.showTime + '\n' +
- KEY_HIDE_SHOWTIME + " : " + this.hideShowTime + '\n';
+ KEY_HIDE_SHOWTIME + " : " + this.hideShowTime + '\n' +
+ KEY_LAZY_MODE + " : " + this.lazyMode + '\n';
}
public String getProperty(String name) {
@@ -785,6 +808,8 @@
value = this.formEncoding;
} else if ( sKey.equals(KEY_LOGGING_OVERRIDE_LOGLEVEL) ) {
value = this.overrideLogLevel;
+ } else if ( sKey.equals(KEY_LAZY_MODE) ) {
+ value = String.valueOf(this.lazyMode);
}
}
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=157267&r2=157268
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java Sat Mar 12
11:17:13 2005
@@ -1,16 +1,16 @@
-/*
+/*
* 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
- *
+ * 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.
*/
@@ -23,20 +23,43 @@
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
import org.apache.cocoon.configuration.Settings;
/**
- * The Core
- *
+ * This is the core Cocoon component.
+ * It can be looked up to get access to various information about the
+ * current installation.
+ *
+ * The core of Cocoon is a singleton object that is created on startup.
+ *
* @version SVN $Id$
+ * @since 2.2
*/
-public class Core {
+public class Core
+ implements Contextualizable {
- /** Application <code>Context</code> Key for the settings @since 2.2 */
+ /** Application <code>Context</code> Key for the settings. Please don't
+ * use this constant to lookup the settings object. Lookup the core
+ * component and use [EMAIL PROTECTED] #getSettings()} instead. */
public static final String CONTEXT_SETTINGS = "settings";
+ /**
+ * The cleanup threads that are invoked after the processing of a
+ * request is finished.
+ */
private static final ThreadLocal cleanup = new ThreadLocal();
-
+
+ /** The component context. */
+ private Context context;
+
+ /* (non-Javadoc)
+ * @see
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(Context context) throws ContextException {
+ this.context = context;
+ }
+
public static void addCleanupTask(CleanupTask task) {
List l = (List)cleanup.get();
if ( l == null ) {
@@ -45,7 +68,7 @@
}
l.add(task);
}
-
+
public static void cleanup() {
List l = (List)cleanup.get();
if ( l != null ) {
@@ -57,17 +80,34 @@
l.clear();
}
}
-
+
public static interface CleanupTask {
-
+
void invoke();
}
-
+
+ /**
+ * Return the settings.
+ */
+ public Settings getSettings() {
+ return getSettings(this.context);
+ }
+
/**
- * Return the current response
- * @param context The component context
- * @return The response
- * @since 2.2
+ * Return the component context.
+ * This method allows access to the component context for other components
+ * that are not created by an Avalon based container.
+ */
+ public Context getContext() {
+ return this.context;
+ }
+
+ /**
+ * Return the current settings.
+ * Please don't use this method directly, look up the Core component
+ * and use [EMAIL PROTECTED] #getSettings()} instead.
+ * @param context The component context.
+ * @return The settings.
*/
public static final Settings getSettings(Context context) {
// the settings object is always present
@@ -77,5 +117,5 @@
throw new CascadingRuntimeException("Unable to get the settings
object from the context.", ce);
}
}
-
+
}
Modified:
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java?view=diff&r1=157267&r2=157268
==============================================================================
---
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
(original)
+++
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CoreServiceManager.java
Sat Mar 12 11:17:13 2005
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright 2002-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
- *
+ * 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.
*/
@@ -65,16 +65,16 @@
public class CoreServiceManager
extends AbstractLogEnabled
implements Contextualizable, ThreadSafe, Disposable, Initializable,
ServiceManager, Configurable {
-
+
/**
* An empty configuration object, that can be used when no configuration
is known but one
* is needed.
*/
public static final Configuration EMPTY_CONFIGURATION = new
DefaultConfiguration("-", "unknown location");
-
+
/** Parameter map for the context protocol */
protected static final Map CONTEXT_PARAMETERS =
Collections.singletonMap("force-traversable", Boolean.TRUE);
-
+
/** The application context for components */
protected Context context;
@@ -95,20 +95,21 @@
/** LoggerManager. */
protected LoggerManager loggerManager;
-
+
private ComponentEnvironment componentEnv;
-
- private boolean lazyMode =
Boolean.getBoolean("org.apache.cocoon.core.LazyMode");
-
+
+ /** The settings */
+ private Settings settings;
+
/** The location where this manager is defined */
protected String location;
-
+
/** The parent ServiceManager */
protected ServiceManager parentManager;
-
+
/** The classloader to get classes from */
protected ClassLoader classloader;
-
+
/** The resolver used to resolve includes. It is lazily loaded in [EMAIL
PROTECTED] #getSourceResolver()}. */
private SourceResolver cachedSourceResolver;
@@ -121,14 +122,14 @@
public CoreServiceManager( final ServiceManager parent, final ClassLoader
classloader ) {
this.parentManager = parent;
this.classloader = classloader;
-
+
RoleManager parentRoleManager = null;
// get role manager and logger manager
if ( parent instanceof CoreServiceManager ) {
parentRoleManager = ((CoreServiceManager)parent).roleManager;
this.loggerManager = ((CoreServiceManager)parent).loggerManager;
}
-
+
// Always create a role manager, it can be filled several times either
through
// the root "roles" attribute or through loading of includes
this.roleManager = new RoleManager(parentRoleManager);
@@ -144,8 +145,6 @@
public void enableLogging(Logger logger) {
super.enableLogging(logger);
this.roleManager.enableLogging(logger);
- String msg = "Lazy mode: " + this.lazyMode;
- logger.debug(msg);
}
/* (non-Javadoc)
@@ -153,15 +152,16 @@
*/
public void contextualize( final Context context ) {
this.context = context;
+ this.settings = Core.getSettings(context);
}
-
+
/**
* Configure the LoggerManager.
*/
public void setLoggerManager( final LoggerManager manager ) {
this.loggerManager = manager;
}
-
+
public void setRoleManager (RoleManager rm) {
if (rm != null) {
// Override the one eventually got in the parent (see constructor)
@@ -173,12 +173,12 @@
* @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws
ConfigurationException {
-
+
this.componentEnv = new ComponentEnvironment(this.classloader,
getLogger(), this.roleManager, this.loggerManager, this.context, this);
-
+
// Setup location
this.location = configuration.getLocation();
-
+
// Find the current URI
String currentURI;
int pos = this.location.lastIndexOf(':');
@@ -189,7 +189,7 @@
pos = this.location.lastIndexOf(':', pos);
currentURI = this.location.substring(0, pos-1);
}
-
+
try {
// and load configuration with a empty list of loaded
configurations
parseConfiguration(configuration, currentURI, new HashSet());
@@ -227,7 +227,7 @@
throw e;
}
}
-
+
// Object[] keyArray = this.componentHandlers.keySet().toArray();
// java.util.Arrays.sort(keyArray);
// for (int i = 0; i < keyArray.length; i++) {
@@ -454,11 +454,11 @@
" but its handler could not be located." );
}
}
-
+
//=============================================================================================
// Additional public & protected contract
//=============================================================================================
-
+
/**
* Add a new component to the manager.
*
@@ -480,7 +480,7 @@
if (
"org.apache.cocoon.components.ExtendedComponentSelector".equals(className)) {
className = DefaultServiceSelector.class.getName();
}
-
+
if( this.getLogger().isDebugEnabled() ) {
this.getLogger().debug( "Adding component (" + role + " = " +
className + ")" );
}
@@ -491,7 +491,7 @@
// the new definition to feed this manager with its components.
checkComponentOverride(role, className, configuration, handler);
}
-
+
try {
handler = this.getComponentHandler(role, className, configuration,
info);
@@ -505,7 +505,7 @@
} catch( final Exception e ) {
throw new ConfigurationException( "Could not add component defined
at " + configuration.getLocation(), e );
}
-
+
// // Initialize shadow selector now, it will feed this service manager
// if ( DefaultServiceSelector.class.isAssignableFrom( component )) {
// try {
@@ -517,7 +517,7 @@
// }
// }
}
-
+
/**
* Add an existing object to the manager. The object should be fully
configured as no
* setup lifecycle methods are called. On manager disposal, the
<code>Disposable</code>
@@ -532,16 +532,16 @@
throw new ServiceException(role,
"Cannot add components to an initialized CoreServiceManager.");
}
-
+
ComponentHandler handler =
(ComponentHandler)this.componentHandlers.get(role);
if (handler != null) {
ComponentInfo info = handler.getInfo();
throw new ServiceException(role, "Component already defined at " +
info.getLocation());
}
-
+
this.componentHandlers.put(role, new
InstanceComponentHandler(getLogger(), instance));
}
-
+
/**
* Add an alias to a role, i.e. define a synonym for the role.
*
@@ -563,14 +563,14 @@
handler =
(ComponentHandler)current.componentHandlers.get(existingRole);
}
}
-
+
if (handler == null) {
throw new ServiceException(newRole, "Cannot alias non-existing
role " + existingRole);
}
-
+
this.componentHandlers.put(newRole, new
AliasComponentHandler(this.getLogger(), handler));
}
-
+
/**
* Initialize the component
* @throws ServiceException
@@ -579,11 +579,11 @@
throws ServiceException {
// we do nothing here, can be used in subclasses
}
-
+
//=============================================================================================
// Private methods
//=============================================================================================
-
+
/**
* Obtain a new ComponentHandler for the specified component.
*
@@ -609,8 +609,8 @@
}
info.setConfiguration(configuration);
info.setServiceClassName(className);
-
- if (!lazyMode || configuration.getAttributeAsBoolean("preload", false)
|| role.endsWith("Selector")) {
+
+ if (!this.settings.isLazyMode() ||
configuration.getAttributeAsBoolean("preload", false) ||
role.endsWith("Selector")) {
return AbstractComponentHandler.getComponentHandler(
role, this.componentEnv, info);
}
@@ -624,9 +624,9 @@
for( int i = 0; i < configurations.length; i++ ) {
final Configuration componentConfig = configurations[i];
-
+
final String componentName = componentConfig.getName();
-
+
if ("classpath".equals(componentName)) {
// Ignore
} else if ("include".equals(componentName)) {
@@ -645,7 +645,7 @@
"' at " + componentConfig.getLocation());
}
}
-
+
// Find the className
String className = componentConfig.getAttribute("class", null);
if (className == null) {
@@ -656,7 +656,7 @@
}
className = info.getServiceClassName();
}
-
+
// If it has a "name" attribute, add it to the role (similar
to the
// declaration within a service selector)
// Note: this has to be done *after* finding the className
above as we change the role
@@ -669,7 +669,7 @@
}
}
}
-
+
private void handleInclude(String contextURI, Set loadedURIs,
Configuration includeStatement)
throws ConfigurationException {
String includeURI = includeStatement.getAttribute("src", null);
@@ -682,10 +682,10 @@
throw new ConfigurationException("Include statement must either
have a 'src' or 'dir' attribute, at " +
includeStatement.getLocation());
}
-
+
// Setup the source resolver if needed
setupSourceResolver();
-
+
if ( includeURI != null ) {
Source src;
try {
@@ -727,9 +727,9 @@
throws ConfigurationException {
// If already loaded: do nothing
try {
-
+
String uri = src.getURI();
-
+
if (!loadedURIs.contains(uri)) {
if ( this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("Loading configuration from: " +
uri);
@@ -746,7 +746,7 @@
throw new ConfigurationException("Cannot load '" + uri +
"' at " + includeStatement.getLocation(), e);
}
loadedURIs.add(uri);
-
+
// what is it?
String includeKind = includeConfig.getName();
if (includeKind.equals("components")) {
@@ -764,14 +764,14 @@
this.cachedSourceResolver.release(src);
}
}
-
+
/**
* If the parent manager does not exist or does not
* provide a source resolver, a simple one is created here to load the
file.
*/
private void setupSourceResolver() {
if (this.cachedSourceResolver == null) {
-
+
if (this.parentManager != null &&
this.parentManager.hasService(SourceResolver.ROLE)) {
try {
this.cachedSourceResolver =
(SourceResolver)this.parentManager.lookup(SourceResolver.ROLE);
@@ -812,7 +812,7 @@
}
this.cachedSourceResolver = null;
}
-
+
/**
* Check if a component can be overriden. Only [EMAIL PROTECTED]
DefaultSelector} or its subclasses can be
* overriden, as they directly feed this manager with their component
definitions and are empty
@@ -827,7 +827,7 @@
throw new ConfigurationException("Role " + role + " redefined with
a different class name, at " +
config.getLocation());
}
-
+
Class clazz;
try {
clazz = this.componentEnv.loadClass(className);
Modified: cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles?view=diff&r1=157267&r2=157268
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles Sat Mar 12 11:17:13
2005
@@ -29,6 +29,10 @@
]>
<role-list>
+ <!-- This is the Cocoon core -->
+ <role name="org.apache.cocoon.core.Core"
+ default-class="org.apache.cocoon.core.Core"
+ model="singleton"/>
<role name="org.apache.cocoon.components.classloader.ClassLoaderFactory"
default-class="org.apache.cocoon.components.classloader.DefaultClassLoaderFactory"/>
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java?view=diff&r1=157267&r2=157268
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
Sat Mar 12 11:17:13 2005
@@ -24,7 +24,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.components.ComponentInfo;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
Modified:
cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java?view=diff&r1=157267&r2=157268
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java Sat
Mar 12 11:17:13 2005
@@ -359,6 +359,7 @@
this.addValue(Settings.KEY_FORM_ENCODING, s.getFormEncoding());
this.addValue(Settings.KEY_SHOWTIME, s.isShowTime());
this.addValue(Settings.KEY_HIDE_SHOWTIME, s.isHideShowTime());
+ this.addValue(Settings.KEY_LAZY_MODE, s.isLazyMode());
}
private void genProperties() throws SAXException {
Modified: cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java?view=diff&r1=157267&r2=157268
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/reading/ImageReader.java Sat Mar 12
11:17:13 2005
@@ -31,7 +31,6 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.commons.lang.BooleanUtils;
import org.xml.sax.SAXException;
import com.sun.image.codec.jpeg.ImageFormatException;