<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    MultiChoiceForkAH
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/admin">Administrator Administrator</a> in <i>jBPM</i> - <a href="http://community.jboss.org/docs/DOC-11442">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>This Multi Choice fork will create an appropriate thread of execution (token) for each dynamically specified item.&#160; For instance, in the case of a customer order containing one phone service product, one internet service product, and two web hosting products:&#160; one token will be created and sent down the 'phone' transition, one token will be created and sent down the 'internet' transition, and two separate tokens can be each created and sent separately down the 'web' transition.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Optionally, this fork can be configured to simply create a token for each combination of 'item' and 'transition'.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>A Collection of Objects driving the choices must be stored in a process instance variable, and each object must share a common accessor method for determining its 'type' (or just use a String).&#160; Just about everything is configurable--see the comments in the sample process definition and attached code.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;process-definition name='ForEachFork Test'&gt; 
&#160;&#160;&#160; &lt;start-state name='START' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;event type='node-leave' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;script&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;expression&gt;List list = new ArrayList(); list.add("item1"); list.add("item2"); list.add("item3");&lt;/expression&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;variable name='myList' access='write' mapped-name='list' &gt;&lt;/variable&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='done' to='_TEST_FORK'&gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/start-state&gt;

&#160;&#160;&#160; &lt;!-- Attempts to provide a robust implementation of workflow pattern 6, multi-choice. --&gt;
&#160;&#160;&#160; &lt;state name='_TEST_FORK' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;action class='org.bminer.jbpm.pd.ah.ForEachForkAH' config-type='bean'&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- process instance variable containing a Collection of items for which we will
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; create sub tokens. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;inputCollectionVar&gt;myList&lt;/inputCollectionVar&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- If the collection is not of Strings, this property may be specified and&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; should be available via a 'get', 'is', or 'has' accessor method on each item in 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; the collection.&#160; Alternatively, an EL expression may be supplied where
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'tempForEachForkAHInputItem' is the Input Item being evaluated against. 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; The returned value must be a String or String.valueOf() compatible value. 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; The value will be used to identify the item and to match
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; against available transition names when matchItemWithTrans = 'true'.
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; If not provided for non-String inputCollections, toString() will be
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; called on those items to provide a String value. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;inputItemProperty&gt;&lt;/inputItemProperty&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- The variable name in the branch token which will hold the Input Item from the
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; inputCollectionVar that caused the creation of the branch token.&#160; If no name is
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; given, the Input Item will not be stored separately under its associated
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; branch token. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;inputItemMappedName&gt;inputItem&lt;/inputItemMappedName&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- 'true' will create a token for each inputCollection item that corresponds to a
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; non-reserved transition name, and then signal that token down the matching
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; transition. ('reserved' transition names include those configured under
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'noMatchTrans' and 'noListTrans' as well as any transition beginning with 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; '_sys_'.)&#160; 'false' will create and signal a token for every combination of 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; inputCollection item and transition. Required. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;matchItemWithTrans&gt;true&lt;/matchItemWithTrans&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- 'true' reduces the inputCollection to a Set prior to matching the collection
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; to the configured transitions. Default is 'false' --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;matchUnique&gt;true&lt;/matchUnique&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- When using matchItemWithTrans = 'true', this is the default transition to take for 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; any inputCollection item that has no matching transition name, 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; otherwise no token will be generated for that item --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;noMatchTrans&gt;noMatch&lt;/noMatchTrans&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- 'true' if the specified 'noMatchTrans' should be taken only once regardless of 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; how many un-matched items exist, or 'false' if the 'noMatchTrans' should be 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; taken for each item that has no matching transition. Default is 'true'. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;noMatchDoTransOnce&gt;true&lt;/noMatchDoTransOnce&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- If any item fails to have a matching transition, set this to 'true' if other matched 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; transitions should be taken, 'false' if only 'notMatchTrans' transitions should be taken. 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; In other words, if there is any failure to match, nothing but the failure(s) will be 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; processed if this is set to 'false'.&#160; Default is 'false'. --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;noMatchDoMatched&gt;false&lt;/noMatchDoMatched&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- transition to take if there is nothing in the inputCollection, otherwise
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; nothing will be done and we'll halt execution in this node.
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Since we don't fork in this scenario, any subsequent nodes should
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lead the root token past the join that corresponds to this fork --&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;noListTrans&gt;noList&lt;/noListTrans&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/action&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='item1' to='ITEM_1' &gt;&lt;/transition&gt;
&#160;&#160;&#160;&#160;&#160;&lt;transition name='item2' to='ITEM_2' &gt;&lt;/transition&gt;
&#160;&#160;&#160;&#160;&#160;&lt;transition name='item3' to='ITEM_3' &gt;&lt;/transition&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='noMatch' to='UNSUPPORTED_ITEM' &gt;&lt;/transition&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='noList' to='NO_ITEMS' &gt;&lt;/transition&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='_sys_redoNode' to='_TEST_FORK' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;

&#160;&#160;&#160; &lt;state name='ITEM_1' &gt;
&#160;&#160;&#160;&#160;&#160;&lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;script&gt;System.out.println("Processing item 1!");&lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='done' to='JOIN' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;

&#160;&#160;&#160; &lt;state name='ITEM_2' &gt;
&#160;&#160;&#160;&#160;&#160;&lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;script&gt;System.out.println("Processing item 2!");&lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='done' to='JOIN' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;

&#160;&#160;&#160; &lt;state name='ITEM_3' &gt;
&#160;&#160;&#160;&#160;&#160;&lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;script&gt;System.out.println("Processing item 3!");&lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='done' to='JOIN' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;
&#160;&#160;&#160; 
&#160;&#160;&#160; &lt;state name='UNSUPPORTED_ITEM' &gt;
&#160;&#160;&#160;&#160;&#160;&lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;script&gt;System.out.println("Received an unsupported item!");&lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='done' to='JOIN' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;
&#160;&#160;&#160; 
&#160;&#160;&#160; &lt;state name='NO_ITEMS' &gt;
&#160;&#160;&#160;&#160;&#160;&lt;event type='node-enter' &gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;script&gt;System.out.println("There was no collection, so I didn't fork!");&lt;/script&gt;
&#160;&#160;&#160;&#160;&#160;&lt;/event&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;transition name='nothingToDo' to='END' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/state&gt;

&#160;&#160;&#160; &lt;join name='JOIN'&gt;
&#160;&#160;&#160;&#160;&#160;&lt;transition name='done' to='END' &gt;&lt;/transition&gt;
&#160;&#160;&#160; &lt;/join&gt;

&#160;&#160;&#160; &lt;end-state name='END' &gt;&lt;/end-state&gt;
&#160;&#160;&#160; 
&lt;/process-definition&gt;</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Hope this is useful. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>(updated to provide a more recent example that fixes two mentioned bugs and includes the "inputMappedName" configuration parameter.)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Referenced by:</strong></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-11442">going to Community</a></p>

        <p style="margin: 0;">Create a new document in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>