1 package org.apache.turbine.pipeline; 2 3 56 57 import java.io.IOException ; 58 59 import org.apache.turbine.Pipeline; 60 import org.apache.turbine.RunData; 61 import org.apache.turbine.TurbineException; 62 import org.apache.turbine.Valve; 63 import org.apache.turbine.ValveContext; 64 65 72 public class TurbinePipeline 73 implements Pipeline, ValveContext 74 { 75 78 public static String CLASSIC_PIPELINE = 79 "conf/turbine-classic-pipeline.xml"; 80 81 84 protected String name; 85 86 89 protected Valve[] valves = new Valve[0]; 90 91 98 protected ThreadLocal state = new ThreadLocal (); 99 100 103 public void initialize() 104 throws Exception 105 { 106 if (state==null){ 108 state = new ThreadLocal (); 109 } 110 111 for (int i = 0; i < valves.length; i++) 113 { 114 valves[i].initialize(); 115 } 116 } 117 118 123 public void setName(String name) 124 { 125 this.name = name; 126 } 127 128 133 public String getName() 134 { 135 return name; 136 } 137 138 141 public void addValve(Valve valve) 142 { 143 synchronized (valves) 145 { 146 Valve[] results = new Valve[valves.length + 1]; 147 System.arraycopy(valves, 0, results, 0, valves.length); 148 results[valves.length] = valve; 149 valves = results; 150 } 151 } 152 153 156 public Valve[] getValves() 157 { 158 synchronized (valves) 159 { 160 Valve[] results = new Valve[valves.length]; 161 System.arraycopy(valves, 0, results, 0, valves.length); 162 return results; 163 } 164 } 165 166 169 public void removeValve(Valve valve) 170 { 171 synchronized (valves) 172 { 173 int index = -1; 175 for (int i = 0; i < valves.length; i++) 176 { 177 if (valve == valves[i]) 178 { 179 index = i; 180 break; 181 } 182 } 183 if (index < 0) 184 { 185 return; 186 } 187 188 Valve[] results = new Valve[valves.length - 1]; 190 int n = 0; 191 for (int i = 0; i < valves.length; i++) 192 { 193 if (i == index) 194 { 195 continue; 196 } 197 results[n++] = valves[i]; 198 } 199 valves = results; 200 } 201 } 202 203 206 public void invoke(RunData data) 207 throws TurbineException, IOException 208 { 209 state.set(new Integer (0)); 211 212 invokeNext(data); 214 } 215 216 219 public void invokeNext(RunData data) 220 throws TurbineException, IOException 221 { 222 Integer current = (Integer ) state.get(); 224 int subscript = current.intValue(); 225 226 if (subscript < valves.length) 227 { 228 state.set(new Integer (subscript + 1)); 231 valves[subscript].invoke(data, this); 232 } 233 } 234 } 235 | Popular Tags |