1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.workflow.base;
18
19
20 import java.util.ArrayList;
21 import org.apache.commons.workflow.Activity;
22 import org.apache.commons.workflow.Step;
23
24
25
26
27
28
29
30
31
32
33
34
35 public class BaseActivity implements Activity {
36
37
38
39
40
41
42
43
44 protected Step firstStep = null;
45
46
47
48
49
50 protected String id = null;
51
52
53
54
55
56 protected Step lastStep = null;
57
58
59
60
61
62
63
64
65 public Step getFirstStep() {
66
67 return (this.firstStep);
68
69 }
70
71
72
73
74
75 public String getId() {
76
77 return (this.id);
78
79 }
80
81
82
83
84
85
86
87 public void setId(String id) {
88
89 this.id = id;
90
91 }
92
93
94
95
96
97 public Step getLastStep() {
98
99 return (this.lastStep);
100
101 }
102
103
104
105
106
107
108
109
110
111
112
113 public void addStep(Step step) {
114
115 step.setOwner(this);
116 if (firstStep == null) {
117 step.setPreviousStep(null);
118 step.setNextStep(null);
119 firstStep = step;
120 lastStep = step;
121 } else {
122 step.setPreviousStep(lastStep);
123 step.setNextStep(null);
124 lastStep.setNextStep(step);
125 lastStep = step;
126 }
127
128 }
129
130
131
132
133
134 public void clearSteps() {
135
136 Step current = firstStep;
137 while (current != null) {
138 Step next = current.getNextStep();
139 current.setOwner(null);
140 current.setPreviousStep(null);
141 current.setNextStep(null);
142 current = next;
143 }
144 firstStep = null;
145 lastStep = null;
146
147 }
148
149
150
151
152
153
154
155
156 public Step findStep(String id) {
157
158 Step current = getFirstStep();
159 while (current != null) {
160 if (id.equals(current.getId()))
161 return (current);
162 current = current.getNextStep();
163 }
164 return (null);
165
166 }
167
168
169
170
171
172 public Step[] getSteps() {
173
174 ArrayList list = new ArrayList();
175 Step currentStep = firstStep;
176 while (currentStep != null) {
177 list.add(currentStep);
178 currentStep = currentStep.getNextStep();
179 }
180 Step steps[] = new Step[list.size()];
181 return ((Step[]) list.toArray(steps));
182
183 }
184
185
186
187
188
189
190
191
192 public void setSteps(Step steps[]) {
193
194 clearSteps();
195 for (int i = 0; i < steps.length; i++)
196 addStep(steps[i]);
197
198 }
199
200
201 }