Package com.microworkflow.process

Source Code of com.microworkflow.process.Conditional

/*
*   
*  Copyright (c) 2002 Dragos Manolescu (dam@micro-workflow.com)
*
*  See the LICENSE file for licensing information.
*/

package com.microworkflow.process;

import com.microworkflow.execution.ConditionalContinuation;
import com.microworkflow.execution.Continuation;

/**
* @author dam
*
* This activity node represents an if-then-else conditional; not both branches are
* required. The calling continuation replaces the missing branch.
*/
public class Conditional extends Activity {
  protected TestCondition test;
  protected Activity thenBranch;
  protected Activity elseBranch;
 
  public Conditional(TestCondition aClosure, Activity thenBranch, Activity elseBranch) {
    this.test=aClosure;
    this.thenBranch=thenBranch;
    this.elseBranch=elseBranch;
  }
 
  public Conditional(TestCondition aClosure, Activity thenBranch) {
    this(aClosure,thenBranch,null);
  }
 
  public Continuation continuationWith(Continuation continuation) {
    ConditionalContinuation k = continuation.makeConditionalContinuation(this);
    k.setTestCondition(test);
    k.resetState();
    return k;
  }
 
  public void setElseBranch(Activity elseBranch) {
    this.elseBranch = elseBranch;
  }
 
  public void setThenBranch(Activity thenBranch) {
    this.thenBranch = thenBranch;
  }

  public void computeStateFor(Continuation k) {
    Continuation next=k.getNextContinuation();
    ConditionalContinuation ck=(ConditionalContinuation)k;
    if (thenBranch != null) {
      ck.setThenContinuation(thenBranch.continuationWith(next));
    } else {
      ck.setThenContinuation(next);
    }
    if (elseBranch != null) {
      ck.setElseContinuation(elseBranch.continuationWith(next));
    } else {
      ck.setElseContinuation(next);
    }   
  }
}
TOP

Related Classes of com.microworkflow.process.Conditional

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.