KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.exe.state;
2
3 import org.jbpm.graph.exe.Token;
4
5 import org.jbpm.bpel.data.def.VariableDefinition;
6 import org.jbpm.bpel.data.exe.VariableInstance;
7 import org.jbpm.bpel.def.FaultHandler;
8 import org.jbpm.bpel.def.ScopeHandler;
9 import org.jbpm.bpel.exe.Fault;
10 import org.jbpm.bpel.exe.ScopeInstance;
11
12 /**
13  * @author Juan Cantú
14  * @version $Revision: 1.5 $ $Date: 2005/06/17 01:31:31 $
15  */

16 public class FaultingState extends HandlingState {
17
18   private static final long serialVersionUID = 1L;
19
20   public static final FaultingState TERMINATING_CHILDREN = new FaultingState("faultingTerminatingChildren", 2) {
21     
22     private static final long serialVersionUID = 1L;
23
24     public void childrenTerminated(ScopeInstance scope) {
25       Fault fault = scope.getFault();
26
27       /*
28       QName messageType = null;
29       try {
30         messageType = fault.getData().getDefinition().getType();
31       } catch (Exception npe) {
32         messageType = null;
33       }*/

34
35       ScopeHandler handler = scope.getDefinition().getFaultHandler(fault);
36
37       if (handler != null) {
38         scope.setState(FAULTING_EXPLICITLY);
39         handleExplicitly(scope, handler);
40       } else {
41         /*TODO If the fault occurs in (or is rethrown to) the global process scope, and there is no matching
42          *fault handler for the fault at the global level, the process terminates abnormally, as though
43          *an exit activity had been performed.*/

44         
45         scope.setState(FAULTING_IMPLICITLY);
46         handleImplicitly(scope);
47       }
48     }
49   };
50
51   public static final FaultingState FAULTING_IMPLICITLY = new FaultingState("faultingImplicitly", 3) {
52
53     private static final long serialVersionUID = 1L;
54
55     public void childrenCompensated(ScopeInstance scope) {
56       enterFaulted(scope);
57     }
58
59     public void faulted(ScopeInstance scope) {
60       enterFaulted(scope);
61     }
62   };
63
64   public static final FaultingState FAULTING_EXPLICITLY = new FaultingState("faultingExplicitly", 4) {
65
66     private static final long serialVersionUID = 1L;
67
68     public void completed(ScopeInstance scope) {
69       scope.setState(EndedState.COMPLETED_ABNORMALLY);
70       ScopeInstance parent = scope.getParent();
71       
72       if(parent != null) {
73         Token parentToken = scope.getToken().getParent();
74         //((Scope)parentToken.getNode()).completed(parentToken);
75
parentToken.signal();
76       }
77     }
78
79     public void faulted(ScopeInstance scope) {
80       scope.setState(TERMINATING_CHILDREN_AT_HANDLER);
81       scope.cancelChildren();
82     }
83   };
84
85   public static final FaultingState TERMINATING_CHILDREN_AT_HANDLER = new FaultingState("faultingTerminatingHandler", 5) {
86
87     private static final long serialVersionUID = 1L;
88
89     public void childrenTerminated(ScopeInstance scope) {
90       enterFaulted(scope);
91     }
92   };
93
94   protected FaultingState(String JavaDoc name, int code) {
95     super(name, code);
96   }
97
98   public void terminate(ScopeInstance scope) {
99     //nothing is done, see enterFaulting.
100
}
101
102   protected void handleExplicitly(ScopeInstance scope, ScopeHandler handler) {
103     // initialize the fault variable before executing the fault handler
104
if (handler instanceof FaultHandler) {
105       VariableDefinition variable = ((FaultHandler) handler).getFaultVariable();
106       if (variable != null) {
107         VariableInstance instance = variable.createInstance(scope.getToken());
108         instance.setValue(scope.getFault().getData());
109       }
110     }
111     super.handleExplicitly(scope, handler);
112   }
113
114   public static void enterFaulting(ScopeInstance scope) {
115     scope.setState(FaultingState.TERMINATING_CHILDREN);
116     scope.cancelChildren();
117   }
118 }
Popular Tags