1 package org.apache.turbine.pipeline; 2 3 56 57 import java.io.BufferedReader ; 58 import java.io.FileReader ; 59 import java.io.IOException ; 60 import java.io.Reader ; 61 62 import org.apache.turbine.Pipeline; 63 import org.apache.turbine.RunData; 64 import org.apache.turbine.TurbineException; 65 import org.apache.turbine.Valve; 66 import org.apache.turbine.ValveContext; 67 68 import org.apache.commons.logging.Log; 69 import org.apache.commons.logging.LogFactory; 70 71 import com.thoughtworks.xstream.XStream; 72 import com.thoughtworks.xstream.io.xml.DomDriver; 73 74 82 public abstract class ConditionalValve 83 extends BranchPointValve 84 { 85 private static final Log log = LogFactory.getLog( ConditionalValve.class ); 86 private static final String pipelineClassName = 87 "org.apache.turbine.pipeline.TurbinePipeline"; 88 89 private String pipelineDescriptorPath; 90 91 94 protected ConditionalValve() 95 { 96 pipelines = new Pipeline[] { new TurbinePipeline() }; 97 } 98 99 100 public void setPipelineDescriptorPath(String pdp) 101 { 102 this.pipelineDescriptorPath = pdp; 103 } 104 105 110 public void initialize() 111 throws Exception 112 { 113 if (pipelineDescriptorPath != null) 116 { 117 log.debug("ConditionalValve using descriptor path: " 118 + pipelineDescriptorPath); 119 Reader reader = new BufferedReader (new FileReader (pipelineDescriptorPath)); 120 XStream pipelineMapper = new XStream(new DomDriver()); pipelines[0] = (Pipeline) 122 (Pipeline) pipelineMapper.fromXML(reader); 123 } 124 super.initialize(); 125 } 126 127 128 131 public void addValve( Valve valve ) 132 { 133 pipelines[0].addValve( valve ); 134 } 135 136 139 public void invoke( RunData data, ValveContext context ) 140 throws IOException , TurbineException 141 { 142 if ( shouldInvoke( data ) ) 143 { 144 log.debug("Invoking conditional pipeline"); 145 pipelines[0].invoke( data ); 146 } 147 148 context.invokeNext( data ); 149 } 150 151 157 protected abstract boolean shouldInvoke( RunData data ); 158 } 159 | Popular Tags |