KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > node > Merge


1 package org.jbpm.graph.node;
2
3 import java.util.*;
4
5 import org.jbpm.graph.def.*;
6 import org.jbpm.graph.exe.*;
7
8 /**
9  * TODO is the merge node usefull ?
10  * i don't think the merge node is usefull because every node has an
11  * implicit merge in front of it (= multiple transitions can arrive in
12  * the same node). maybe we should just leave this in for the sake
13  * of workflow patterns ?
14  */

15 public class Merge extends Node {
16   
17   private static final long serialVersionUID = 1L;
18   
19   private boolean isSynchronized = false;
20   
21   public Merge() {
22   }
23
24   public Merge(String JavaDoc name) {
25     super(name);
26   }
27
28   public void execute(ExecutionContext executionContext) {
29     Token token = executionContext.getToken();
30     Node mergeNode = token.getNode();
31     
32     // if this is a simple merge
33
if ( ! isSynchronized ) {
34       mergeNode.leave(executionContext);
35
36     // this is a synchronizing multi merge
37
} else {
38       
39       Collection concurrentTokens = token.getParent().getChildren().values();
40       boolean reactivate = true;
41       Iterator iter = concurrentTokens.iterator();
42       while ( (iter.hasNext())
43               && (reactivate) ) {
44         Token concurrentToken = (Token) iter.next();
45         if ( concurrentToken.getNode() != mergeNode ) {
46           reactivate = false;
47         }
48       }
49       
50       if ( reactivate ) {
51         iter = concurrentTokens.iterator();
52         while (iter.hasNext()) {
53           Token concurrentToken = (Token) iter.next();
54           mergeNode.leave(new ExecutionContext(concurrentToken));
55         }
56       }
57     }
58   }
59   
60   public boolean isSynchronized() {
61     return isSynchronized;
62   }
63   public void setSynchronized(boolean isSynchronized) {
64     this.isSynchronized = isSynchronized;
65   }
66 }
67
Popular Tags