You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2001/12/06 19:54:03 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon Cocoon.java
giacomo 01/12/06 10:54:03
Modified: src/org/apache/cocoon Cocoon.java
Log:
slowly moving toward more optimized code
Revision Changes Path
1.33 +205 -51 xml-cocoon2/src/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- Cocoon.java 2001/10/29 12:22:01 1.32
+++ Cocoon.java 2001/12/06 18:54:03 1.33
@@ -1,10 +1,58 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/*
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Axis" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
package org.apache.cocoon;
import org.apache.avalon.excalibur.component.DefaultRoleManager;
@@ -56,7 +104,7 @@
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a> (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
- * @version CVS $Revision: 1.32 $ $Date: 2001/10/29 12:22:01 $
+ * @version CVS $Revision: 1.33 $ $Date: 2001/12/06 18:54:03 $
*/
public class Cocoon
extends AbstractLoggable
@@ -88,10 +136,10 @@
private File workDir;
/** The component manager. */
- public ExcaliburComponentManager componentManager;
+ private ExcaliburComponentManager componentManager;
/** The parent component manager. */
- public ComponentManager parentComponentManager;
+ private ComponentManager parentComponentManager;
/** flag for disposed or not */
private boolean disposed = false;
@@ -105,7 +153,11 @@
/** the Processor if it is ThreadSafe */
private Processor threadSafeProcessor = null;
- /** Create a new <code>Cocoon</code> instance. */
+ /**
+ * Creates a new <code>Cocoon</code> instance.
+ *
+ * @exception ConfigurationException if an error occurs
+ */
public Cocoon() throws ConfigurationException {
// Set the system properties needed by Xalan2.
setSystemProperties();
@@ -121,6 +173,12 @@
this.parentComponentManager = manager;
}
+ /**
+ * Describe <code>contextualize</code> method here.
+ *
+ * @param context a <code>Context</code> value
+ * @exception ContextException if an error occurs
+ */
public void contextualize(Context context) throws ContextException {
if (this.context == null) {
this.context = context;
@@ -136,19 +194,33 @@
}
}
+ /**
+ * The <code>setLogKitManager</code> method will get a <code>LogKitManager</code>
+ * for further use.
+ *
+ * @param logKitManager a <code>LogKitManager</code> value
+ */
public void setLogKitManager(LogKitManager logKitManager) {
this.logKitManager = logKitManager;
}
+ /**
+ * The <code>initialize</code> method
+ *
+ * @exception Exception if an error occurs
+ */
public void initialize() throws Exception {
- if(parentComponentManager != null)
+ if (parentComponentManager != null) {
this.componentManager = new ExcaliburComponentManager(parentComponentManager,(ClassLoader)this.context.get(Constants.CONTEXT_CLASS_LOADER));
- else
+ } else {
this.componentManager = new ExcaliburComponentManager((ClassLoader)this.context.get(Constants.CONTEXT_CLASS_LOADER));
+ }
this.componentManager.setLogger(getLogger());
this.componentManager.contextualize(this.context);
- getLogger().debug("New Cocoon object.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("New Cocoon object.");
+ }
// Log the System Properties.
dumpSystemProperties();
@@ -156,7 +228,9 @@
// Setup the default parser, for parsing configuration.
// If one need to use a different parser, set the given system property
String parser = System.getProperty(Constants.PARSER_PROPERTY, Constants.DEFAULT_PARSER);
- getLogger().debug("Using parser: " + parser);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Using parser: " + parser);
+ }
ExcaliburComponentManager startupManager = new ExcaliburComponentManager((ClassLoader)this.context.get(Constants.CONTEXT_CLASS_LOADER));
startupManager.setLogger(getLogger());
startupManager.contextualize(this.context);
@@ -170,7 +244,9 @@
}
try {
- getLogger().debug("Creating Repository with this directory: " + this.workDir);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Creating Repository with this directory: " + this.workDir);
+ }
FilesystemStore repository = new FilesystemStore();
repository.setLogger(getLogger());
repository.setDirectory(this.workDir);
@@ -180,8 +256,10 @@
throw new ConfigurationException("Could not create the repository!", e);
}
- getLogger().debug("Classpath = " + classpath);
- getLogger().debug("Work directory = " + workDir.getCanonicalPath());
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Classpath = " + classpath);
+ getLogger().debug("Work directory = " + workDir.getCanonicalPath());
+ }
startupManager.initialize();
Configuration conf = this.configure(startupManager);
@@ -192,11 +270,15 @@
// Get the Processor and keep it if it's ThreadSafe
Processor processor = (Processor)this.componentManager.lookup(Processor.ROLE);
if (processor instanceof ThreadSafe) {
- getLogger().debug("Processor of class " + processor.getClass().getName() + " is ThreadSafe");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Processor of class " + processor.getClass().getName() + " is ThreadSafe");
+ }
this.threadSafeProcessor = processor;
} else {
- getLogger().debug("Processor of class " + processor.getClass().getName() +
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Processor of class " + processor.getClass().getName() +
" is NOT ThreadSafe -- will be looked up at each request");
+ }
this.componentManager.release(processor);
}
@@ -206,10 +288,14 @@
// Check if the hsqldb server has been disabled in either cocoon.roles or cocoon.xconf
Configuration children[] = conf.getChildren("hsqldb-server");
if((children != null) && (children.length > 0) && this.componentManager.hasComponent(Server.ROLE)) {
- getLogger().debug("Starting database server");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Starting database server");
+ }
server = (Server) this.componentManager.lookup(Server.ROLE);
} else {
- getLogger().debug("Disabled hsqldb server");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Disabled hsqldb server");
+ }
}
} catch (Exception e){
getLogger().error("Error starting database server",e);
@@ -223,18 +309,31 @@
private void dumpSystemProperties() {
try {
Enumeration e = System.getProperties().propertyNames();
- getLogger().debug("===== System Properties Start =====");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("===== System Properties Start =====");
+ }
for (;e.hasMoreElements();) {
String key = (String) e.nextElement();
- getLogger().debug(key + "=" + System.getProperty(key));
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(key + "=" + System.getProperty(key));
+ }
+ }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("===== System Properties End =====");
}
- getLogger().debug("===== System Properties End =====");
} catch ( SecurityException se ) {
// Ignore Exceptions.
}
}
- /** Configure this <code>Cocoon</code> instance. */
+ /**
+ * Configure this <code>Cocoon</code> instance.
+ *
+ * @param startupManager an <code>ExcaliburComponentManager</code> value
+ * @return a <code>Configuration</code> value
+ * @exception ConfigurationException if an error occurs
+ * @exception ContextException if an error occurs
+ */
public Configuration configure(ExcaliburComponentManager startupManager) throws ConfigurationException, ContextException {
Parser p = null;
Configuration roleConfig = null;
@@ -277,11 +376,15 @@
Configuration conf = this.configuration;
- getLogger().debug("Root configuration: " + conf.getName());
+ 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"));
}
- getLogger().debug("Configuration version: " + conf.getAttribute("version"));
if (Constants.CONF_VERSION.equals(conf.getAttribute("version")) == false) {
throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
}
@@ -316,19 +419,28 @@
this.componentManager.setRoleManager(drm);
this.componentManager.setLogKitManager(this.logKitManager);
- getLogger().debug("Setting up components...");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Setting up components...");
+ }
this.componentManager.configure(conf);
return conf;
}
- /** Queries the class to estimate its ergodic period termination. */
+ /**
+ * 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) {
this.configurationFile.refresh();
return date < this.configurationFile.getLastModified();
}
- /** Sets required system properties . */
+ /**
+ * Sets required system properties.
+ */
protected void setSystemProperties() {
java.util.Properties props = new java.util.Properties();
// FIXME We shouldn't have to specify the SAXParser...
@@ -339,11 +451,12 @@
Enumeration propEnum = props.propertyNames();
while (propEnum.hasMoreElements()) {
String prop = (String)propEnum.nextElement();
- if (!systemProps.containsKey(prop))
+ if (!systemProps.containsKey(prop)) {
systemProps.put(prop, props.getProperty(prop));
+ }
}
// FIXME We shouldn't have to specify these. Needed to override jaxp implementation of weblogic.
- if(systemProps.containsKey("javax.xml.parsers.DocumentBuilderFactory") &&
+ if (systemProps.containsKey("javax.xml.parsers.DocumentBuilderFactory") &&
systemProps.getProperty("javax.xml.parsers.DocumentBuilderFactory").startsWith("weblogic")) {
systemProps.put("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
systemProps.put("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");
@@ -351,16 +464,24 @@
System.setProperties(systemProps);
}
+ /**
+ * Dispose this instance
+ */
public void dispose() {
this.componentManager.release(this.threadSafeProcessor);
this.componentManager.dispose();
- if (this.configurationFile != null)
+ if (this.configurationFile != null) {
this.configurationFile.recycle();
+ }
this.disposed = true;
}
/**
- * Log debug information about the current environment
+ * Log debug information about the current environment.
+ *
+ * @param environment an <code>Environment</code> value
+ * @param pipeline a <code>StreamPipeline</code> value
+ * @param eventPipeline an <code>EventPipeline</code> value
*/
protected void debug(Environment environment,
StreamPipeline pipeline,
@@ -407,9 +528,10 @@
.append("VALUES: '");
String[] params = request.getParameterValues(p);
for (int i = 0; i < params.length; i++) {
- msg.append("["+params[i]+"]");
- if (i != params.length-1)
- msg.append(", ");
+ msg.append("[" + params[i] + "]");
+ if (i != (params.length - 1)) {
+ msg.append(", ");
+ }
}
msg.append("'").append(lineSeparator);
@@ -426,10 +548,11 @@
msg.append("PARAM: '").append(p).append("' ")
.append("VALUES: '");
Enumeration e3 = request.getHeaders(p);
- while(e3.hasMoreElements()) {
- msg.append("["+e3.nextElement()+"]");
- if(e3.hasMoreElements())
+ while (e3.hasMoreElements()) {
+ msg.append("[" + e3.nextElement() + "]");
+ if (e3.hasMoreElements()) {
msg.append(", ");
+ }
}
msg.append("'").append(lineSeparator);
@@ -449,20 +572,30 @@
}
}
- getLogger().debug(msg.toString());
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(msg.toString());
+ }
}
/**
* Process the given <code>Environment</code> to produce the output.
+ *
+ * @param environment an <code>Environment</code> value
+ * @return a <code>boolean</code> value
+ * @exception Exception if an error occurs
*/
public boolean process(Environment environment)
throws Exception {
- if (disposed) throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
+ if (disposed) {
+ throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
+ }
try {
if (this.getLogger().isDebugEnabled()) {
incRequestCount();
- this.debug(environment, null, null);
+ if (this.getLogger().isDebugEnabled()) {
+ this.debug(environment, null, null);
+ }
}
if (this.threadSafeProcessor != null) {
@@ -486,15 +619,25 @@
/**
* Process the given <code>Environment</code> to assemble
* a <code>StreamPipeline</code> and an <code>EventPipeline</code>.
+ *
+ * @param environment an <code>Environment</code> value
+ * @param pipeline a <code>StreamPipeline</code> value
+ * @param eventPipeline an <code>EventPipeline</code> value
+ * @return a <code>boolean</code> value
+ * @exception Exception if an error occurs
*/
public boolean process(Environment environment, StreamPipeline pipeline, EventPipeline eventPipeline)
throws Exception {
- if (disposed) throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
+ if (disposed) {
+ throw new IllegalStateException("You cannot process a Disposed Cocoon engine.");
+ }
try {
if (this.getLogger().isDebugEnabled()) {
incRequestCount();
- this.debug(environment, pipeline, eventPipeline);
+ if (this.getLogger().isDebugEnabled()) {
+ this.debug(environment, pipeline, eventPipeline);
+ }
}
if (this.threadSafeProcessor != null) {
@@ -519,6 +662,9 @@
/**
* Process the given <code>Environment</code> to generate the sitemap.
* Delegated to the Processor component if it's a <code>SitemapManager</code>.
+ *
+ * @param environment an <code>Environment</code> value
+ * @exception Exception if an error occurs
*/
public void generateSitemap(Environment environment)
throws Exception {
@@ -534,6 +680,10 @@
/**
* Process the given <code>Environment</code> to generate Java code for specified XSP files.
+ *
+ * @param fileName a <code>String</code> value
+ * @param environment an <code>Environment</code> value
+ * @exception Exception if an error occurs
*/
public void generateXSP(String fileName, Environment environment)
throws Exception {
@@ -541,7 +691,9 @@
SourceHandler oldSourceHandler = environment.getSourceHandler();
SourceHandler sourceHandler = null;
try {
- getLogger().debug("XSP generation begin:" + fileName);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("XSP generation begin:" + fileName);
+ }
programGenerator = (ProgramGenerator) this.componentManager.lookup(ProgramGenerator.ROLE);
sourceHandler = (SourceHandler) this.componentManager.lookup(SourceHandler.ROLE);
@@ -550,8 +702,9 @@
String programmingLanguage = "java";
CompiledComponent xsp = programGenerator.load(this.componentManager, fileName, markupLanguage, programmingLanguage, environment);
- getLogger().debug("XSP generation complete:" + xsp);
-
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("XSP generation complete:" + xsp);
+ }
this.componentManager.release(programGenerator);
} catch (Exception e) {
getLogger().error("Main: Error compiling XSP", e);
@@ -568,8 +721,9 @@
* result if it's the maximum.
*/
private static synchronized void incRequestCount() {
- if (++activeRequestCount > maxRequestCount)
- maxRequestCount = activeRequestCount;
+ if (++activeRequestCount > maxRequestCount) {
+ maxRequestCount = activeRequestCount;
+ }
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org