Coverage Report - org.apache.commons.workflow.core.NotOrStep
 
Classes in this File Line Coverage Branch Coverage Complexity
NotOrStep
0%
0/26
0%
0/12
2.4
 
 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 ANY of them are
 12  
  * <code>false</code> (if boolean) or null (if Object).
 13  
  *
 14  
  * <b>This is the exact opposite of OrStep</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 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 NotOrStep extends GotoStep {
 30  
 
 31  
 
 32  
     // ----------------------------------------------------------= Constructors
 33  
 
 34  
 
 35  
     /**
 36  
      * Construct a default instance of this Step.
 37  
      */
 38  
     public NotOrStep() {
 39  
 
 40  0
         super();
 41  
 
 42  0
     }
 43  
     /**
 44  
      * Construct an instance of this Step with the specified identifier.
 45  
      *
 46  
      * @param id Step identifier
 47  
      */
 48  
     public NotOrStep(String id) {
 49  
 
 50  0
         this(id, null, null);
 51  
 
 52  0
     }
 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 NotOrStep(String id, String step) {
 60  
 
 61  0
         this(id, step, null);
 62  
 
 63  0
     }
 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 NotOrStep(String id, String step, Descriptor descriptor) {
 72  
 
 73  0
         super();
 74  0
         setId(id);
 75  0
         setStep(step);
 76  0
         addDescriptor(descriptor);
 77  
 
 78  0
     }
 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  0
         boolean condition = false;
 94  0
         Descriptor descriptors[] = findDescriptors();
 95  0
         for (int i = 0; i < descriptors.length; i++) {
 96  0
             Object value = descriptors[i].get(context);
 97  0
             if (value != null) {
 98  0
                 if (value instanceof Boolean) {
 99  0
                     if (((Boolean) value).booleanValue())
 100  0
                         condition = true;
 101  
                 } else {
 102  0
                     condition = true;
 103  
                 }
 104  
             }
 105  
         }
 106  
 
 107  
         // Conditionally forward control to the specified step
 108  0
         if (!condition) {
 109  0
             Step next = getOwner().findStep(this.step);
 110  0
             if (next == null)
 111  0
                 throw new StepException("Cannot find step '" + step + "'",
 112  
                                         this);
 113  0
             context.setNextStep(next);
 114  
         }
 115  
                 
 116  0
     }
 117  
 }
 118