KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > exe > state > CompensatingState


1 package org.jbpm.bpel.exe.state;
2
3 import org.jbpm.bpel.def.Scope;
4 import org.jbpm.bpel.def.ScopeHandler;
5 import org.jbpm.bpel.exe.ScopeInstance;
6
7 /**
8  * @author Juan Cantú
9  * @version $Revision: 1.2 $ $Date: 2005/06/16 19:15:36 $
10  */

11 public class CompensatingState extends HandlingState {
12
13   private static final long serialVersionUID = 1L;
14
15   public static final CompensatingState COMPENSATING_IMPLICITLY = new CompensatingState("compensatingImplicitly", 10) {
16
17     private static final long serialVersionUID = 1L;
18
19     public void faulted(ScopeInstance scope) {
20       enterFaulted(scope);
21     }
22
23     public void childrenCompensated(ScopeInstance scope) {
24       enterCompensated(scope);
25     }
26   };
27
28   public static final CompensatingState COMPENSATING_EXPLICITLY = new CompensatingState("compensatingExplicitly", 11) {
29
30     private static final long serialVersionUID = 1L;
31
32     public void completed(ScopeInstance scope) {
33       enterCompensated(scope);
34     }
35
36     public void faulted(ScopeInstance scope) {
37       scope.setState(TERMINATING_CHILDREN_AT_HANDLER);
38       scope.cancelChildren();
39     }
40   };
41
42   public static final CompensatingState TERMINATING_CHILDREN_AT_HANDLER = new CompensatingState("compensatingTerminatingHandler", 12) {
43
44     private static final long serialVersionUID = 1L;
45
46     public void childrenTerminated(ScopeInstance scope) {
47       enterFaulted(scope);
48     }
49   };
50
51   protected CompensatingState(String JavaDoc name, int code) {
52   super(name, code);
53 }
54
55
56   public static void enterCompensating(ScopeInstance scope) {
57     ScopeHandler handler = scope.getDefinition().getHandler(Scope.COMPENSATION);
58
59     if (handler != null) {
60       scope.setState(COMPENSATING_EXPLICITLY);
61       COMPENSATING_EXPLICITLY.handleExplicitly(scope, handler);
62     } else {
63       scope.setState(COMPENSATING_IMPLICITLY);
64       COMPENSATING_IMPLICITLY.handleImplicitly(scope);
65     }
66   }
67
68   protected void enterCompensated(ScopeInstance scope) {
69     scope.setState(EndedState.COMPENSATED);
70     ScopeInstance parent = scope.getParent();
71     
72     if(parent != null) {
73       parent.childCompensated(scope);
74     }
75     
76   }
77 }
78
Popular Tags