KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.graph.node;
2 import org.jbpm.graph.def.*;
3 import org.jbpm.graph.exe.ExecutionContext;
4 import org.jbpm.graph.exe.Token;
5 import org.jbpm.jpdl.exe.*;
6
7 public class MilestoneNode extends Node {
8   
9   private static final long serialVersionUID = 1L;
10   
11   private String JavaDoc tokenPath = ".";
12   
13   public MilestoneNode() {
14   }
15
16   public MilestoneNode(String JavaDoc name) {
17     super(name);
18   }
19
20   public void execute(ExecutionContext executionContext) {
21     Token token = executionContext.getToken();
22     // get the token on which the milestone should be verified
23
Token milestoneToken = token.findToken( tokenPath );
24     if ( isMilestoneReached( name, milestoneToken ) ) {
25       
26       // continue to pass the token over the default transition
27
token.getNode().leave(executionContext);
28
29     } else {
30       addMilestoneListener(name,milestoneToken);
31     }
32   }
33   
34   public boolean isMilestoneReached(String JavaDoc milestoneName, Token token) {
35     MilestoneInstance mi = MilestoneInstance.getMilestoneInstance(milestoneName, token);
36     return (mi != null ? mi.isReached() : false);
37   }
38
39   public void addMilestoneListener(String JavaDoc milestoneName, Token token) {
40     MilestoneInstance mi = MilestoneInstance.getMilestoneInstance(milestoneName, token);
41     mi.addListener(token);
42   }
43
44
45   public String JavaDoc getTokenPath() {
46     return tokenPath;
47   }
48   public void setTokenPath(String JavaDoc relativeTokenPath) {
49     this.tokenPath = relativeTokenPath;
50   }
51 }
52
Popular Tags