You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2006/12/13 20:50:41 UTC
svn commit: r486818 - in
/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon:
components/pipeline/AbstractProcessingPipeline.java
components/pipeline/VirtualProcessingPipeline.java
sitemap/SitemapErrorHandler.java
Author: danielf
Date: Wed Dec 13 11:50:39 2006
New Revision: 486818
URL: http://svn.apache.org/viewvc?view=rev&rev=486818
Log:
Refactoring to make the pipelines usable outside the tree processor:
* The source resolver in AbstractProcessingPipeline is looked up from the service manager that is inserted with the setProcessorManager instead of from the EnvironmentHelper.getCurrentProccessor method. After having traced the call sequence it seem to be equivalent and from testing it seem to work.
* Changed the return type SitemapErrorHandler.prepareErrorHandler to Processing pipeline which is the same as it in Cocoon 2.1.x. Before the pipeline was embedded in a descriptor object. The only use for that in the pipeline context was that it was used for having a refernce to the container that created the pipeline and could use that for releasing the pipeline. But in the Spring Avalon implementation the release method is a noop.
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapErrorHandler.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java?view=diff&rev=486818&r1=486817&r2=486818
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java Wed Dec 13 11:50:39 2006
@@ -34,11 +34,10 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.ConnectionResetException;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.Processor;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Response;
-import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.reading.Reader;
import org.apache.cocoon.serialization.Serializer;
@@ -89,7 +88,7 @@
// Error handler stuff
private SitemapErrorHandler errorHandler;
- private Processor.InternalPipelineDescription errorPipeline;
+ private ProcessingPipeline errorPipeline;
/** True when pipeline has been prepared. */
private boolean prepared;
@@ -124,8 +123,8 @@
/** Output Buffer Size */
protected int outputBufferSize;
- /** The current Processor */
- protected Processor processor;
+ /** The current SourceResolver */
+ protected SourceResolver sourceResolver;
/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
@@ -339,7 +338,7 @@
try {
// setup the generator
this.generator.setup(
- this.processor.getSourceResolver(),
+ this.sourceResolver,
environment.getObjectModel(),
generatorSource,
generatorParam
@@ -351,7 +350,7 @@
while (transformerItt.hasNext()) {
Transformer trans = (Transformer)transformerItt.next();
- trans.setup(this.processor.getSourceResolver(),
+ trans.setup(this.sourceResolver,
environment.getObjectModel(),
(String)transformerSourceItt.next(),
(Parameters)transformerParamItt.next()
@@ -360,7 +359,7 @@
if (this.serializer instanceof SitemapModelComponent) {
((SitemapModelComponent)this.serializer).setup(
- this.processor.getSourceResolver(),
+ this.sourceResolver,
environment.getObjectModel(),
this.serializerSource,
this.serializerParam
@@ -443,8 +442,13 @@
*/
protected void preparePipeline(Environment environment)
throws ProcessingException {
- // TODO (CZ) Get the processor set via IoC
- this.processor = EnvironmentHelper.getCurrentProcessor();
+ // Look up the source resolver as late as possible as setProcessorManager might
+ // have changed the service manager
+ try {
+ this.sourceResolver = (SourceResolver) this.newManager.lookup(SourceResolver.ROLE);
+ } catch (ServiceException e) {
+ throw new ProcessingException("Couldn't find a source resolver", e);
+ }
if (!checkPipeline()) {
throw new ProcessingException("Attempted to process incomplete pipeline.");
}
@@ -485,7 +489,7 @@
try {
this.errorPipeline = this.errorHandler.prepareErrorPipeline(ex);
if (this.errorPipeline != null) {
- this.errorPipeline.processingPipeline.prepareInternal(environment);
+ this.errorPipeline.prepareInternal(environment);
return;
}
} catch (ProcessingException e) {
@@ -550,7 +554,7 @@
protected void setupReader(Environment environment)
throws ProcessingException {
try {
- this.reader.setup(this.processor.getSourceResolver(),environment.getObjectModel(),readerSource,readerParam);
+ this.reader.setup(this.sourceResolver,environment.getObjectModel(),readerSource,readerParam);
// set the expires parameter on the pipeline if the reader is configured with one
if (readerParam.isParameter("expires")) {
@@ -686,17 +690,23 @@
this.newManager.release(this.serializer);
this.serializerParam = null;
}
+
+ // Release source resolver
+ if (this.sourceResolver != null) {
+ this.newManager.release(this.sourceResolver);
+ }
this.serializer = null;
this.parameters = null;
- this.processor = null;
+ this.sourceResolver = null;
this.lastConsumer = null;
// Release error handler
this.errorHandler = null;
- if (this.errorPipeline != null) {
- this.errorPipeline.release();
- this.errorPipeline = null;
- }
+
+ // Release error pipeline
+ // This is not done by using release in the creating container as release
+ // is a noop for the Avalon life style in the Spring container
+ this.errorPipeline = null;
}
/**
@@ -711,7 +721,7 @@
// Exception happened during setup and was handled
if (this.errorPipeline != null) {
- return this.errorPipeline.processingPipeline.process(environment, consumer);
+ return this.errorPipeline.process(environment, consumer);
}
// Have to buffer events if error handler is specified.
@@ -740,8 +750,8 @@
try {
this.errorPipeline = this.errorHandler.prepareErrorPipeline(e);
if (this.errorPipeline != null) {
- this.errorPipeline.processingPipeline.prepareInternal(environment);
- return this.errorPipeline.processingPipeline.process(environment, consumer);
+ this.errorPipeline.prepareInternal(environment);
+ return this.errorPipeline.process(environment, consumer);
}
} catch (Exception ignored) {
getLogger().debug("Exception in error handler", ignored);
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java?view=diff&rev=486818&r1=486817&r2=486818
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java Wed Dec 13 11:50:39 2006
@@ -74,7 +74,7 @@
// Error handler stuff
private SitemapErrorHandler errorHandler;
- private Processor.InternalPipelineDescription errorPipeline;
+ private ProcessingPipeline errorPipeline;
/**
* True when pipeline has been prepared.
@@ -357,7 +357,7 @@
try {
this.errorPipeline = this.errorHandler.prepareErrorPipeline(ex);
if (this.errorPipeline != null) {
- this.errorPipeline.processingPipeline.prepareInternal(environment);
+ this.errorPipeline.prepareInternal(environment);
return;
}
} catch (ProcessingException e) {
@@ -401,7 +401,7 @@
throws ProcessingException {
// Exception happened during setup and was handled
if (this.errorPipeline != null) {
- return this.errorPipeline.processingPipeline.process(environment, consumer);
+ return this.errorPipeline.process(environment, consumer);
}
// Have to buffer events if error handler is specified.
@@ -566,10 +566,11 @@
// Release error handler
this.errorHandler = null;
- if (this.errorPipeline != null) {
- this.errorPipeline.release();
- this.errorPipeline = null;
- }
+
+ // Release error pipeline
+ // This is not done by using release in the creating container as release
+ // is a noop for the Avalon life style in the Spring container
+ this.errorPipeline = null;
}
protected boolean processErrorHandler(Environment environment, ProcessingException e, XMLConsumer consumer)
@@ -578,8 +579,8 @@
try {
this.errorPipeline = this.errorHandler.prepareErrorPipeline(e);
if (this.errorPipeline != null) {
- this.errorPipeline.processingPipeline.prepareInternal(environment);
- return this.errorPipeline.processingPipeline.process(environment, consumer);
+ this.errorPipeline.prepareInternal(environment);
+ return this.errorPipeline.process(environment, consumer);
}
} catch (Exception ignored) {
getLogger().debug("Exception in error handler", ignored);
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapErrorHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapErrorHandler.java?view=diff&rev=486818&r1=486817&r2=486818
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapErrorHandler.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapErrorHandler.java Wed Dec 13 11:50:39 2006
@@ -17,6 +17,7 @@
package org.apache.cocoon.sitemap;
import org.apache.cocoon.Processor;
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.components.treeprocessor.InvokeContext;
import org.apache.cocoon.components.treeprocessor.sitemap.ErrorHandlerHelper;
import org.apache.cocoon.environment.Environment;
@@ -77,10 +78,13 @@
* Build error handling pipeline.
* @return error handling pipeline, or null if error was not handled.
*/
- public Processor.InternalPipelineDescription prepareErrorPipeline(Exception e) throws Exception {
+ public ProcessingPipeline prepareErrorPipeline(Exception e) throws Exception {
// Restore environment state
this.environment.setURI(this.envPrefix, this.envURI);
+
+ Processor.InternalPipelineDescription pipelineDescription =
+ this.handler.prepareErrorHandler(e, this.environment, this.context);
- return this.handler.prepareErrorHandler(e, this.environment, this.context);
+ return pipelineDescription != null ? pipelineDescription.processingPipeline : null;
}
}