1 package org.jbpm.jpdl.exe; 2 3 import java.io.*; 4 import java.util.*; 5 6 import org.jbpm.context.exe.*; 7 import org.jbpm.graph.def.*; 8 import org.jbpm.graph.exe.*; 9 10 public class MilestoneInstance implements Serializable { 11 12 private static final long serialVersionUID = 1L; 13 14 protected long id = 0; 15 protected String name = null; 16 protected boolean reached = false; 17 protected Token token = null; 18 protected Collection listeners = null; 19 20 public MilestoneInstance() { 21 } 22 23 public MilestoneInstance(String name) { 24 this.name = name; 25 } 26 27 public static MilestoneInstance getMilestoneInstance(String milestoneName, Token token) { 28 ContextInstance ci = (ContextInstance) token.getProcessInstance().getInstance(ContextInstance.class); 29 MilestoneInstance mi = (MilestoneInstance) ci.getVariable( milestoneName, token ); 30 if (mi == null) { 31 mi = new MilestoneInstance(milestoneName); 32 mi.setToken(token); 33 ci.setVariable( milestoneName, mi ); 34 } 35 return mi; 36 } 37 38 public void addListener(Token token) { 39 if ( listeners == null ) listeners = new HashSet(); 40 listeners.add( token ); 41 } 42 43 public void notifyListeners() { 44 if ( listeners != null ) { 45 Iterator iter = listeners.iterator(); 47 while (iter.hasNext()) { 48 Token token = (Token) iter.next(); 49 Node node = token.getNode(); 51 ExecutionContext executionContext = new ExecutionContext(token); 52 node.leave(executionContext); 53 } 54 } 55 } 56 57 public long getId() { 58 return id; 59 } 60 public void setId(long id) { 61 this.id = id; 62 } 63 public Collection getListeners() { 64 return listeners; 65 } 66 public void setListeners(Collection listeners) { 67 this.listeners = listeners; 68 } 69 public String getName() { 70 return name; 71 } 72 public void setName(String name) { 73 this.name = name; 74 } 75 public boolean isReached() { 76 return reached; 77 } 78 public void setReached(boolean reached) { 79 this.reached = reached; 80 } 81 public Token getToken() { 82 return token; 83 } 84 public void setToken(Token token) { 85 this.token = token; 86 } 87 } 88 | Popular Tags |