KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > Link


1 package org.jbpm.bpel.def;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.jbpm.graph.exe.ExecutionContext;
8 import org.jbpm.graph.exe.Token;
9
10 import org.jbpm.bpel.data.def.Snippet;
11 import org.jbpm.bpel.exe.LinkInstance;
12 import org.jbpm.bpel.xml.util.DatatypeUtil;
13
14 /**
15  * Links enable the expression of synchronization dependencies between activities that are
16  * nested directly or indirectly within a flow activity.
17  * @see "WS-BPEL 2.0 §12.5.1"
18  * @author Juan Cantú
19  * @version $Revision: 1.6 $ $Date: 2005/06/23 02:22:46 $
20  */

21 public class Link implements Serializable JavaDoc {
22   private static final long serialVersionUID = 1L;
23   protected long id = -1;
24   private String JavaDoc name;
25   private Snippet transitionCondition;
26   protected Activity target = null;
27   protected Activity source = null;
28   
29   public Link() {
30   }
31   
32   public Link(String JavaDoc name) {
33     setName(name);
34   }
35   
36   public void execute(ExecutionContext executionContext) {
37     Token token = executionContext.getToken();
38     LinkInstance linkInstance = LinkInstance.get(token, getName());
39
40     if(transitionCondition == null) {
41       linkInstance.setReached(Boolean.TRUE);
42     }
43     else {
44       try {
45         linkInstance.setReached(DatatypeUtil.toBoolean(transitionCondition.getScript().evaluate(token)));
46       }
47       catch(RuntimeException JavaDoc e) {
48         linkInstance.setReached(Boolean.FALSE);
49         //throw scripting exception
50
}
51     }
52     
53     //Notify the link status resolution to tokens waiting at the target activity
54
notifyTokensAtDestination(linkInstance.getToken());
55   }
56   
57   public void setNegativeStatus(Token token) {
58     LinkInstance linkInstance = LinkInstance.get(token, getName());
59     linkInstance.setReached(Boolean.FALSE);
60     //Notify the link status resolution to tokens waiting at the target activity
61
notifyTokensAtDestination(linkInstance.getToken());
62   }
63   
64   public Snippet getTransitionCondition() {
65     return transitionCondition;
66   }
67   
68   public void setTransitionCondition(Snippet transitionCondition) {
69     this.transitionCondition = transitionCondition;
70   }
71   
72   protected void notifyTokensAtDestination(Token token) {
73     List JavaDoc tokens = token.getChildrenAtNode(target);
74     
75     for(Iterator JavaDoc it = tokens.iterator(); it.hasNext();) {
76       Token aToken = (Token) it.next();
77       if(target.areLinksReached(aToken))
78         target.execute(new ExecutionContext(aToken));
79     }
80   }
81   
82   public String JavaDoc getName() {
83     return name;
84   }
85   public void setName(String JavaDoc name) {
86     this.name = name;
87   }
88   public Activity getTarget() {
89     return target;
90   }
91   public Activity getSource() {
92     return source;
93   }
94 }
Popular Tags