1 package org.apache.turbine.pipeline;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.Iterator;
24 import java.util.concurrent.CopyOnWriteArrayList;
25
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlAttribute;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlElementWrapper;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33
34 import org.apache.turbine.annotation.AnnotationProcessor;
35 import org.apache.turbine.util.TurbineException;
36
37
38
39
40
41
42
43
44
45 @XmlRootElement(name="pipeline")
46 @XmlAccessorType(XmlAccessType.NONE)
47 public class TurbinePipeline
48 implements Pipeline, ValveContext
49 {
50
51
52
53 public static final String CLASSIC_PIPELINE =
54 "/WEB-INF/conf/turbine-classic-pipeline.xml";
55
56
57
58
59 @XmlAttribute
60 private String name;
61
62
63
64
65 private CopyOnWriteArrayList<Valve> valves = new CopyOnWriteArrayList<>();
66
67
68
69
70 private ThreadLocal<Iterator<Valve>> state = new ThreadLocal<>();
71
72
73
74
75 @Override
76 public void initialize()
77 throws Exception
78 {
79
80
81
82
83 for (Valve v : valves)
84 {
85 AnnotationProcessor.process(v);
86 v.initialize();
87 }
88 }
89
90
91
92
93
94
95
96 public void setName(String name)
97 {
98 this.name = name;
99 }
100
101
102
103
104
105
106 public String getName()
107 {
108 return name;
109 }
110
111
112
113
114 @Override
115 public void addValve(Valve valve)
116 {
117
118 valves.add(valve);
119 }
120
121
122
123
124 @Override
125 @XmlElementWrapper(name="valves")
126 @XmlElement(name="valve")
127 @XmlJavaTypeAdapter(XmlValveAdapter.class)
128 public Valve[] getValves()
129 {
130 return valves.toArray(new Valve[0]);
131 }
132
133
134
135
136
137
138 protected void setValves(Valve[] valves)
139 {
140 this.valves = new CopyOnWriteArrayList<>(valves);
141 }
142
143
144
145
146 @Override
147 public void removeValve(Valve valve)
148 {
149 valves.remove(valve);
150 }
151
152
153
154
155 @Override
156 public void invoke(PipelineData pipelineData)
157 throws TurbineException, IOException
158 {
159
160 state.set(valves.iterator());
161
162
163 invokeNext(pipelineData);
164 }
165
166
167
168
169 @Override
170 public void invokeNext(PipelineData pipelineData)
171 throws TurbineException, IOException
172 {
173
174 Iterator<Valve> current = state.get();
175
176 if (current.hasNext())
177 {
178
179
180 current.next().invoke(pipelineData, this);
181 }
182 }
183 }