sylvain 01/10/25 03:34:00 Modified: . changes.xml src/org/apache/cocoon Cocoon.java Processor.java cocoon.roles src/org/apache/cocoon/sitemap Manager.java Added: src/org/apache/cocoon/sitemap SitemapManager.java Log: The sitemap engine is now a regular component available through Processor.ROLE. This allows alternative implementations of Processors (e.g. interpreted sitemap, flowmap, statemap) to be plugged through cocoon.xconf. Note : to ensure compatibility with existing cocoon.xconf files, the shorthand for the Processor role is "sitemap". Revision Changes Path 1.45 +7 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- changes.xml 2001/10/22 13:14:06 1.44 +++ changes.xml 2001/10/25 10:34:00 1.45 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.44 2001/10/22 13:14:06 sylvain Exp $ + $Id: changes.xml,v 1.45 2001/10/25 10:34:00 sylvain Exp $ --> <changes title="History of Changes"> @@ -26,6 +26,12 @@ </devs> <release version="2.1-dev" date="@date@"> + <action dev="SW" type="update"> + The sitemap engine is now a regular component available through Processor.ROLE. This allows + alternative implementations of Processors (e.g. interpreted sitemap, flowmap, statemap) to + be plugged through cocoon.xconf. Note : to ensure compatibility with existing cocoon.xconf + files, the shorthand for the Processor role is "sitemap". + </action> <action dev="SW" type="add"> Deprecation of CodeFactory in preparation of the tree traversal implementation of the sitemap. All factory-based matchers have been rewritten using the new PreparableMatcher interface, and 1.31 +51 -93 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.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- Cocoon.java 2001/10/11 07:28:15 1.30 +++ Cocoon.java 2001/10/25 10:34:00 1.31 @@ -38,8 +38,7 @@ import org.apache.cocoon.environment.ModifiableSource; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Session; -import org.apache.cocoon.sitemap.AbstractSitemap; -import org.apache.cocoon.sitemap.Manager; +import org.apache.cocoon.sitemap.SitemapManager; import org.apache.cocoon.util.ClassUtils; import org.xml.sax.InputSource; @@ -57,7 +56,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> (Apache Software Foundation, Exoffice Technologies) * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> * @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a> - * @version CVS $Revision: 1.30 $ $Date: 2001/10/11 07:28:15 $ + * @version CVS $Revision: 1.31 $ $Date: 2001/10/25 10:34:00 $ */ public class Cocoon extends AbstractLoggable @@ -76,15 +75,9 @@ /** The configuration file */ private ModifiableSource configurationFile; - /** The sitemap file */ - private String sitemapFileName; - /** The configuration tree */ private Configuration configuration; - /** The sitemap manager */ - private Manager sitemapManager; - /** The logkit manager */ private LogKitManager logKitManager; @@ -94,12 +87,6 @@ /** The working directory (null if not available) */ private File workDir; - /** Check reloading of sitemap */ - private boolean checkSitemapReload = true; - - /** reload sitemap asynchron */ - private boolean reloadSitemapAsynchron = true; - /** The component manager. */ public ExcaliburComponentManager componentManager; @@ -114,6 +101,9 @@ /** maximum request count */ private static int maxRequestCount = 0; + + /** the Processor if it is ThreadSafe */ + private Processor threadSafeProcessor = null; /** Create a new <code>Cocoon</code> instance. */ public Cocoon() throws ConfigurationException { @@ -199,26 +189,16 @@ this.componentManager.initialize(); - getLogger().debug("Setting up the sitemap."); - // Create the sitemap - Configuration sconf = conf.getChild("sitemap"); - this.sitemapManager = new Manager(); - this.sitemapManager.setLogger(getLogger()); - this.sitemapManager.contextualize(this.context); - this.sitemapManager.compose(this.componentManager); - this.sitemapManager.configure(conf); - this.sitemapFileName = sconf.getAttribute("file"); - if (this.sitemapFileName == null) { - getLogger().error("No sitemap file name"); - throw new ConfigurationException("No sitemap file name\n" + conf.toString()); - } - String value = sconf.getAttribute("check-reload", "yes"); - this.checkSitemapReload = !(value != null && value.equalsIgnoreCase("no") == true); - value = sconf.getAttribute("reload-method", "asynchron"); - this.reloadSitemapAsynchron = !(value != null && value.equalsIgnoreCase("synchron") == true); - getLogger().debug("Sitemap location = " + this.sitemapFileName); - getLogger().debug("Checking sitemap reload = " + this.checkSitemapReload); - getLogger().debug("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron); + // 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"); + this.threadSafeProcessor = processor; + } else { + getLogger().debug("Processor of class " + processor.getClass().getName() + + " is NOT ThreadSafe -- will be looked up at each request"); + this.componentManager.release(processor); + } // Start the database server Server server = null; @@ -236,6 +216,7 @@ } finally { this.componentManager.release(server); } + } /** Dump System Properties */ @@ -257,7 +238,6 @@ public Configuration configure(ExcaliburComponentManager startupManager) throws ConfigurationException, ContextException { Parser p = null; Configuration roleConfig = null; - Configuration sitemapConfig = null; try { this.configurationFile.refresh(); @@ -282,27 +262,6 @@ roleConfig = null; try { - this.configurationFile.refresh(); - p = (Parser)startupManager.lookup(Parser.ROLE); - SAXConfigurationHandler b = new SAXConfigurationHandler(); - InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/sitemap/sitemap.roles").openStream(); - InputSource is = new InputSource(inputStream); - is.setSystemId(this.configurationFile.getSystemId()); - p.setContentHandler(b); - p.parse(is); - sitemapConfig = b.getConfiguration(); - } catch (Exception e) { - getLogger().error("Could not configure Cocoon environment", e); - throw new ConfigurationException("Error trying to load configurations", e); - } finally { - if (p != null) startupManager.release(p); - } - - DefaultRoleManager sitemapRoleManager = new DefaultRoleManager(); - sitemapRoleManager.setLogger(getLogger()); - sitemapRoleManager.configure(sitemapConfig); - - try { p = (Parser)startupManager.lookup(Parser.ROLE); SAXConfigurationHandler b = new SAXConfigurationHandler(); InputSource is = this.configurationFile.getInputSource(); @@ -318,9 +277,6 @@ Configuration conf = this.configuration; - AbstractSitemap.setRoleManager(sitemapRoleManager, conf); - AbstractSitemap.setLogKitManager(this.logKitManager); - getLogger().debug("Root configuration: " + conf.getName()); if (! "cocoon".equals(conf.getName())) { throw new ConfigurationException("Invalid configuration file\n" + conf.toString()); @@ -363,10 +319,6 @@ getLogger().debug("Setting up components..."); this.componentManager.configure(conf); - // adding the processor itself to the available components - // we need a wrapper to avoid infinite dispose loops - this.componentManager.addComponentInstance(Processor.ROLE, new ProcessorWrapper(this)); - return conf; } @@ -400,6 +352,7 @@ } public void dispose() { + this.componentManager.release(this.threadSafeProcessor); this.componentManager.dispose(); if (this.configurationFile != null) this.configurationFile.recycle(); @@ -506,17 +459,28 @@ throws Exception { if (disposed) throw new IllegalStateException("You cannot process a Disposed Cocoon engine."); - try { + try { if (this.getLogger().isDebugEnabled()) { incRequestCount(); this.debug(environment, null, null); } - return this.sitemapManager.invoke(this.componentManager, environment, "", this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron); + + if (this.threadSafeProcessor != null) { + return this.threadSafeProcessor.process(environment); + } else { + Processor processor = (Processor)this.componentManager.lookup(Processor.ROLE); + try { + return processor.process(environment); + } + finally { + this.componentManager.release(processor); + } + } } finally { if (this.getLogger().isDebugEnabled()) { decRequestCount(); } - } + } } /** @@ -527,50 +491,44 @@ throws Exception { if (disposed) throw new IllegalStateException("You cannot process a Disposed Cocoon engine."); - try { + try { if (this.getLogger().isDebugEnabled()) { incRequestCount(); this.debug(environment, pipeline, eventPipeline); + } + + if (this.threadSafeProcessor != null) { + return this.threadSafeProcessor.process(environment, pipeline, eventPipeline); + } else { + Processor processor = (Processor)this.componentManager.lookup(Processor.ROLE); + try { + return processor.process(environment); + } + finally { + this.componentManager.release(processor); + } } - return this.sitemapManager.invoke(this.componentManager, environment, "", this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron, pipeline, eventPipeline); + } finally { if (this.getLogger().isDebugEnabled()) { decRequestCount(); } - } + } } /** * Process the given <code>Environment</code> to generate the sitemap. + * Delegated to the Processor component if it's a <code>SitemapManager</code>. */ public void generateSitemap(Environment environment) throws Exception { - ProgramGenerator programGenerator = null; - SourceHandler oldSourceHandler = environment.getSourceHandler(); - SourceHandler sourceHandler = null; + Component processor = this.componentManager.lookup(Processor.ROLE); try { - programGenerator = (ProgramGenerator) this.componentManager.lookup(ProgramGenerator.ROLE); - sourceHandler = (SourceHandler) this.componentManager.lookup(SourceHandler.ROLE); - environment.setSourceHandler(sourceHandler); - String markupLanguage = "sitemap"; - String programmingLanguage = "java"; - - getLogger().debug("Sitemap regeneration begin:" + sitemapFileName); - CompiledComponent smap = programGenerator.load(this.componentManager, sitemapFileName, markupLanguage, programmingLanguage, environment); - getLogger().debug("Sitemap regeneration complete"); - - if (smap != null) { - getLogger().debug("Main: The sitemap has been successfully compiled!"); - } else { - getLogger().debug("Main: No errors, but the sitemap has not been set."); + if (processor instanceof SitemapManager) { + ((SitemapManager)processor).generateSitemap(environment); } - } catch (Exception e) { - getLogger().error("Main: Error compiling sitemap", e); - throw e; } finally { - environment.setSourceHandler(oldSourceHandler); - if (programGenerator != null) this.componentManager.release(programGenerator); - if (sourceHandler != null) this.componentManager.release((Component) sourceHandler); + this.componentManager.release(processor); } } 1.6 +3 -2 xml-cocoon2/src/org/apache/cocoon/Processor.java Index: Processor.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Processor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Processor.java 2001/10/11 07:28:15 1.5 +++ Processor.java 2001/10/25 10:34:00 1.6 @@ -7,6 +7,7 @@ *****************************************************************************/ package org.apache.cocoon; +import org.apache.avalon.framework.component.Component; import org.apache.cocoon.components.pipeline.EventPipeline; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.environment.Environment; @@ -15,9 +16,9 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> * (Apache Software Foundation, Exoffice Technologies) - * @version CVS $Revision: 1.5 $ $Date: 2001/10/11 07:28:15 $ + * @version CVS $Revision: 1.6 $ $Date: 2001/10/25 10:34:00 $ */ -public interface Processor { +public interface Processor extends Component { String ROLE = "org.apache.cocoon.Processor"; 1.25 +5 -0 xml-cocoon2/src/org/apache/cocoon/cocoon.roles Index: cocoon.roles =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- cocoon.roles 2001/10/23 11:55:19 1.24 +++ cocoon.roles 2001/10/25 10:34:00 1.25 @@ -17,8 +17,13 @@ shorthand="browser" default-class="org.apache.cocoon.components.browser.BrowserImpl"/> +<!-- For backwards compatibility, the shorthand for this role is "sitemap" <role name="org.apache.cocoon.Processor" shorthand="processor"/> +--> + <role name="org.apache.cocoon.Processor" + shorthand="sitemap" + default-class="org.apache.cocoon.sitemap.SitemapManager"/> <role name="org.apache.cocoon.components.store.Store" shorthand="store" 1.20 +9 -8 xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java Index: Manager.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- Manager.java 2001/10/17 10:06:24 1.19 +++ Manager.java 2001/10/25 10:34:00 1.20 @@ -16,6 +16,7 @@ import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; @@ -34,27 +35,27 @@ * checking regeneration of the sub <code>Sitemap</code> * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Revision: 1.19 $ $Date: 2001/10/17 10:06:24 $ + * @version CVS $Revision: 1.20 $ $Date: 2001/10/25 10:34:00 $ */ public class Manager extends AbstractLoggable implements Component, Configurable, Composable, Contextualizable, ThreadSafe, LogKitManageable { - private Context context; + protected Context context; /** The vectors of sub sitemaps */ - private HashMap sitemaps = new HashMap(); + protected HashMap sitemaps = new HashMap(); /** The configuration */ - private Configuration conf; + protected Configuration conf; /** The component manager */ - private ComponentManager manager; + protected ComponentManager manager; /** The sitemap role manager */ - private RoleManager sitemapRoles; + protected RoleManager sitemapRoles; /** The sitemap logkit manager */ - private LogKitManager sitemapLogKitManager; + protected LogKitManager sitemapLogKitManager; /** @@ -74,7 +75,7 @@ /** get a configuration * @param conf the configuration */ - public void configure(Configuration conf) { + public void configure(Configuration conf) throws ConfigurationException { this.conf = conf; } 1.1 xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapManager.java Index: SitemapManager.java =================================================================== /***************************************************************************** * 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. * *****************************************************************************/ package org.apache.cocoon.sitemap; import org.apache.avalon.excalibur.component.RoleManager; import org.apache.avalon.excalibur.logger.LogKitManager; import org.apache.avalon.excalibur.component.DefaultRoleManager; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.SAXConfigurationHandler; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.Processor; import org.apache.cocoon.components.language.generator.CompiledComponent; import org.apache.cocoon.components.language.generator.ProgramGenerator; import org.apache.cocoon.components.parser.Parser; import org.apache.cocoon.components.pipeline.EventPipeline; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.components.source.SourceHandler; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.util.ClassUtils; import org.xml.sax.InputSource; import java.io.InputStream; /** * A <code>Processor</code> based on sitemap language files compiled * to Java code. * * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> * @version CVS $Revision: 1.1 $ $Date: 2001/10/25 10:34:00 $ */ public class SitemapManager extends Manager implements Processor, Configurable { /** The sitemap file */ private String sitemapFileName; /** Check reloading of sitemap */ private boolean checkSitemapReload = true; /** reload sitemap asynchron */ private boolean reloadSitemapAsynchron = true; public void configure(Configuration sconf) throws ConfigurationException { super.configure(sconf); this.sitemapFileName = sconf.getAttribute("file"); String value = sconf.getAttribute("check-reload", "yes"); this.checkSitemapReload = !(value != null && value.equalsIgnoreCase("no") == true); value = sconf.getAttribute("reload-method", "asynchron"); this.reloadSitemapAsynchron = !(value != null && value.equalsIgnoreCase("synchron") == true); getLogger().debug("Sitemap location = " + this.sitemapFileName); getLogger().debug("Checking sitemap reload = " + this.checkSitemapReload); getLogger().debug("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron); System.err.println("Sitemap location = " + this.sitemapFileName); System.err.println("Checking sitemap reload = " + this.checkSitemapReload); System.err.println("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron); // Read sitemap roles Parser p = null; Configuration rolesConfig; try { p = (Parser)this.manager.lookup(Parser.ROLE); SAXConfigurationHandler b = new SAXConfigurationHandler(); InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/sitemap/sitemap.roles").openStream(); InputSource is = new InputSource(inputStream); is.setSystemId("org/apache/cocoon/sitemap/sitemap.roles"); p.setContentHandler(b); p.parse(is); rolesConfig = b.getConfiguration(); } catch (Exception e) { getLogger().error("Could not configure Cocoon environment", e); throw new ConfigurationException("Error trying to load configurations", e); } finally { this.manager.release(p); } DefaultRoleManager sitemapRoleManager = new DefaultRoleManager(); sitemapRoleManager.setLogger(getLogger()); sitemapRoleManager.configure(rolesConfig); AbstractSitemap.setRoleManager(sitemapRoleManager, sconf); AbstractSitemap.setLogKitManager(this.sitemapLogKitManager); } /** * Process the given <code>Environment</code> to generate the sitemap. */ public void generateSitemap(Environment environment) throws Exception { ProgramGenerator programGenerator = null; SourceHandler oldSourceHandler = environment.getSourceHandler(); SourceHandler sourceHandler = null; try { programGenerator = (ProgramGenerator) this.manager.lookup(ProgramGenerator.ROLE); sourceHandler = (SourceHandler) this.manager.lookup(SourceHandler.ROLE); environment.setSourceHandler(sourceHandler); String markupLanguage = "sitemap"; String programmingLanguage = "java"; getLogger().debug("Sitemap regeneration begin:" + sitemapFileName); CompiledComponent smap = programGenerator.load(this.manager, sitemapFileName, markupLanguage, programmingLanguage, environment); getLogger().debug("Sitemap regeneration complete"); if (smap != null) { getLogger().debug("Main: The sitemap has been successfully compiled!"); } else { getLogger().debug("Main: No errors, but the sitemap has not been set."); } } catch (Exception e) { getLogger().error("Main: Error compiling sitemap", e); throw e; } finally { environment.setSourceHandler(oldSourceHandler); if (programGenerator != null) this.manager.release(programGenerator); if (sourceHandler != null) this.manager.release(sourceHandler); } } /** * Process the given <code>Environment</code> producing the output. */ public boolean process(Environment environment) throws Exception { return this.invoke(this.manager, environment, "", this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron); } /** * Process the given <code>Environment</code> to assemble * a <code>StreamPipeline</code> and an <code>EventPipeline</code>. */ public boolean process(Environment environment, StreamPipeline pipeline, EventPipeline eventPipeline) throws Exception { return this.invoke(this.manager, environment, "", this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron, pipeline, eventPipeline); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]