Author: cziegeler Date: Mon Mar 21 07:42:04 2005 New Revision: 158469 URL: http://svn.apache.org/viewcvs?view=rev&rev=158469 Log: Correct disping of component locator Start adding event listeners
Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java (with props) cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java (with props) cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java (with props) cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java (with props) cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java (with props) cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java (with props) Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?view=diff&r1=158468&r2=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Mon Mar 21 07:42:04 2005 @@ -20,6 +20,7 @@ import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.container.ContainerUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceManager; import org.apache.cocoon.ProcessingException; @@ -32,6 +33,7 @@ import org.apache.cocoon.environment.internal.EnvironmentHelper; import org.apache.cocoon.environment.internal.ForwardEnvironmentWrapper; import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade; +import org.apache.cocoon.sitemap.ComponentLocator; import org.apache.cocoon.sitemap.SitemapExecutor; /** @@ -66,6 +68,9 @@ /** The sitemap executor */ private SitemapExecutor sitemapExecutor; + /** Optional application container */ + private ComponentLocator applicationContainer; + /** * Builds a concrete processig, given the wrapping processor */ @@ -79,7 +84,13 @@ } /** Set the processor data, result of the treebuilder job */ - public void setProcessorData(ServiceManager manager, ClassLoader classloader, ProcessingNode rootNode, List disposableNodes) { + public void setProcessorData(ServiceManager manager, + ClassLoader classloader, + ProcessingNode rootNode, + List disposableNodes, + ComponentLocator componentLocator, + List enterSitemapEventListeners, + List leaveSitemapEventListeners) { if (this.rootNode != null) { throw new IllegalStateException("setProcessorData() can only be called once"); } @@ -95,6 +106,9 @@ this.componentConfigurations = componentConfigurations; } + /** + * @see org.apache.cocoon.Processor#getComponentConfigurations() + */ public Configuration[] getComponentConfigurations() { if (this.componentConfigurations == null) { if (this.wrappingProcessor.parent != null) { @@ -135,6 +149,9 @@ return this.wrappingProcessor; } + /** + * @see org.apache.cocoon.Processor#getRootProcessor() + */ public Processor getRootProcessor() { return this.wrappingProcessor.getRootProcessor(); } @@ -298,6 +315,8 @@ // Ensure it won't be used anymore this.rootNode = null; this.sitemapExecutor = null; + ContainerUtil.dispose(this.applicationContainer); + this.applicationContainer = null; } private class TreeProcessorRedirector extends ForwardRedirector { Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java?view=diff&r1=158468&r2=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java Mon Mar 21 07:42:04 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-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. @@ -40,6 +40,7 @@ import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; +import org.apache.cocoon.sitemap.ComponentLocator; import org.apache.cocoon.sitemap.PatternException; import org.apache.cocoon.sitemap.SitemapParameters; import org.apache.excalibur.source.Source; @@ -116,6 +117,15 @@ */ protected ProcessorComponentInfo itsComponentInfo; + /** Optional application container */ + protected ComponentLocator applicationContainer; + + /** Optional event listeners for the enter sitemap event */ + protected List enterSitemapEventListeners = new ArrayList(); + + /** Optional event listeners for the leave sitemap event */ + protected List leaveSitemapEventListeners = new ArrayList(); + // ------------------------------------- /** @@ -244,6 +254,32 @@ } /** + * @see org.apache.cocoon.components.treeprocessor.TreeBuilder#getComponentLocator() + */ + public ComponentLocator getComponentLocator() { + // Useless method as it's redefined in SitemapLanguage + return this.applicationContainer; + } + + /** + * @see org.apache.cocoon.components.treeprocessor.TreeBuilder#getEnterSitemapEventListeners() + */ + public List getEnterSitemapEventListeners() { + // we make a copy here, so we can clear(recylce) the list after the + // sitemap is build + return (List)((ArrayList)this.enterSitemapEventListeners).clone(); + } + + /** + * @see org.apache.cocoon.components.treeprocessor.TreeBuilder#getLeaveSitemapEventListeners() + */ + public List getLeaveSitemapEventListeners() { + // we make a copy here, so we can clear(recylce) the list after the + // sitemap is build + return (List)((ArrayList)this.leaveSitemapEventListeners).clone(); + } + + /** * Register a <code>ProcessingNode</code> under a given name. * For example, <code>ResourceNodeBuilder</code> stores here the <code>ProcessingNode</code>s * it produces for use by sitemap pipelines. This allows to turn the tree into a graph. @@ -551,6 +587,9 @@ this.registeredNodes.clear(); VariableResolverFactory.setDisposableCollector(null); + this.applicationContainer = null; + this.enterSitemapEventListeners.clear(); + this.leaveSitemapEventListeners.clear(); } public void dispose() { Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java?view=diff&r1=158468&r2=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeBuilder.java Mon Mar 21 07:42:04 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-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. @@ -20,6 +20,7 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.service.ServiceManager; +import org.apache.cocoon.sitemap.ComponentLocator; /** * @@ -104,4 +105,22 @@ * Get the value of an attribute. */ Object getAttribute(String name); + + /** + * Return the sitemap component locator - if available. + */ + ComponentLocator getComponentLocator(); + + /** + * Return all event listers that are registered for the + * [EMAIL PROTECTED] org.apache.cocoon.sitemap.EnterSitemapEvent}. + */ + List getEnterSitemapEventListeners(); + + /** + * Return all event listers that are registered for the + * [EMAIL PROTECTED] org.apache.cocoon.sitemap.LeaveSitemapEvent}. + */ + List getLeaveSitemapEventListeners(); + } Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java?view=diff&r1=158468&r2=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Mon Mar 21 07:42:04 2005 @@ -404,7 +404,10 @@ newProcessor.setProcessorData( treeBuilder.getBuiltProcessorManager(), treeBuilder.getBuiltProcessorClassLoader(), - root, treeBuilder.getDisposableNodes()); + root, treeBuilder.getDisposableNodes(), + treeBuilder.getComponentLocator(), + treeBuilder.getEnterSitemapEventListeners(), + treeBuilder.getLeaveSitemapEventListeners()); } finally { this.manager.release(treeBuilder); } 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=158468&r2=158469 ============================================================================== --- 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 Mon Mar 21 07:42:04 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-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. @@ -59,9 +59,6 @@ // Regexp's for splitting expressions private static final String COMMA_SPLIT_REGEXP = "[\\s]*,[\\s]*"; private static final String EQUALS_SPLIT_REGEXP = "[\\s]*=[\\s]*"; - - /** Optional application container */ - private ComponentLocator applicationContainer; /** * Build a component manager with the contents of the <map:components> element of @@ -118,6 +115,7 @@ c.addAll(config); c.removeChild(config.getChild("application-container")); c.removeChild(config.getChild("classpath")); + c.removeChild(config.getChild("listeners")); ContainerUtil.configure(newManager, c); ContainerUtil.initialize(newManager); @@ -191,15 +189,6 @@ this.viewsNode = null; this.isBuildingView = false; this.isBuildingErrorHandler = false; - } - - /** - * @see org.apache.avalon.framework.activity.Disposable#dispose() - */ - public void dispose() { - ContainerUtil.dispose(this.applicationContainer); - this.applicationContainer = null; - super.dispose(); } /** Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,30 @@ +/* + * 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; + +import org.apache.cocoon.Processor; +import org.apache.cocoon.environment.Environment; + +/** + * @version $Id:$ + * @since 2.2 + */ +public class EnterSitemapEvent extends SitemapEvent { + + public EnterSitemapEvent(Processor source, Environment env) { + super(source, env); + } +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEvent.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,25 @@ +/* + * 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; + +/** + * @version $Id:$ + * @since 2.2 + */ +public interface EnterSitemapEventListener extends SitemapListener { + + void enteredSitemap(EnterSitemapEvent event); +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/EnterSitemapEventListener.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,31 @@ +/* + * 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; + +import org.apache.cocoon.Processor; +import org.apache.cocoon.environment.Environment; + +/** + * + * @version $Id:$ + * @since 2.2 + */ +public class LeaveSitemapEvent extends SitemapEvent { + + public LeaveSitemapEvent(Processor source, Environment env) { + super(source, env); + } +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEvent.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,26 @@ +/* + * 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; + +/** + * + * @version $Id:$ + * @since 2.2 + */ +public interface LeaveSitemapEventListener extends SitemapListener { + + void leftSitemap(LeaveSitemapEvent event); +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/LeaveSitemapEventListener.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,49 @@ +/* + * 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; + +import java.util.EventObject; + +import org.apache.cocoon.Processor; +import org.apache.cocoon.environment.Environment; + +/** + * Base interface for all sitemap events. + * + * @version $Id:$ + * @since 2.2 + */ +public abstract class SitemapEvent extends EventObject { + + private final Environment environment; + + /** + * @param source The current processor (sitemap) + * @param env The environment describing the current request + */ + public SitemapEvent(Processor source, Environment env) { + super(source); + this.environment = env; + } + + public Processor getSourceProcessor() { + return (Processor)this.getSource(); + } + + public Environment getEnvironment() { + return this.environment; + } +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapEvent.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java?view=auto&rev=158469 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java Mon Mar 21 07:42:04 2005 @@ -0,0 +1,29 @@ +/* + * 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; + +import java.util.EventListener; + +/** + * Base interface for all sitemap event listeners. + * + * @version $Id:$ + * @since 2.2 + */ +public interface SitemapListener extends EventListener { + + // just a marker interface +} Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/java/org/apache/cocoon/sitemap/SitemapListener.java ------------------------------------------------------------------------------ svn:keywords = Id