1 package br.com.ibnetwork.guara.pipeline.impl;
2
3 import org.apache.commons.lang.ArrayUtils;
4
5 import br.com.ibnetwork.guara.pipeline.Pipeline;
6 import br.com.ibnetwork.guara.pipeline.PipelineException;
7 import br.com.ibnetwork.guara.pipeline.Valve;
8 import br.com.ibnetwork.guara.rundata.RunData;
9
10 /***
11 * @author <a href="mailto:leandro@ibnetwork.com.br">leandro</a>
12 */
13 public class PipelineImpl
14 implements Pipeline
15 {
16 private Valve[] valves;
17
18 private String name;
19
20 public PipelineImpl(String name)
21 {
22 this.name = name;
23 }
24
25 public String getName()
26 {
27 return name;
28 }
29
30 public void execute(RunData runData)
31 {
32 Valve start = valves[0];
33 start.forward(runData);
34 }
35
36 public Valve[] getValves()
37 {
38 return valves;
39 }
40
41 public Valve getValveByName(String valveName)
42 {
43 for (int i = 0; i < valves.length; i++)
44 {
45 Valve valve = valves[i];
46 if(valve.getName().equals(valveName))
47 {
48 return valve;
49 }
50 }
51 return null;
52 }
53
54
55 public void addValve(Valve valve)
56 throws PipelineException
57 {
58 if(valves == null)
59 {
60 valves = new Valve[0];
61 }
62 int size = valves.length;
63 Valve[] tmp = new Valve[size + 1];
64 tmp[size] = valve;
65 System.arraycopy(valves,0,tmp,0,size);
66 valves = tmp;
67 }
68
69
70 public void removeValve(Valve valve)
71 throws PipelineException
72 {
73 }
74
75 public Valve getNextValve(Valve valve)
76 throws PipelineException
77 {
78 int index = ArrayUtils.indexOf(valves,valve);
79 return index < 0 || index == valves.length -1 ? null : valves[index+1];
80 }
81
82 }