KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 public abstract class ScopeState implements Serializable JavaDoc {
12   
13   private static final int STATE_COUNT = 19;
14   private static final ScopeState[] states = new ScopeState[STATE_COUNT];
15   
16   private String JavaDoc name;
17   private int code;
18   
19   /**
20    * Constructs a scope state identified by the given name.
21    * @param name
22    */

23   protected ScopeState(String JavaDoc name, int code) {
24     if ((code < 0) && (code <= STATE_COUNT)) throw new AssertionError JavaDoc("code out of bounds");
25     if(states[code] != null) throw new AssertionError JavaDoc("code already in use");
26     this.code = code;
27     this.name = name;
28     states[code] = this;
29   }
30   
31   /**
32    * Requests cancelation of the scope instance argument.
33    * @param scope
34    */

35   public void terminate(ScopeInstance scope) {
36     throw newStateException("cancel");
37   }
38
39   /**
40    * Requests compensation of the scope instance argument.
41    * @param scope
42    */

43   public void compensate(ScopeInstance scope) {
44     throw newStateException("compensate");
45   }
46
47   /**
48    * Notifies the completion of a scope instance inside an execution flow
49    * @param scope
50    */

51   public void completed(ScopeInstance scope) {
52     throw newStateException("completed");
53   }
54
55   /**
56    * Notifies that a fault occured during the execution of a scope instance
57    * @param scope
58    */

59   public void faulted(ScopeInstance scope) {
60     throw newStateException("faulted");
61   }
62
63   /**
64    * Notifies that the children of the given scope instance were terminated
65    * @param scope
66    */

67   public void childrenTerminated(ScopeInstance scope) {
68     throw newStateException("childTerminated");
69   }
70   
71   /**
72    * Creates an exception to signal that the given transition is illegal from
73    * the current state.
74    * @param transition the name of the illegal transition
75    * @return a newly created exception
76    */

77   protected IllegalStateException JavaDoc newStateException(String JavaDoc transition) {
78     return new IllegalStateException JavaDoc(toString() + " - transition=" + transition);
79   }
80   
81   /**{@inheritDoc}*/
82   public String JavaDoc toString() {
83         return "[" + name + "]";
84   }
85
86   /**
87    * Returns an integer representation of this state.
88    * @return an integer that identifies the state
89    */

90   public int toInt() {
91     return code;
92   }
93
94   public static Object JavaDoc fromInt(int code) {
95     return states[code];
96   }
97 }
98
Popular Tags