View Javadoc

1   package org.apache.commons.workflow.core;
2   
3   import org.apache.commons.workflow.Context;
4   import org.apache.commons.workflow.Descriptor;
5   import org.apache.commons.workflow.Step;
6   import org.apache.commons.workflow.StepException;
7   
8   
9   /**
10   * <p>Evaluate properties specified by the associated Descriptors, and
11   * transfer control to the specified step if ALL of them are
12   * <code>false</code> (if boolean) or null (if Object).
13   *
14   * <b>This is the exact opposite of AndStep</b>
15   *
16   * To avoid non-deterministic evaluation stack behavior, all of the 
17   * specified Descriptors are always evaluated.</p>
18   *
19   * <p>Supported Attributes:</p>
20   * <ul>
21   * <li><strong>step</strong> - Identifier of the Step to which control
22   *     should be transferred if the condition is not met.</li>
23   * </ul>
24   *
25   * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
26   * @author Preston Sheldon
27   */
28  
29  public class NotAndStep extends GotoStep {
30  
31  
32      // ----------------------------------------------------------= Constructors
33  
34  
35      /**
36       * Construct a default instance of this Step.
37       */
38      public NotAndStep() {
39  
40          super();
41  
42      }
43      /**
44       * Construct an instance of this Step with the specified identifier.
45       *
46       * @param id Step identifier
47       */
48      public NotAndStep(String id) {
49  
50          this(id, null, null);
51  
52      }
53      /**
54       * Construct a fully configured instance of this Step.
55       *
56       * @param id Step identifier of this step
57       * @param step Step identifier to which control should be redirected
58       */
59      public NotAndStep(String id, String step) {
60  
61          this(id, step, null);
62  
63      }
64      /**
65       * Construct a fully configured instance of this Step.
66       *
67       * @param id Step identifier of this step
68       * @param step Step identifier to which control should be redirected
69       * @param descriptor Initial descriptor to be added
70       */
71      public NotAndStep(String id, String step, Descriptor descriptor) {
72  
73          super();
74          setId(id);
75          setStep(step);
76          addDescriptor(descriptor);
77  
78      }
79      // --------------------------------------------------------- Public Methods
80  
81  
82      /**
83       * Perform the executable actions related to this Step, in the context of
84       * the specified Context.
85       *
86       * @param context The Context that is tracking our execution state
87       *
88       * @exception StepException if a processing error has occurred
89       */
90      public void execute(Context context) throws StepException {
91  
92          // Process all associated descriptors
93          boolean condition = true;
94          Descriptor descriptors[] = findDescriptors();
95          for (int i = 0; i < descriptors.length; i++) {
96              Object value = descriptors[i].get(context);
97              if (value == null)
98                  condition = false;
99              else if ((value instanceof Boolean) &&
100                      !((Boolean) value).booleanValue())
101                 condition = false;
102         }
103 
104         // Conditionally forward control to the specified step
105         if (!condition) {
106             Step next = getOwner().findStep(this.step);
107             if (next == null)
108                 throw new StepException("Cannot find step '" + step + "'",
109                                         this);
110             context.setNextStep(next);
111         }
112                 
113     }
114 }