1 package org.jbpm.bpel.def; 2 3 import java.io.Serializable ; 4 import java.util.Iterator ; 5 import java.util.List ; 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 21 public class Link implements Serializable { 22 private static final long serialVersionUID = 1L; 23 protected long id = -1; 24 private String 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 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 e) { 48 linkInstance.setReached(Boolean.FALSE); 49 } 51 } 52 53 notifyTokensAtDestination(linkInstance.getToken()); 55 } 56 57 public void setNegativeStatus(Token token) { 58 LinkInstance linkInstance = LinkInstance.get(token, getName()); 59 linkInstance.setReached(Boolean.FALSE); 60 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 tokens = token.getChildrenAtNode(target); 74 75 for(Iterator 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 getName() { 83 return name; 84 } 85 public void setName(String 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 |