craigmcc 01/11/18 14:19:13 Modified: workflow/src/java/org/apache/commons/workflow/core CoreRuleSet.java Added: workflow/src/java/org/apache/commons/workflow/core NotAndStep.java NotOrStep.java Log: Add "NotAndStep" and "NotOrStep" implementations that are the exact opposite of "AndStep" and "OrStep". While not strictly required for functional completeness, these rules make some logic sequences easier to express. Submitted by: Colin Sharples <[EMAIL PROTECTED]> Revision Changes Path 1.5 +39 -4 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/CoreRuleSet.java Index: CoreRuleSet.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/CoreRuleSet.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CoreRuleSet.java 2001/09/19 15:26:16 1.4 +++ CoreRuleSet.java 2001/11/18 22:19:13 1.5 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/CoreRuleSet.java,v 1.4 2001/09/19 15:26:16 craigmcc Exp $ - * $Revision: 1.4 $ - * $Date: 2001/09/19 15:26:16 $ + * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/CoreRuleSet.java,v 1.5 2001/11/18 22:19:13 craigmcc Exp $ + * $Revision: 1.5 $ + * $Date: 2001/11/18 22:19:13 $ * * ==================================================================== * @@ -76,7 +76,8 @@ * </pre> * * @author Craig R. McClanahan - * @version $Revision: 1.4 $ $Date: 2001/09/19 15:26:16 $ + * @author Preston Sheldon + * @version $Revision: 1.5 $ $Date: 2001/11/18 22:19:13 $ */ public class CoreRuleSet extends BaseRuleSet { @@ -242,6 +243,40 @@ (prefix + "load", "addStep", "org.apache.commons.workflow.Step"); + digester.addObjectCreate + (prefix + "notAnd", + "org.apache.commons.workflow.core.AndNotStep"); + digester.addSetProperties + (prefix + "notAnd"); + digester.addSetNext + (prefix + "notAnd", "addStep", + "org.apache.commons.workflow.Step"); + digester.addObjectCreate + (prefix + "notAnd/descriptor", + "org.apache.commons.workflow.base.BaseDescriptor"); + digester.addSetProperties + (prefix + "notAnd/descriptor"); + digester.addSetNext + (prefix + "notAnd/descriptor", "addDescriptor", + "org.apache.commons.workflow.Descriptor"); + + digester.addObjectCreate + (prefix + "notOr", + "org.apache.commons.workflow.core.OrStep"); + digester.addSetProperties + (prefix + "notOr"); + digester.addSetNext + (prefix + "notOr", "addStep", + "org.apache.commons.workflow.Step"); + digester.addObjectCreate + (prefix + "notOr/descriptor", + "org.apache.commons.workflow.base.BaseDescriptor"); + digester.addSetProperties + (prefix + "notOr/descriptor"); + digester.addSetNext + (prefix + "notOr/descriptor", "addDescriptor", + "org.apache.commons.workflow.Descriptor"); + digester.addObjectCreate (prefix + "or", "org.apache.commons.workflow.core.OrStep"); 1.1 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/NotAndStep.java Index: NotAndStep.java =================================================================== package org.apache.commons.workflow.core; import org.apache.commons.workflow.Context; import org.apache.commons.workflow.Descriptor; import org.apache.commons.workflow.Step; import org.apache.commons.workflow.StepException; /** * <p>Evaluate properties specified by the associated Descriptors, and * transfer control to the specified step if ALL of them are * <code>false</code> (if boolean) or null (if Object). * * <b>This is the exact opposite of AndStep</b> * * To avoid non-deterministic evaluation stack behavior, all of the * specified Descriptors are always evaluated.</p> * * <p>Supported Attributes:</p> * <ul> * <li><strong>step</strong> - Identifier of the Step to which control * should be transferred if the condition is not met.</li> * </ul> * * @version $Revision: 1.1 $ $Date: 2001/11/18 22:19:13 $ * @author Preston Sheldon */ public class NotAndStep extends GotoStep { // ----------------------------------------------------------= Constructors /** * Construct a default instance of this Step. */ public NotAndStep() { super(); } /** * Construct an instance of this Step with the specified identifier. * * @param id Step identifier */ public NotAndStep(String id) { this(id, null, null); } /** * Construct a fully configured instance of this Step. * * @param id Step identifier of this step * @param step Step identifier to which control should be redirected */ public NotAndStep(String id, String step) { this(id, step, null); } /** * Construct a fully configured instance of this Step. * * @param id Step identifier of this step * @param step Step identifier to which control should be redirected * @param descriptor Initial descriptor to be added */ public NotAndStep(String id, String step, Descriptor descriptor) { super(); setId(id); setStep(step); addDescriptor(descriptor); } // --------------------------------------------------------- Public Methods /** * Perform the executable actions related to this Step, in the context of * the specified Context. * * @param context The Context that is tracking our execution state * * @exception StepException if a processing error has occurred */ public void execute(Context context) throws StepException { // Process all associated descriptors boolean condition = true; Descriptor descriptors[] = findDescriptors(); for (int i = 0; i < descriptors.length; i++) { Object value = descriptors[i].get(context); if (value == null) condition = false; else if ((value instanceof Boolean) && !((Boolean) value).booleanValue()) condition = false; } // Conditionally forward control to the specified step if (!condition) { Step next = findStep(this.step); if (next == null) throw new StepException("Cannot find step '" + step + "'", this); context.setNextStep(next); } } } 1.1 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/NotOrStep.java Index: NotOrStep.java =================================================================== package org.apache.commons.workflow.core; import org.apache.commons.workflow.Context; import org.apache.commons.workflow.Descriptor; import org.apache.commons.workflow.Step; import org.apache.commons.workflow.StepException; /** * <p>Evaluate properties specified by the associated Descriptors, and * transfer control to the specified step if ANY of them are * <code>false</code> (if boolean) or null (if Object). * * <b>This is the exact opposite of OrStep</b> * * To avoid non-deterministic evaluation stack behavior, all of the * specified Descriptors are always evaluated.</p> * * <p>Supported Attributes:</p> * <ul> * <li><strong>step</strong> - Identifier of the Step to which control * should be transferred if the condition is met.</li> * </ul> * * @version $Revision: 1.1 $ $Date: 2001/11/18 22:19:13 $ * @author Preston Sheldon */ public class NotOrStep extends GotoStep { // ----------------------------------------------------------= Constructors /** * Construct a default instance of this Step. */ public NotOrStep() { super(); } /** * Construct an instance of this Step with the specified identifier. * * @param id Step identifier */ public NotOrStep(String id) { this(id, null, null); } /** * Construct a fully configured instance of this Step. * * @param id Step identifier of this step * @param step Step identifier to which control should be redirected */ public NotOrStep(String id, String step) { this(id, step, null); } /** * Construct a fully configured instance of this Step. * * @param id Step identifier of this step * @param step Step identifier to which control should be redirected * @param descriptor Initial descriptor to be added */ public NotOrStep(String id, String step, Descriptor descriptor) { super(); setId(id); setStep(step); addDescriptor(descriptor); } // --------------------------------------------------------- Public Methods /** * Perform the executable actions related to this Step, in the context of * the specified Context. * * @param context The Context that is tracking our execution state * * @exception StepException if a processing error has occurred */ public void execute(Context context) throws StepException { // Process all associated descriptors boolean condition = false; Descriptor descriptors[] = findDescriptors(); for (int i = 0; i < descriptors.length; i++) { Object value = descriptors[i].get(context); if (value != null) { if (value instanceof Boolean) { if (((Boolean) value).booleanValue()) condition = true; } else { condition = true; } } } // Conditionally forward control to the specified step if (!condition) { Step next = findStep(this.step); if (next == null) throw new StepException("Cannot find step '" + step + "'", this); context.setNextStep(next); } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>