Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1999-2004 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.components.thread;
+
+/**
+ * The ThreadFactory interface describes the responability of Factories
+ * creating Thread for {@link ThreadPool}s of the {@link RunnableManager}
+ *
+ * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
+ * @version $Id: ThreadFactory.java 321157 2005-10-14 17:21:29Z cziegeler $
+ */
+public interface ThreadFactory
+ extends EDU.oswego.cs.dl.util.concurrent.ThreadFactory {
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Set the daemon mode of created <code>Thread</code>s should have
+ *
+ * @param isDaemon Whether new {@link Thread}s should run as daemons.
+ */
+ void setDaemon( boolean isDaemon );
+
+ /**
+ * Get the daemon mode created <code>Thread</code>s will have
+ *
+ * @return Whether new {@link Thread}s should run as daemons.
+ */
+ boolean isDaemon();
+
+ /**
+ * Set the priority newly created <code>Thread</code>s should have
+ *
+ * @param priority One of {@link Thread#MIN_PRIORITY}, {@link
+ * Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
+ */
+ void setPriority( int priority );
+
+ /**
+ * Get the priority newly created <code>Thread</code>s will have
+ *
+ * @return One of {@link Thread#MIN_PRIORITY}, {@link
+ * Thread#NORM_PRIORITY}, {@link Thread#MAX_PRIORITY}
+ */
+ int getPriority();
+
+ /**
+ * Create a new Thread for a {@link Runnable} command
+ *
+ * @param command The <code>Runnable</code>
+ *
+ * @return new <code>Thread</code>
+ */
+ Thread newThread( Runnable command );
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadPool.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadPool.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadPool.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadPool.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ * 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.components.thread;
+
+/**
+ * The ThreadPool interface gives access to methods needed to inspect and use
+ * of a pool of threads
+ *
+ * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
+ * @version $Id: ThreadPool.java 312843 2005-10-11 09:12:58Z cziegeler $
+ */
+public interface ThreadPool {
+
+ //~ Instance fields --------------------------------------------------------
+
+ /** ThreadPool block policy ABORT */
+ String POLICY_ABORT = "ABORT";
+
+ /** ThreadPool block policy DISCARD */
+ String POLICY_DISCARD = "DISCARD";
+
+ /** ThreadPool block policy DISCARD-OLDEST */
+ String POLICY_DISCARD_OLDEST = "DISCARDOLDEST";
+
+ /** ThreadPool block policy RUN */
+ String POLICY_RUN = "RUN";
+
+ /** ThreadPool block policy WAIT */
+ String POLICY_WAIT = "WAIT";
+
+ /** The Role name */
+ String ROLE = ThreadPool.class.getName();
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * The blocking policy used
+ *
+ * @return DOCUMENT ME!
+ */
+ String getBlockPolicy();
+
+ /**
+ * How long will a thread in this pool be idle before it is allowed to be
+ * garbage collected
+ *
+ * @return maximum idle time
+ */
+ long getKeepAliveTime();
+
+ /**
+ * How many threads are in this pool at maximum
+ *
+ * @return maximum size of pool
+ */
+ int getMaximumPoolSize();
+
+ /**
+ * Maximum size of the queue
+ *
+ * @return current size of queue
+ */
+ int getMaximumQueueSize();
+
+ /**
+ * How many threads are in this pool at minimum
+ *
+ * @return minimum size of pool
+ */
+ int getMinimumPoolSize();
+
+ /**
+ * The Name of this thread pool
+ *
+ * @return The name
+ */
+ String getName();
+
+ /**
+ * How many threads are currently in this pool
+ *
+ * @return current size of pool
+ */
+ int getPoolSize();
+
+ /**
+ * Get the thread priority used by this pool
+ *
+ * @return current size of queue
+ */
+ int getPriority();
+
+ /**
+ * Current size of the queue.
+ *
+ * @return current size of queue. If the size of the queue is not
+ * maintained by an implementation -1 should be returned.
+ */
+ int getQueueSize();
+
+ /**
+ * Whether this ThreadPool has a queue
+ *
+ * @return Returns true if this ThreadPool has a queue
+ */
+ boolean isQueued();
+
+ /**
+ * Returns true if a shutDown method has succeeded in terminating all
+ * threads
+ *
+ * @return Whether a shutDown method has succeeded in terminating all
+ * threads
+ */
+ boolean isTerminatedAfterShutdown();
+
+ /**
+ * Execute a command using this pool
+ *
+ * @param command a {@link Runnable} to execute
+ *
+ * @throws InterruptedException In case of interruption
+ */
+ void execute( Runnable command )
+ throws InterruptedException;
+
+ /**
+ * Terminates all threads possibly awaiting processing all elements
+ * currently in queue.
+ */
+ void shutdown();
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/thread/ThreadPool.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.cocoon.environment.Environment;
+
+import java.util.Map;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: AbstractParentProcessingNode.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+public abstract class AbstractParentProcessingNode extends AbstractProcessingNode {
+
+ public AbstractParentProcessingNode(String type) {
+ super(type);
+ }
+
+ public AbstractParentProcessingNode() {
+ this(null);
+ }
+
+ /**
+ * Invoke all nodes of a node array in order, until one succeeds.
+ *
+ * @param currentMap the <code>Map<code> of parameters produced by this node,
+ * which is added to <code>listOfMap</code>.
+ */
+ protected final boolean invokeNodes(ProcessingNode[] nodes,
+ Environment env,
+ InvokeContext context,
+ String currentName,
+ Map currentMap)
+ throws Exception {
+
+ currentMap = this.executor.pushVariables(this, env.getObjectModel(), currentName, currentMap);
+ context.pushMap(currentName,currentMap);
+
+ try {
+ for (int i = 0; i < nodes.length; i++) {
+ if (nodes[i].invoke(env, context)) {
+ // Success
+ return true;
+ }
+ }
+ } finally {
+ this.executor.popVariables(this, env.getObjectModel());
+ // No success
+ context.popMap();
+ }
+ return false;
+ }
+
+ /**
+ * Invoke all nodes of a node array in order, until one succeeds.
+ */
+ protected final boolean invokeNodes (ProcessingNode[] nodes,
+ Environment env,
+ InvokeContext context)
+ throws Exception {
+
+ for (int i = 0; i < nodes.length; i++) {
+ if (nodes[i].invoke(env, context)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,157 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Base class for parent <code>ProcessingNodeBuilders</code>, providing services for parsing
+ * children nodes.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: AbstractParentProcessingNodeBuilder.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+public abstract class AbstractParentProcessingNodeBuilder extends AbstractProcessingNodeBuilder
+ implements Configurable {
+
+ protected Collection allowedChildren;
+
+ protected Collection forbiddenChildren;
+
+ protected Collection ignoredChildren;
+
+ /**
+ * Configure the sets of allowed, forbidden and ignored children nodes.
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ this.allowedChildren = getStringCollection(config.getChild("allowed-children"));
+ this.forbiddenChildren = getStringCollection(config.getChild("forbidden-children"));
+ this.ignoredChildren = getStringCollection(config.getChild("ignored-children"));
+ }
+
+ /**
+ * Checks if a child element and is allowed, and if not throws a <code>ConfigurationException</code>.
+ *
+ * @param child the child configuration to check.
+ * @return <code>true</code> if this child should be considered or <code>false</code>
+ * if it should be ignored.
+ * @throws ConfigurationException if this child isn't allowed.
+ */
+ protected boolean isChild(Configuration child) throws ConfigurationException {
+
+ checkNamespace(child);
+
+ String name = child.getName();
+
+ // Is this a parameter of a parameterizable node builder ?
+ if (isParameter(child)) {
+ return false;
+ }
+
+ // Is this element to be ignored ?
+ if (ignoredChildren != null && ignoredChildren.contains(name)) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Element '" + name + "' is ignored for building children of element '" +
+ child.getName() + "'");
+ }
+
+ return false;
+ }
+
+ // Is it allowed ?
+ if ( (allowedChildren != null && !allowedChildren.contains(name)) ||
+ (forbiddenChildren != null && forbiddenChildren.contains(name)) ) {
+ String msg = "Element '" + name + "' is not allowed at " + child.getLocation();
+ throw new ConfigurationException(msg);
+ }
+
+ return true;
+ }
+
+ protected boolean isParameter(Configuration config) throws ConfigurationException {
+ final String name = config.getName();
+ if (name.equals("parameter")) {
+ if (this.hasParameters()) {
+ return true;
+ }
+ String msg = "Element '" + name + "' has no parameters at " + config.getLocation();
+ throw new ConfigurationException(msg);
+ }
+ return false;
+ }
+
+ /**
+ * Create the <code>ProcessingNode</code>s for the children of a given node.
+ * Child nodes are controlled to be actually allowed in this node.
+ */
+ protected List buildChildNodesList(Configuration config) throws Exception {
+
+ Configuration[] children = config.getChildren();
+ List result = new ArrayList();
+
+ for (int i = 0; i < children.length; i++) {
+
+ Configuration child = children[i];
+ try {
+ if (isChild(child)) {
+ // OK : get a builder.
+ ProcessingNodeBuilder childBuilder = this.treeBuilder.createNodeBuilder(child);
+ result.add(childBuilder.buildNode(child));
+ }
+
+ } catch(ConfigurationException ce) {
+ throw ce;
+ } catch(Exception e) {
+ String msg = "Error while creating node '" + child.getName() + "' at " + child.getLocation();
+ throw new ConfigurationException(msg, e);
+ }
+ }
+
+ return result;
+ }
+
+ protected ProcessingNode[] buildChildNodes(Configuration config) throws Exception {
+ return toNodeArray(buildChildNodesList(config));
+ }
+
+ /**
+ * Convenience function that converts a <code>List</code> of <code>ProcessingNode</code>s
+ * to an array.
+ */
+ public static ProcessingNode[] toNodeArray(List list) {
+ return (ProcessingNode[])list.toArray(new ProcessingNode[list.size()]);
+ }
+
+ /**
+ * Splits the value of a Configuration in a Collection of Strings. Splitting
+ * occurs at space characters (incl. line breaks) and comma.
+ *
+ * @return a collection of Strings, or null if <code>config</code> has no value.
+ */
+ private Collection getStringCollection(Configuration config) {
+ String s = config.getValue(null);
+
+ return (s == null) ? null : Arrays.asList(StringUtils.split(s, ", \t\n\r"));
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.sitemap.ExecutionContext;
+import org.apache.cocoon.sitemap.SitemapExecutor;
+import org.apache.cocoon.util.location.Location;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: AbstractProcessingNode.java 233343 2005-08-18 18:06:44Z sylvain $
+ */
+
+public abstract class AbstractProcessingNode
+ extends AbstractLogEnabled
+ implements ProcessingNode, ExecutionContext {
+
+ protected Location location = Location.UNKNOWN;
+
+ /** The type of the component */
+ protected String componentName;
+
+ /** The sitemap executor */
+ protected SitemapExecutor executor;
+
+ public AbstractProcessingNode(String type) {
+ this.componentName = type;
+ }
+
+ public AbstractProcessingNode() {
+ this(null);
+ }
+
+ /**
+ * Get the location of this node.
+ */
+ public Location getLocation() {
+ return this.location;
+ }
+
+ /**
+ * Set the location of this node.
+ */
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ /**
+ * Set the sitemap executor
+ */
+ public void setSitemapExecutor(SitemapExecutor executor) {
+ this.executor = executor;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.sitemap.ExecutionContext#getType()
+ */
+ public String getType() {
+ return this.componentName;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: AbstractProcessingNodeBuilder.java 233343 2005-08-18 18:06:44Z sylvain $
+ */
+public abstract class AbstractProcessingNodeBuilder extends AbstractLogEnabled
+ implements ProcessingNodeBuilder {
+
+ protected TreeBuilder treeBuilder;
+
+ protected ServiceManager manager;
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder#setBuilder(org.apache.cocoon.components.treeprocessor.TreeBuilder)
+ */
+ public void setBuilder(TreeBuilder treeBuilder) {
+ this.treeBuilder = treeBuilder;
+ this.manager = treeBuilder.getBuiltProcessorManager();
+ }
+
+ /**
+ * Does this node accept parameters ? Default is true : if a builder that doesn't
+ * have parameters doesn't override this method, erroneous parameters will be silently
+ * ignored.
+ */
+ protected boolean hasParameters() {
+ return true;
+ }
+
+ /**
+ * Check if the namespace URI of the given configuraition is the same as the
+ * one given by the builder.
+ */
+ protected void checkNamespace(Configuration config) throws ConfigurationException {
+ if (!this.treeBuilder.getNamespace().equals(config.getNamespace())) {
+ String msg = "Invalid namespace '" + config.getNamespace() + "' at " + config.getLocation();
+ throw new ConfigurationException(msg);
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AbstractProcessingNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/** Filter out annotations in the sitemap
+ * (bugzilla 25352)
+ * $Id: AnnotationsFilter.java 292282 2005-09-28 19:54:16Z vgritsenko $
+ */
+class AnnotationsFilter implements ContentHandler {
+ public static final String ANNOTATIONS_NAMESPACE = "http://apache.org/cocoon/sitemap/annotations/1.0";
+
+ private ContentHandler delegate;
+
+ private int nestingLevel;
+
+ private boolean isOutsideAnnotation()
+ {
+ return nestingLevel == 0;
+ }
+
+ public AnnotationsFilter(ContentHandler delegate) {
+ this.delegate = delegate;
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ delegate.setDocumentLocator(locator);
+ }
+
+ public void startDocument() throws SAXException {
+ delegate.startDocument();
+ }
+
+ public void endDocument() throws SAXException {
+ delegate.endDocument();
+ }
+
+ public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.startPrefixMapping(prefix, namespaceURI);
+ }
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.endPrefixMapping(prefix);
+ }
+ }
+
+ public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException {
+ if (namespaceURI != null && namespaceURI.equals(ANNOTATIONS_NAMESPACE)) {
+ nestingLevel++;
+ }
+ if (isOutsideAnnotation()) {
+ delegate.startElement(namespaceURI, localName, qName, attributes);
+ }
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.endElement(namespaceURI, localName, qName);
+ }
+ if (namespaceURI != null && namespaceURI.equals(ANNOTATIONS_NAMESPACE)) {
+ nestingLevel--;
+ }
+ }
+
+ public void characters(char[] ch, int start, int len) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.characters(ch, start, len);
+ }
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int len) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.ignorableWhitespace(ch, start, len);
+ }
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.processingInstruction(target, data);
+ }
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ if (isOutsideAnnotation()) {
+ delegate.skippedEntity(name);
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * A generic container node that just invokes its children.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: CategoryNode.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+
+public final class CategoryNode extends AbstractParentProcessingNode {
+
+ public CategoryNode(String type) {
+ super(type);
+ }
+
+ /** The name of this category */
+ private String categoryName;
+
+ /** The Map of named nodes in this category */
+ private Map nodes;
+
+ public void setCategory(String categoryName, Map nodes) {
+ this.categoryName = categoryName;
+ this.nodes = (nodes != null) ? nodes : new HashMap(0);
+ }
+
+ public final boolean invoke(Environment env, InvokeContext context) throws Exception {
+ String msg = "Cannot invoke " + this.categoryName + " at " + getLocation();
+ throw new ProcessingException(msg);
+ }
+
+ public final ProcessingNode getNodeByName(String name) throws Exception {
+ ProcessingNode node = (ProcessingNode)nodes.get(name);
+ if (node == null) {
+ String msg = "Unknown " + this.categoryName + " named '" + name + "' at " + getLocation();
+ throw new ProcessingException(msg);
+ }
+
+ return node;
+ }
+
+ public final boolean invokeByName(String name, Environment env, InvokeContext context)
+ throws Exception {
+
+ return getNodeByName(name).invoke(env, context);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ * 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.components.treeprocessor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.thread.ThreadSafe;
+
+/**
+ * Builds a generic container node.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: CategoryNodeBuilder.java 290410 2005-09-20 10:13:19Z sylvain $
+ */
+
+public class CategoryNodeBuilder extends AbstractParentProcessingNodeBuilder
+ implements Configurable, ThreadSafe {
+
+ // Prefix used for registering as a TreeBuilder attribute
+ private static String PREFIX = CategoryNodeBuilder.class.getName() + "/";
+
+ protected String name;
+
+ /**
+ * The category name is the value of the "category-name" child, or if not
+ * present, the name of the configuration element.
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ super.configure(config);
+ this.name = config.getChild("category-name").getValue(config.getAttribute("name"));
+ }
+
+ /** This builder has no parameters -- return <code>false</code> */
+ protected boolean hasParameters() {
+ return false;
+ }
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ CategoryNode node = new CategoryNode(null);
+ this.treeBuilder.setupNode(node, config);
+
+ // Get all children and associate them to their name
+ Map category = new HashMap();
+
+ List children = buildChildNodesList(config);
+ Iterator iter = children.iterator();
+ while(iter.hasNext()) {
+ NamedProcessingNode child = (NamedProcessingNode)iter.next();
+ category.put(child.getName(), child);
+ }
+
+ node.setCategory(this.name, category);
+
+ // Register node to allow lookup by other nodes
+ if ( !this.treeBuilder.registerNode(PREFIX + this.name, node) ) {
+ throw new ConfigurationException("Only one <map:" + this.name +
+ "> is allowed in a sitemap. Another one is declared at " +
+ config.getLocation());
+ }
+
+ return node;
+ }
+
+ public static CategoryNode getCategoryNode(TreeBuilder builder, String categoryName) {
+ return (CategoryNode)builder.getRegisteredNode(PREFIX + categoryName);
+ }
+
+ public static ProcessingNode getNamedNode(TreeBuilder builder, String categoryName, String nodeName)
+ throws Exception {
+ CategoryNode category = getCategoryNode(builder, categoryName);
+
+ return category.getNodeByName(nodeName);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/CategoryNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,495 @@
+/*
+ * 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.
+ * 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.components.treeprocessor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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;
+import org.apache.cocoon.Processor;
+import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.ForwardRedirector;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.SourceResolver;
+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.EnterSitemapEvent;
+import org.apache.cocoon.sitemap.EnterSitemapEventListener;
+import org.apache.cocoon.sitemap.ExecutionContext;
+import org.apache.cocoon.sitemap.LeaveSitemapEvent;
+import org.apache.cocoon.sitemap.LeaveSitemapEventListener;
+import org.apache.cocoon.sitemap.SitemapExecutor;
+import org.apache.cocoon.sitemap.SitemapListener;
+import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.commons.jci.listeners.NotificationListener;
+
+/**
+ * The concrete implementation of {@link Processor}, containing the evaluation tree and associated
+ * data such as component manager.
+ *
+ * @version $Id: ConcreteTreeProcessor.java 292823 2005-09-30 18:01:51Z tcurdt $
+ */
+public class ConcreteTreeProcessor extends AbstractLogEnabled
+ implements Processor, Disposable, ExecutionContext, NotificationListener {
+
+ /** Our ServiceManager */
+ private ServiceManager manager;
+
+ /** Our class loader */
+ private ClassLoader classloader;
+
+ /** The processor that wraps us */
+ private TreeProcessor wrappingProcessor;
+
+ /** Processing nodes that need to be disposed with this processor */
+ private List disposableNodes;
+
+ /** Root node of the processing tree */
+ private ProcessingNode rootNode;
+
+ private Configuration componentConfigurations;
+
+ /** Number of simultaneous uses of this processor (either by concurrent request or by internal requests) */
+ private int requestCount;
+
+ /** The sitemap executor */
+ private SitemapExecutor sitemapExecutor;
+
+ /** Optional application container */
+ private ComponentLocator applicationContainer;
+
+ /** Optional event listeners for the enter sitemap event */
+ private List enterSitemapEventListeners = new ArrayList();
+
+ /** Optional event listeners for the leave sitemap event */
+ private List leaveSitemapEventListeners = new ArrayList();
+
+ /** Needs a reload? */
+ protected volatile boolean needsReload = false;
+
+ /** Processor attributes */
+ protected Map processorAttributes = new HashMap();
+
+ /** no listeners by default */
+ private Map classpathListeners = Collections.EMPTY_MAP;
+
+ /**
+ * Builds a concrete processig, given the wrapping processor
+ */
+ public ConcreteTreeProcessor(TreeProcessor wrappingProcessor,
+ SitemapExecutor sitemapExecutor) {
+ // Store our wrapping processor
+ this.wrappingProcessor = wrappingProcessor;
+
+ // Get the sitemap executor - we use the same executor for each sitemap
+ this.sitemapExecutor = sitemapExecutor;
+ }
+
+ public void handleNotification() {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(this + " got notified that a reload is required");
+ }
+ needsReload = true;
+ }
+
+ public void setClasspathListeners(Map classpathListeners) {
+ this.classpathListeners = classpathListeners;
+ }
+
+ public Map getClasspathListeners() {
+ return this.classpathListeners;
+ }
+
+ /** Set the processor data, result of the treebuilder job */
+ 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");
+ }
+
+ this.manager = manager;
+ this.classloader = classloader;
+ this.rootNode = rootNode;
+ this.disposableNodes = disposableNodes;
+ this.enterSitemapEventListeners = enterSitemapEventListeners;
+ this.leaveSitemapEventListeners = leaveSitemapEventListeners;
+ this.applicationContainer = componentLocator;
+ }
+
+ /** Set the sitemap component configurations (called as part of the tree building process) */
+ public void setComponentConfigurations(Configuration componentConfigurations) {
+ this.componentConfigurations = componentConfigurations;
+ }
+
+ /**
+ * @see org.apache.cocoon.Processor#getComponentConfigurations()
+ */
+ public Configuration[] getComponentConfigurations() {
+ if (this.componentConfigurations == null) {
+ if (this.wrappingProcessor.parent != null) {
+ return this.wrappingProcessor.parent.getComponentConfigurations();
+ }
+ return null;
+ }
+ if (this.wrappingProcessor.parent == null) {
+ return new Configuration[]{this.componentConfigurations};
+ }
+ final Configuration[] parentArray = this.wrappingProcessor.parent.getComponentConfigurations();
+ if ( parentArray != null ) {
+ final Configuration[] newArray = new Configuration[parentArray.length + 1];
+ System.arraycopy(parentArray, 0, newArray, 1, parentArray.length);
+ newArray[0] = this.componentConfigurations;
+ return newArray;
+ }
+ return new Configuration[] {this.componentConfigurations};
+ }
+
+ /**
+ * Mark this processor as needing to be disposed. Actual call to {@link #dispose()} will occur when
+ * all request processings on this processor will be terminated.
+ */
+ public void markForDisposal() {
+ // Decrement the request count (negative number means dispose)
+ synchronized(this) {
+ this.requestCount--;
+ }
+
+ if (this.requestCount < 0) {
+ // No more users : dispose right now
+ dispose();
+ }
+ }
+
+ boolean isReloadNeeded() {
+ return needsReload;
+ }
+
+ public TreeProcessor getWrappingProcessor() {
+ return this.wrappingProcessor;
+ }
+
+ /**
+ * @see org.apache.cocoon.Processor#getRootProcessor()
+ */
+ public Processor getRootProcessor() {
+ return this.wrappingProcessor.getRootProcessor();
+ }
+
+ /**
+ * Process the given <code>Environment</code> producing the output.
+ * @return If the processing is successfull <code>true</code> is returned.
+ * If not match is found in the sitemap <code>false</code>
+ * is returned.
+ * @throws org.apache.cocoon.ResourceNotFoundException If a sitemap component tries
+ * to access a resource which can not
+ * be found, e.g. the generator
+ * ConnectionResetException If the connection was reset
+ */
+ public boolean process(Environment environment) throws Exception {
+ InvokeContext context = new InvokeContext();
+ context.enableLogging(getLogger());
+ try {
+ return process(environment, context);
+ } finally {
+ context.dispose();
+ }
+ }
+
+ /**
+ * Process the given <code>Environment</code> to assemble
+ * a <code>ProcessingPipeline</code>.
+ * @since 2.1
+ */
+ public InternalPipelineDescription buildPipeline(Environment environment)
+ throws Exception {
+ InvokeContext context = new InvokeContext(true);
+ context.enableLogging(getLogger());
+ try {
+ if (process(environment, context)) {
+ return context.getInternalPipelineDescription(environment);
+ }
+ return null;
+ } finally {
+ context.dispose();
+ }
+ }
+
+ /**
+ * Do the actual processing, be it producing the response or just building the pipeline
+ * @param environment
+ * @param context
+ * @return true if the pipeline was successfully built, false otherwise.
+ * @throws Exception
+ */
+ protected boolean process(Environment environment, InvokeContext context)
+ throws Exception {
+
+ // Increment the concurrent requests count
+ synchronized (this) {
+ requestCount++;
+ }
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader oldClassLoader = currentThread.getContextClassLoader();
+ currentThread.setContextClassLoader(this.classloader);
+
+ try {
+ // invoke listeners
+ // only invoke if pipeline is not internally
+ if ( !context.isBuildingPipelineOnly() && this.enterSitemapEventListeners.size() > 0 ) {
+ final EnterSitemapEvent enterEvent = new EnterSitemapEvent(this, environment);
+ final Iterator enterSEI = this.enterSitemapEventListeners.iterator();
+ while ( enterSEI.hasNext() ) {
+ final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)enterSEI.next();
+ ((EnterSitemapEventListener)current.component).enteredSitemap(enterEvent);
+ }
+ }
+
+ this.sitemapExecutor.enterSitemap(this, environment.getObjectModel(), this.wrappingProcessor.source.getURI());
+ // and now process
+ EnvironmentHelper.enterProcessor(this, this.manager, environment);
+ final Redirector oldRedirector = context.getRedirector();
+
+ // Build a redirector
+ TreeProcessorRedirector redirector = new TreeProcessorRedirector(environment, context);
+ setupLogger(redirector);
+ context.setRedirector(redirector);
+ context.service(this.manager);
+ context.setLastProcessor(this);
+
+ try {
+ final boolean success = this.rootNode.invoke(environment, context);
+ return success;
+ } finally {
+ EnvironmentHelper.leaveProcessor();
+ // Restore old redirector
+ context.setRedirector(oldRedirector);
+ }
+
+ } finally {
+ this.sitemapExecutor.leaveSitemap(this, environment.getObjectModel());
+ // invoke listeners
+ // only invoke if pipeline is not internally
+ if ( !context.isBuildingPipelineOnly() && this.leaveSitemapEventListeners.size() > 0 ) {
+ final LeaveSitemapEvent leaveEvent = new LeaveSitemapEvent(this, environment);
+ final Iterator leaveSEI = this.leaveSitemapEventListeners.iterator();
+ while ( leaveSEI.hasNext() ) {
+ final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)leaveSEI.next();
+ ((LeaveSitemapEventListener)current.component).leftSitemap(leaveEvent);
+ }
+ }
+
+ // Restore classloader
+ currentThread.setContextClassLoader(oldClassLoader);
+
+ // Decrement the concurrent request count
+ synchronized (this) {
+ requestCount--;
+ }
+
+ if (requestCount < 0) {
+ // Marked for disposal and no more concurrent requests.
+ dispose();
+ }
+ }
+ }
+
+ protected boolean handleCocoonRedirect(String uri, Environment environment, InvokeContext context)
+ throws Exception {
+ // Build an environment wrapper
+ // If the current env is a facade, change the delegate and continue processing the facade, since
+ // we may have other redirects that will in turn also change the facade delegate
+
+ MutableEnvironmentFacade facade = environment instanceof MutableEnvironmentFacade ?
+ ((MutableEnvironmentFacade)environment) : null;
+
+ if (facade != null) {
+ // Consider the facade delegate (the real environment)
+ environment = facade.getDelegate();
+ }
+
+ // test if this is a call from flow
+ boolean isRedirect = (environment.getObjectModel().remove("cocoon:forward") == null);
+ final SitemapSourceInfo info = SitemapSourceInfo.parseURI(environment, uri);
+ Environment newEnv = new ForwardEnvironmentWrapper(environment, info, getLogger());
+ if (isRedirect) {
+ ((ForwardEnvironmentWrapper) newEnv).setInternalRedirect(true);
+ }
+
+ if (facade != null) {
+ // Change the facade delegate
+ facade.setDelegate((ForwardEnvironmentWrapper)newEnv);
+ newEnv = facade;
+ }
+
+ // Get the processor that should process this request
+ ConcreteTreeProcessor processor;
+ if (newEnv.getURIPrefix().equals("")) {
+ processor = ((TreeProcessor)getRootProcessor()).concreteProcessor;
+ } else {
+ processor = this;
+ }
+
+ // Process the redirect
+ // No more reset since with TreeProcessorRedirector, we need to pop values from the redirect location
+ // context.reset();
+ // The following is a fix for bug #26854 and #26571
+ final boolean result = processor.process(newEnv, context);
+ if (facade != null) {
+ newEnv = facade.getDelegate();
+ }
+ if (((ForwardEnvironmentWrapper) newEnv).getRedirectURL() != null) {
+ environment.redirect(((ForwardEnvironmentWrapper) newEnv).getRedirectURL(), false, false);
+ }
+ return result;
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if (this.disposableNodes != null) {
+ // we must dispose the nodes in reverse order
+ // otherwise selector nodes are freed before the components node
+ for (int i = this.disposableNodes.size() - 1; i > -1; i--) {
+ ((Disposable) disposableNodes.get(i)).dispose();
+ }
+ this.disposableNodes = null;
+ }
+
+ // Ensure it won't be used anymore
+ this.rootNode = null;
+ this.sitemapExecutor = null;
+
+ // dispose listeners
+ this.disposeListeners(this.enterSitemapEventListeners);
+ this.disposeListeners(this.leaveSitemapEventListeners);
+
+ // dispose component locator - if it is a SitemapListener it is already disposed!
+ if ( !(this.applicationContainer instanceof SitemapListener) ) {
+ ContainerUtil.dispose(this.applicationContainer);
+ }
+ this.applicationContainer = null;
+ }
+
+ protected void disposeListeners(List l) {
+ Iterator i = l.iterator();
+ while ( i.hasNext() ) {
+ final TreeBuilder.EventComponent current = (TreeBuilder.EventComponent)i.next();
+ if ( current.releaseUsingManager ) {
+ this.manager.release(current.component);
+ } else {
+ ContainerUtil.dispose(current.component);
+ }
+ }
+ l.clear();
+ }
+
+ private class TreeProcessorRedirector extends ForwardRedirector {
+ private InvokeContext context;
+
+ public TreeProcessorRedirector(Environment env, InvokeContext context) {
+ super(env);
+ this.context = context;
+ }
+
+ protected void cocoonRedirect(String uri) throws IOException, ProcessingException {
+ try {
+ ConcreteTreeProcessor.this.handleCocoonRedirect(uri, this.env, this.context);
+ } catch (IOException e) {
+ throw e;
+ } catch (ProcessingException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ProcessingException(e);
+ }
+ }
+ }
+
+ public SourceResolver getSourceResolver() {
+ return wrappingProcessor.getSourceResolver();
+ }
+
+ public String getContext() {
+ return wrappingProcessor.getContext();
+ }
+ /**
+ * Return the sitemap executor
+ */
+ public SitemapExecutor getSitemapExecutor() {
+ return this.sitemapExecutor;
+ }
+
+ public ServiceManager getServiceManager() {
+ return this.manager;
+ }
+
+ /**
+ * @see org.apache.cocoon.Processor#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return this.processorAttributes.get(name);
+ }
+
+ /**
+ * @see org.apache.cocoon.Processor#removeAttribute(java.lang.String)
+ */
+ public Object removeAttribute(String name) {
+ return this.processorAttributes.remove(name);
+ }
+
+ /**
+ * @see org.apache.cocoon.Processor#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ this.processorAttributes.put(name, value);
+ }
+
+ /**
+ * @see org.apache.cocoon.sitemap.ExecutionContext#getLocation()
+ */
+ public Location getLocation() {
+ return new LocationImpl("[sitemap]", this.wrappingProcessor.source.getURI());
+ }
+
+ /**
+ * @see org.apache.cocoon.sitemap.ExecutionContext#getType()
+ */
+ public String getType() {
+ return "sitemap";
+ }
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * A generic container node that just invokes its children.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: ContainerNode.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+
+public class ContainerNode extends SimpleParentProcessingNode {
+
+ public ContainerNode(String type) {
+ super(type);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
+ public final boolean invoke(Environment env, InvokeContext context) throws Exception {
+
+ return invokeNodes(this.children, env, context);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+/**
+ * Builds a generic container node.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: ContainerNodeBuilder.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+
+public class ContainerNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
+
+ /** This builder has no parameters -- return <code>false</code> */
+ protected boolean hasParameters() {
+ return false;
+ }
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ ContainerNode node = new ContainerNode(null);
+ setupNode(node, config);
+
+ return node;
+ }
+
+ protected void setupNode(ContainerNode node, Configuration config)throws Exception {
+
+ this.treeBuilder.setupNode(node, config);
+
+ ProcessingNode[] children = buildChildNodes(config);
+ if (children.length == 0) {
+ String msg = "There must be at least one child at " + config.getLocation();
+ throw new ConfigurationException(msg);
+ }
+
+ node.setChildren(children);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/ContainerNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
|