Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AndStep |
|
| 2.2;2.2 |
1 | /* | |
2 | * Copyright 1999-2001,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package org.apache.commons.workflow.core; | |
18 | ||
19 | ||
20 | import org.apache.commons.workflow.Context; | |
21 | import org.apache.commons.workflow.Descriptor; | |
22 | import org.apache.commons.workflow.Step; | |
23 | import org.apache.commons.workflow.StepException; | |
24 | ||
25 | ||
26 | /** | |
27 | * <p>Evaluate properties specified by the associated Descriptors, and | |
28 | * transfer control to the specified step if ALL of them are | |
29 | * <code>true</code> (if boolean) or not null (if Object). To avoid | |
30 | * non-deterministic evaluation stack behavior, all of the specified | |
31 | * Descriptors are always evaluated.</p> | |
32 | * | |
33 | * <p>Supported Attributes:</p> | |
34 | * <ul> | |
35 | * <li><strong>step</strong> - Identifier of the Step to which control | |
36 | * should be transferred if the condition is met.</li> | |
37 | * </ul> | |
38 | * | |
39 | * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $ | |
40 | * @author Craig R. McClanahan | |
41 | */ | |
42 | ||
43 | public class AndStep extends GotoStep { | |
44 | ||
45 | ||
46 | // ----------------------------------------------------------= Constructors | |
47 | ||
48 | ||
49 | /** | |
50 | * Construct a default instance of this Step. | |
51 | */ | |
52 | public AndStep() { | |
53 | ||
54 | 0 | super(); |
55 | ||
56 | 0 | } |
57 | ||
58 | ||
59 | /** | |
60 | * Construct an instance of this Step with the specified identifier. | |
61 | * | |
62 | * @param id Step identifier | |
63 | */ | |
64 | public AndStep(String id) { | |
65 | ||
66 | 0 | this(id, null, null); |
67 | ||
68 | 0 | } |
69 | ||
70 | ||
71 | /** | |
72 | * Construct a fully configured instance of this Step. | |
73 | * | |
74 | * @param id Step identifier of this step | |
75 | * @param step Step identifier to which control should be redirected | |
76 | */ | |
77 | public AndStep(String id, String step) { | |
78 | ||
79 | 0 | this(id, step, null); |
80 | ||
81 | 0 | } |
82 | ||
83 | ||
84 | /** | |
85 | * Construct a fully configured instance of this Step. | |
86 | * | |
87 | * @param id Step identifier of this step | |
88 | * @param step Step identifier to which control should be redirected | |
89 | * @param descriptor Initial descriptor to be added | |
90 | */ | |
91 | public AndStep(String id, String step, Descriptor descriptor) { | |
92 | ||
93 | 0 | super(); |
94 | 0 | setId(id); |
95 | 0 | setStep(step); |
96 | 0 | addDescriptor(descriptor); |
97 | ||
98 | 0 | } |
99 | ||
100 | ||
101 | // --------------------------------------------------------- Public Methods | |
102 | ||
103 | ||
104 | /** | |
105 | * Perform the executable actions related to this Step, in the context of | |
106 | * the specified Context. | |
107 | * | |
108 | * @param context The Context that is tracking our execution state | |
109 | * | |
110 | * @exception StepException if a processing error has occurred | |
111 | */ | |
112 | public void execute(Context context) throws StepException { | |
113 | ||
114 | // Process all associated descriptors | |
115 | 0 | boolean condition = true; |
116 | 0 | Descriptor descriptors[] = findDescriptors(); |
117 | 0 | for (int i = 0; i < descriptors.length; i++) { |
118 | 0 | Object value = descriptors[i].get(context); |
119 | 0 | if (value == null) |
120 | 0 | condition = false; |
121 | 0 | else if ((value instanceof Boolean) && |
122 | !((Boolean) value).booleanValue()) | |
123 | 0 | condition = false; |
124 | } | |
125 | ||
126 | // Conditionally forward control to the specified step | |
127 | 0 | if (condition) { |
128 | 0 | Step next = getOwner().findStep(this.step); |
129 | 0 | if (next == null) |
130 | 0 | throw new StepException("Cannot find step '" + step + "'", |
131 | this); | |
132 | 0 | context.setNextStep(next); |
133 | } | |
134 | ||
135 | 0 | } |
136 | ||
137 | ||
138 | } |