cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Hartmann <andr...@apache.org>
Subject Re: [Corona] PIpeline API
Date Thu, 17 Jul 2008 15:57:46 GMT
Carsten Ziegeler schrieb:

[…]

>> Client code inside a web application:
>>
>> public void parameterizeComponents(Request req, Pipeline pipeline) {
>>   for (Iterator i = pipeline.getComponents().iterator(); … ) {
>>     PipelineComponent c = (PipelineComponent) i.next();
>>     if (c instanceof WebappPipelineComponent) {
>>       WebappPipelineComponent wpc = (…) c;
>>       wpc.setRequest(req);
>>     }
>>   }
>> }
>>
>> The pipeline is executed in a specific environment. The actual
>> pipeline object itself is oblivious of the environment information, but
>> the pipeline components are directly dependent on the environment.
 >
> Hmm, yes this would work, but :) this would make it harder to have a 
> reusable pipeline implementation that frees my application from passing 
> the information to the components.

Does it make a big difference if the information is passed to the 
pipeline or to the components? To get rid of the boilerplate loop above, 
the visitor pattern could be used:

public class Webapp implements PipelineEnvironment {

   public void preparePipelineForExecution() {
     // let the pipeline visit its components
     this.pipeline.setEnvironment(this);
   }

   /**
    * @see PipelineEnvironment.environmentalize(…)
    */
   public void environmentalize(PipelineComponent c) {
     if (c instanceof WebappPipelineComponent) {
       WebappPipelineComponent wpc = (…) c;
       wpc.setRequest(req);
     }
   }

}


> Currently the app creates a map, passed it to the pipeline 
> implementation and this implementation passes the map on to the components.
> With the approach above, I would need a custom pipeline implementation 
> to do this.

Hmm, why would you need a custom pipeline implementation? Wouldn't this 
be generic enough:

public class PipelineImpl implements Pipeline {

   public void setEnvironment(PipelineEnvironment env) {
     for (Iterator i = getComponents().iterator(); … ) {
       PipelineComponent c = (…) i.next();
       env.environmentalize(c);
     }
   }

}


> Furthermore there might be a lot of marker interfaces to test.

The marker interfaces wouldn't be generic, but application-specific, so 
there would only be one needed per application.

I imagine to use application-specific wrappers for "standard" pipeline 
components, e.g.

public class WebappXsltTransformerWrapper implements Transformer,
   WebappPipelineComponent {

   private XsltTransformer delegate;

   public void setRequest(Request req) {
     if (this.useRequestParams()) {
       this.delegate.setXsltParams(req.getParameterMap());
     }
   }
}

In this case the application can provide a layer of classes to adapt the 
standard pipeline components to the application-specific environment. 
The marker interface check would allow to use other components as well - 
they just wouldn't be "environmentalized".

-- Andreas



-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


Mime
View raw message