Version 9

    OK, this is a custom fork handler. In tyhis case I am hardcoding two attendees who have to respond to a meeting invite. However, you should be able to extrapolate that to generate child tasks based on an array which is arbitrary in length. In this particular case, I am passing in the attendees from a form with two fields.

     

     

    -


     
    package org.jbpm.delegation.fork; 
     
    import java.util.*; 
    import org.jbpm.*; 
    import org.jbpm.delegation.*; 
    import org.jbpm.model.definition.*; 
    import org.jbpm.model.definition.impl.*; 
    import org.jbpm.model.execution.impl.*; 
     
    /** 
    * @author marc_mulzer 
    * 
    */ 
    public class MyForkHandler implements ForkHandler {
     
       public void fork(ForkContext forkContext) throws ExecutionException{ 
     
          String attendee1 = (String) forkContext.getVariable("attendee1"); 
          String attendee2 = (String) forkContext.getVariable("attendee2"); 
     
          JoinImpl correspondingJoin = (JoinImpl) ((Fork)forkContext.getNode()).getCorrespondingJoin(); 
     
          Iterator iter = forkContext.getNode().getLeavingTransitions().iterator(); 
          while( iter.hasNext() ) { 
             Transition transition = (Transition) iter.next(); 
             TokenImpl childToken = (TokenImpl) forkContext.createToken( transition, attendee1 ); 
             childToken.setActorId(attendee1); 
             childToken.setName("You have a new invitation from name.goes.here "); 
             childToken.setReactivationJoin( correspondingJoin ); 
             TokenImpl childToken1 = (TokenImpl) forkContext.createToken( transition, attendee2 ); 
             childToken1.setActorId(attendee2); 
             childToken1.setName("You have a new invitation from name.goes.here "); 
             childToken1.setReactivationJoin( correspondingJoin ); 
     
          }  
       } 
    } 
    

    -


     

     

    The process files looks like this. Someone requests a meeting and all I am doing here is to wait for any response. (You can add additional forks to branch if you care what the response is) Notice the custom fork handler class in there and the arbitrary actor. At runtime, the code overrides the actor in the custom fork handler.

     

     
    <?xml version="1.0" encoding="UTF-8"?> 
     
    <!DOCTYPE process-definition PUBLIC 
    "-//jBpm/jBpm Mapping DTD 2.0 beta3//EN" 
    "http://jbpm.org/dtd/processdefinition-2.0-beta3.dtd";> 
     
    <process-definition name="scheduling process">  
     
       <!-- SWIMLANES --> 
       <swimlane name="requester" ></swimlane> 
     
       <swimlane name="boss"> 
          <delegation class="org.jbpm.delegation.assignment.ActorAssignmentHandler">cg</delegation> 
       </swimlane> 
     
       <swimlane name="approver list"> 
       </swimlane> 
     
       <!-- START-STATE --> 
       <start-state name="request a meeting" swimlane="requester"> 
          <transition to="fork"></transition> 
       </start-state> 
     
       <!-- NODES --> 
       <fork name="fork"> 
          <delegation class="org.jbpm.delegation.fork.MyForkHandler">ae</delegation> 
          <transition to="custom fork" ></transition> 
       </fork> 
     
       <state name="custom fork"> 
          <assignment swimlane="approver list" ></assignment> 
          <transition to="join" ></transition> 
       </state> 
     
       <join name="join"> 
          <transition to="notify" ></transition> 
       </join> 
     
       <state name="notify"> 
          <assignment swimlane="requester" ></assignment> 
          <transition to="done" ></transition> 
       </state> 
     
       <!-- END-STATE --> 
       <end-state name="done" ></end-state> 
     
    </process-definition> 
    

     

    -


     

    This is the associated form.xml. Here you can see how I am passing the variables. It could easily be an array or a complex type.

     
    <forms> 
     
       <form> 
          <file>forms/request.form</file> 
          <state-name>request a meeting</state-name> 
          <task-name>request a meeting</task-name> 
          <variable name="attendee1" ></variable> 
          <variable name="attendee2" ></variable> 
       </form> 
     
       <form> 
          <file>forms/approve.form</file> 
          <state-name>custom fork</state-name> 
          <task-name>meeting request received</task-name> 
          <variable name="attendee1" ></variable> 
          <variable name="attendee2" ></variable> 
       </form> 
     
       <form> 
          <file>forms/notify.form</file> 
          <state-name>notify</state-name> 
          <task-name>all responses received</task-name> 
          <variable name="attendee1" ></variable> 
          <variable name="attendee2" ></variable> 
       </form> 
    
    </forms> 
    

    -


     

     

    Hope this helps!

     

    Marc

     

    -


     

     

    Note: This is valid only for Jbpm 2.0.

     

    For a valid Jbpm 3.0 implementation, see ForEachForkActionHandler.

     

     

     

    By Rodrigo Porto