1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.workflow.core;
18
19
20 import java.util.EmptyStackException;
21 import org.apache.commons.workflow.Block;
22 import org.apache.commons.workflow.BlockState;
23 import org.apache.commons.workflow.Context;
24 import org.apache.commons.workflow.Descriptor;
25 import org.apache.commons.workflow.Step;
26 import org.apache.commons.workflow.StepException;
27 import org.apache.commons.workflow.base.BaseBlock;
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class IfStep extends BaseBlock {
42
43
44
45
46
47
48
49
50 public IfStep() {
51
52 super();
53
54 }
55
56
57
58
59
60
61
62 public IfStep(String id) {
63
64 this(id, null);
65
66 }
67
68
69
70
71
72
73
74
75 public IfStep(String id, Descriptor descriptor) {
76
77 super();
78 setId(id);
79 if (descriptor != null)
80 addDescriptor(descriptor);
81
82 }
83
84
85
86
87
88
89
90
91 public String toString() {
92
93 StringBuffer sb = new StringBuffer("<core:if");
94 if (getId() != null) {
95 sb.append(" id=\"");
96 sb.append(getId());
97 sb.append("\"");
98 }
99 sb.append(">");
100 Descriptor descriptors[] = findDescriptors();
101 for (int i = 0; i < descriptors.length; i++)
102 sb.append(descriptors[i]);
103 Step steps[] = getSteps();
104 for (int i = 0; i < steps.length; i++)
105 sb.append(steps[i]);
106 sb.append("</core:if>");
107 return (sb.toString());
108
109 }
110
111
112
113
114
115
116
117
118
119
120
121 protected boolean evaluate(Context context) {
122
123 boolean condition = true;
124 Descriptor descriptors[] = findDescriptors();
125 for (int i = 0; i < descriptors.length; i++) {
126 if (descriptors[i] == null)
127 continue;
128 if (!descriptors[i].positive(context))
129 condition = false;
130 }
131 return (condition);
132
133 }
134
135
136
137
138
139
140
141 protected void initial(Context context) {
142
143 if (evaluate(context)) {
144 BlockState state = new BlockState(this, false);
145 context.pushBlockState(state);
146 context.setNextStep(getFirstStep());
147 } else {
148 context.setNextStep(getNextStep());
149 }
150
151 }
152
153
154 }