Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IfNotAnyStep |
|
| 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 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 | * <p>Evaluate properties specified by the associated Descriptors, and | |
32 | * execute the nested Steps if and only if <strong>ALL</strong> of them | |
33 | * evaluate to a negative result. To avoid non-deterministic evaluation | |
34 | * stack behavior, all of the specified Descriptors are always | |
35 | * evaluated exactly once.</p> | |
36 | * | |
37 | * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $ | |
38 | * @author Craig R. McClanahan | |
39 | */ | |
40 | ||
41 | public class IfNotAnyStep extends IfStep { | |
42 | ||
43 | ||
44 | // ----------------------------------------------------------= Constructors | |
45 | ||
46 | ||
47 | /** | |
48 | * Construct a default instance of this Step. | |
49 | */ | |
50 | public IfNotAnyStep() { | |
51 | ||
52 | 0 | super(); |
53 | ||
54 | 0 | } |
55 | ||
56 | ||
57 | /** | |
58 | * Construct an instance of this Step with the specified identifier. | |
59 | * | |
60 | * @param id Step identifier | |
61 | */ | |
62 | public IfNotAnyStep(String id) { | |
63 | ||
64 | 0 | this(id, null); |
65 | ||
66 | 0 | } |
67 | ||
68 | ||
69 | /** | |
70 | * Construct a fully configured instance of this Step. | |
71 | * | |
72 | * @param id Step identifier of this step | |
73 | * @param descriptor Initial descriptor to be added | |
74 | */ | |
75 | public IfNotAnyStep(String id, Descriptor descriptor) { | |
76 | ||
77 | 0 | super(); |
78 | 0 | setId(id); |
79 | 0 | if (descriptor != null) |
80 | 0 | addDescriptor(descriptor); |
81 | ||
82 | 0 | } |
83 | ||
84 | ||
85 | // --------------------------------------------------------- Public Methods | |
86 | ||
87 | ||
88 | /** | |
89 | * Render a string representation of this Step. | |
90 | */ | |
91 | public String toString() { | |
92 | ||
93 | 0 | StringBuffer sb = new StringBuffer("<core:ifNotAny"); |
94 | 0 | if (getId() != null) { |
95 | 0 | sb.append(" id=\""); |
96 | 0 | sb.append(getId()); |
97 | 0 | sb.append("\""); |
98 | } | |
99 | 0 | sb.append(">"); |
100 | 0 | Descriptor descriptors[] = findDescriptors(); |
101 | 0 | for (int i = 0; i < descriptors.length; i++) |
102 | 0 | sb.append(descriptors[i]); |
103 | 0 | Step steps[] = getSteps(); |
104 | 0 | for (int i = 0; i < steps.length; i++) |
105 | 0 | sb.append(steps[i]); |
106 | 0 | sb.append("</core:ifNotAny>"); |
107 | 0 | return (sb.toString()); |
108 | ||
109 | } | |
110 | ||
111 | ||
112 | // ------------------------------------------------------ Protected Methods | |
113 | ||
114 | ||
115 | /** | |
116 | * Evaluate the condition specified by the Descriptors associated with | |
117 | * this Block, and return the resulting boolean value. | |
118 | * | |
119 | * @param context Context within which to evaluate the descriptors | |
120 | */ | |
121 | protected boolean evaluate(Context context) { | |
122 | ||
123 | 0 | boolean condition = false; |
124 | 0 | Descriptor descriptors[] = findDescriptors(); |
125 | 0 | for (int i = 0; i < descriptors.length; i++) { |
126 | 0 | if (descriptors[i].positive(context)) |
127 | 0 | condition = true; |
128 | } | |
129 | 0 | return (!condition); |
130 | ||
131 | } | |
132 | ||
133 | ||
134 | } |