1 package org.jbpm.bpel.exe.state; 2 3 import org.jbpm.graph.exe.Token; 4 5 import org.jbpm.bpel.def.Scope; 6 import org.jbpm.bpel.exe.InstanceIterator; 7 import org.jbpm.bpel.exe.ScopeInstance; 8 import org.jbpm.bpel.exe.ScopeInstance.ScopeIterator; 9 10 14 public abstract class ActiveState extends ScopeState { 15 16 public static final ActiveState NORMAL_PROCESSING = new ActiveState("normalProcessing", 0) { 17 18 private static final long serialVersionUID = 1L; 19 20 public void completed(ScopeInstance scope) { 21 Token eventToken = scope.getToken().getChild(Scope.EVENTS_TOKEN); 23 if(eventToken != null) { 24 scope.getDefinition().disableEvents(eventToken); 25 } 26 27 if ( !hasPendingEvents(scope) ) { 28 enterCompleted(scope); 30 } else { 31 scope.setState(EVENTS_PENDING); 33 } 34 } 35 }; 36 37 public static final ActiveState EVENTS_PENDING = new ActiveState("eventsPending", 1) { 38 39 private static final long serialVersionUID = 1L; 40 41 public void completed(ScopeInstance scope) { 42 enterCompleted(scope); 45 } 46 }; 47 48 52 protected ActiveState(String name, int code) { 53 super(name, code); 54 } 55 56 public void terminate(ScopeInstance scope) { 57 TerminatingState.enterTerminating(scope); 58 } 59 60 public void faulted(ScopeInstance scope) { 61 FaultingState.enterFaulting(scope); 62 } 63 64 protected void enterCompleted(ScopeInstance scope) { 65 scope.setState(EndedState.COMPLETED); 67 scope.notifyCompletion(); 68 } 69 70 public boolean hasPendingEvents(ScopeInstance scope) { 71 Token eventToken = scope.getToken().getChild(Scope.EVENTS_TOKEN); 72 if(eventToken == null) return false; 73 74 InstanceIterator it = new ScopeIterator(eventToken); 75 76 while (it.hasNext()) { 77 ScopeInstance child = (ScopeInstance) it.next(); 78 if(!child.getState().equals(EndedState.COMPLETED)) return true; 79 } 80 81 return false; 82 } 83 } 84 | Popular Tags |