You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/07/18 19:09:27 UTC
svn commit: r677971 - in /cocoon/whiteboard/corona/trunk:
corona-controller/src/main/java/org/apache/cocoon/corona/controller/
corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/
corona-pipeline/src/main/java/org/apache/cocoon/corona/pipel...
Author: reinhard
Date: Fri Jul 18 10:09:26 2008
New Revision: 677971
URL: http://svn.apache.org/viewvc?rev=677971&view=rev
Log:
. provide abstract pipeline component implementation
. give access to the exception, that was thrown during the execution of the pipeline, in the finish method
(implementation done together with Steven)
Added:
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java (with props)
Modified:
cocoon/whiteboard/corona/trunk/corona-controller/src/main/java/org/apache/cocoon/corona/controller/SpringControllerComponent.java
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/PipelineComponent.java
cocoon/whiteboard/corona/trunk/corona-sample/src/main/resources/COB-INF/sitemap.xmap
cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
Modified: cocoon/whiteboard/corona/trunk/corona-controller/src/main/java/org/apache/cocoon/corona/controller/SpringControllerComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-controller/src/main/java/org/apache/cocoon/corona/controller/SpringControllerComponent.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-controller/src/main/java/org/apache/cocoon/corona/controller/SpringControllerComponent.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-controller/src/main/java/org/apache/cocoon/corona/controller/SpringControllerComponent.java Fri Jul 18 10:09:26 2008
@@ -21,13 +21,15 @@
import java.io.OutputStream;
import java.util.Map;
+import org.apache.cocoon.corona.pipeline.component.AbstractPipelineComponent;
import org.apache.cocoon.corona.pipeline.component.Finisher;
import org.apache.cocoon.corona.pipeline.component.Starter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-public class SpringControllerComponent implements Starter, Finisher, ApplicationContextAware {
+public class SpringControllerComponent extends AbstractPipelineComponent implements Starter, Finisher,
+ ApplicationContextAware {
private ApplicationContext applicationContext;
private String beanName;
@@ -38,7 +40,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Starter#execute()
*/
public void execute() {
@@ -49,7 +51,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
*/
public String getContentType() {
@@ -58,7 +60,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -67,9 +69,10 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
*/
+ @Override
public void setConfiguration(Map<String, ? extends Object> configuration) {
this.configuration = configuration;
this.beanName = (String) configuration.get("controller");
@@ -78,25 +81,17 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setup(java.util.Map)
*/
+ @Override
public void setup(Map<String, Object> parameters) {
this.parameters = parameters;
}
/**
* {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#finish()
- */
- public void finish() {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
*/
public void setOutputStream(OutputStream outputStream) {
Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java Fri Jul 18 10:09:26 2008
@@ -43,7 +43,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.Pipeline#addComponent(org.apache.cocoon.corona.pipeline.component.PipelineComponent)
*/
public void addComponent(PipelineComponent pipelineComponent) {
@@ -55,7 +55,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.Pipeline#setup(java.util.Map, java.io.OutputStream)
*/
public void setup(Map<String, Object> parameters, OutputStream outputStream) {
@@ -64,7 +64,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.Pipeline#execute()
*/
public void execute() throws Exception {
@@ -73,7 +73,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.Pipeline#getContentType()
*/
public String getContentType() {
@@ -94,8 +94,18 @@
this.logger.debug("Invoking first component of " + this);
}
- Starter starter = (Starter) this.components.getFirst();
- starter.execute();
+ RuntimeException exception = null;
+ try {
+ Starter starter = (Starter) this.components.getFirst();
+ starter.execute();
+ } catch (RuntimeException ex) {
+ exception = ex;
+ throw ex;
+ } finally {
+ for (PipelineComponent pipelineComponent : this.getComponents()) {
+ pipelineComponent.finish(exception);
+ }
+ }
}
protected void setupComponents(Map<String, Object> parameters, OutputStream outputStream) {
Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java?rev=677971&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java Fri Jul 18 10:09:26 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.corona.pipeline.component;
+
+import java.util.Map;
+
+public abstract class AbstractPipelineComponent implements PipelineComponent {
+
+ public void finish(Exception exception) {
+ // do nothing
+ }
+
+ public void setConfiguration(Map<String, ? extends Object> configuration) {
+ // do nothing
+ }
+
+ public void setup(Map<String, Object> parameters) {
+ // do nothing
+ }
+}
Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractPipelineComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java Fri Jul 18 10:09:26 2008
@@ -40,9 +40,9 @@
}
/**
- *
+ *
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
*/
public String getContentType() {
@@ -64,9 +64,9 @@
}
/**
- *
+ *
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
*/
public void setConfiguration(Map<String, ? extends Object> configuration) {
@@ -84,7 +84,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setup(java.util.Map)
*/
public void setup(Map<String, Object> inputParameters) {
@@ -93,17 +93,17 @@
/**
* {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#finish()
+ *
+ * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#finish(java.lang.Exception)
*/
- public void finish() {
- // nothing to do
+ public void finish(Exception exception) {
+ // do nothing
}
/**
- *
+ *
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
*/
public void setOutputStream(OutputStream outputStream) {
@@ -111,9 +111,9 @@
}
/**
- *
+ *
* {@inheritDoc}
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java Fri Jul 18 10:09:26 2008
@@ -18,17 +18,15 @@
*/
package org.apache.cocoon.corona.pipeline.component;
-import java.util.Map;
-
import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
-public abstract class AbstractXMLProducer implements XMLProducer {
+public abstract class AbstractXMLProducer extends AbstractPipelineComponent implements XMLProducer {
private XMLConsumer xmlConsumer;
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Producer#setConsumer(org.apache.cocoon.corona.pipeline.component.Consumer)
*/
public final void setConsumer(Consumer consumer) {
@@ -39,33 +37,6 @@
this.setXMLConsumer((XMLConsumer) consumer);
}
- /**
- * {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
- */
- public void setConfiguration(Map<String, ? extends Object> configuration) {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setup(java.util.Map)
- */
- public void setup(Map<String, Object> inputParameters) {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#finish()
- */
- public void finish() {
- // nothing to do
- }
-
protected XMLConsumer getXMLConsumer() {
return this.xmlConsumer;
}
Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java Fri Jul 18 10:09:26 2008
@@ -31,7 +31,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class FileReaderComponent implements Starter, Finisher, CachingPipelineComponent {
+public class FileReaderComponent extends AbstractPipelineComponent implements Starter, Finisher,
+ CachingPipelineComponent {
private final Log logger = LogFactory.getLog(this.getClass());
@@ -50,7 +51,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.CachingPipelineComponent#constructCacheKey()
*/
public CacheKey constructCacheKey() {
@@ -66,7 +67,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Starter#execute()
*/
public void execute() {
@@ -101,7 +102,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
*/
public String getContentType() {
@@ -122,35 +123,18 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
*/
+ @Override
public void setConfiguration(Map<String, ? extends Object> configuration) {
this.setSource((URL) configuration.get("source"));
this.setMimeType((String) configuration.get("mime-type"));
}
/**
- * {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setup(java.util.Map)
- */
- public void setup(Map<String, Object> inputParameters) {
- // nothing to do
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#finish()
- */
- public void finish() {
- // nothing to do
- }
-
- /**
* Set the mime-type directly which is useful when this component is used directly.
- *
+ *
* @param mimeType The mime-type that belongs to the content that is produced by this component.
*/
public void setMimeType(String mimeType) {
@@ -159,7 +143,7 @@
/**
* Set the source {@link URL} directly when this component is used directly.
- *
+ *
* @param source A {@link URL} that will be used by this component.
*/
public void setSource(URL source) {
@@ -168,7 +152,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
*/
public void setOutputStream(OutputStream outputStream) {
@@ -177,7 +161,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/PipelineComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/PipelineComponent.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/PipelineComponent.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/PipelineComponent.java Fri Jul 18 10:09:26 2008
@@ -22,13 +22,10 @@
/**
* This is a component used in a pipeline.
- *
- * If the environment has some configuration for this component
- * {@link #setConfiguration(Map)} is called as the first step.
- * After the component has been added to pipeline,
- * {@link #setup(Map)} is called before the pipeline is executed.
- * When the pipeline is finished or if any error ocurred
- * {@link #finish} is called.
+ *
+ * If the environment has some configuration for this component {@link #setConfiguration(Map)} is called as the first
+ * step. After the component has been added to pipeline, {@link #setup(Map)} is called before the pipeline is executed.
+ * When the pipeline is finished or if any error occurred {@link #finish} is called.
*/
public interface PipelineComponent {
@@ -36,14 +33,15 @@
/**
* The shared object map for this pipeline run.
- * @param parameters A {@link Map} of parameters that are available to all {@link PipelineComponent}s.
- * This is a modifiable map that can be changed by this pipeline component.
+ *
+ * @param parameters A {@link Map} of parameters that are available to all {@link PipelineComponent}s. This is a
+ * modifiable map that can be changed by this pipeline component.
*/
void setup(Map<String, Object> parameters);
/**
- * This method is called after pipeline run - regardless if the
- * run was successful or an exception was thrown.
+ * This method is called after pipeline run - regardless if the run was successful or an exception was thrown.
+ *
*/
- void finish();
+ void finish(Exception exception);
}
Modified: cocoon/whiteboard/corona/trunk/corona-sample/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sample/src/main/resources/COB-INF/sitemap.xmap?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sample/src/main/resources/COB-INF/sitemap.xmap (original)
+++ cocoon/whiteboard/corona/trunk/corona-sample/src/main/resources/COB-INF/sitemap.xmap Fri Jul 18 10:09:26 2008
@@ -128,7 +128,7 @@
<map:transform src="sax-pipeline/simple.xslt">
<map:parameter name="myParam" value="serializer-pipeline" />
</map:transform>
- <map:serialize type="xml" />
+ <map:serialize type="xml" />
</map:match>
<map:match pattern="ssf/calling-a-transformer-servlet-service">
<map:generate src="sax-pipeline/simple.xml" />
Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java?rev=677971&r1=677970&r2=677971&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java Fri Jul 18 10:09:26 2008
@@ -26,13 +26,14 @@
import javax.servlet.http.HttpServletResponse;
+import org.apache.cocoon.corona.pipeline.component.AbstractPipelineComponent;
import org.apache.cocoon.corona.pipeline.component.Finisher;
import org.apache.cocoon.corona.pipeline.component.Starter;
import org.apache.cocoon.corona.servlet.util.HttpContextHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class RedirectorComponent implements Starter, Finisher {
+public class RedirectorComponent extends AbstractPipelineComponent implements Starter, Finisher {
private final Log logger = LogFactory.getLog(this.getClass());
@@ -42,7 +43,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Starter#execute()
*/
public void execute() {
@@ -71,29 +72,38 @@
}
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
+ */
public String getContentType() {
return null;
}
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
*/
+ @Override
public void setConfiguration(Map<String, ? extends Object> configuration) {
this.uri = (String) configuration.get("uri");
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.corona.pipeline.component.AbstractPipelineComponent#setup(java.util.Map)
+ */
+ @Override
public void setup(Map<String, Object> parameters) {
this.parameters = parameters;
}
- public void finish() {
- }
-
/**
* {@inheritDoc}
- *
+ *
* @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
*/
public void setOutputStream(OutputStream outputStream) {
@@ -102,7 +112,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see java.lang.Object#toString()
*/
@Override