1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
package com.c2kernel.lifecycle.instance.stateMachine;
import java.io.Serializable;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.utils.Logger;
/**
* @version $Revision: 1.30 $ $Date: 2004/06/04 09:39:19 $
* @author $Author: sgaspard $
*/
/** this class represents the link between 2 successive activities */
public class StateMachine implements Serializable
{
public int state = 0;
private Activity activity;
public static final String SKIPPABLE = "Skippable";
public static final String REPEATABLE = "Repeatable";
public static final String IGNORABLE = "Ignorable";
public static final String AUTOSTART = "Autostart";
/**
* Method StateMachine.
* @param act
*/
public StateMachine(Activity act)
{
activity = act;
}
/** row : States from (WAITING,RESERVED,STARTED,SUSPENDED,FINISHED,RWAITING,RRESERVED,RSTARTED,RSUSPENDED)
* collumn : transition (RESERVE,START,SKIP,DONE,COMPLETE,SUSPEND,REASIGN,RESUME,REPEAT,IGNORE,PROCEED)
* cell : State that is reached (-1 if transition not allowed)
*/
private int[][] getCurrentMachine()
{
int [][] returnArray =
{ /*RESERVE, START, SKIP, DONE,COMPLETE,SUSPEND,REASIGN,RESUME, REPEAT, IGNORE, PROCEED*/
/*0 WAITING*/ { 1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*0 WAITING*/
/*1 RESERVED*/ { -1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, 0, -1},/*1 RESERVED*/
/*2 STARTED*/ { -1, -1, -1, -1, 4, 3, -1, -1, -1,getIgnorable()?0:-1, -1},/*2 STARTED*/
/*3 SUSPENDED*/ { -1, -1, -1, -1, -1, -1, 2, 2, -1,getIgnorable()?0:-1, -1},/*3 SUSPENDED*/
/*4 FINISHED*/ { -1, -1, -1, -1, -1, -1, -1, -1,getRepeatable()?!getAutoStart()?5:7:-1, -1,getActive()?4:-1},/*4 FINISHED*/
/*5 RWAITING*/ { 6,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*5 RWAITING*/
/*6 RRESERVED*/ { -1,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*6 RRESERVED*/
/*7 RSTARTED*/ { -1, -1, -1, -1, 4, 8, -1, -1, -1,getIgnorable()?5:-1, -1},/*7 RSTARTED*/
/*8 RSUSPENDED*/ { -1, -1, -1, -1, -1, -1, 8, 7, -1, -1, -1} /*8 RSUSPENDED*/
};
return returnArray;
}
/**
* @see java.lang.Object#Object()
*/
public StateMachine()
{
}
/**
* Method getCurrentState.
* @return String
*/
public int getCurrentState()
{
return state;
}
/**
* Method possibleTransition.
* @return String[]
*/
public int[] possibleTransition()
{
int[] trans = new int[9];
int cmpt = 0;
for (int i=0; i< getCurrentMachine()[state].length;i++)
if (getCurrentMachine()[state][i]!=-1) trans[cmpt++]=i;
int [] result = new int[cmpt];
for (int i=0;i<cmpt;i++) result[i] = trans[i];
return result;
}
/**
* Method traverse.
* @param transition
* @return boolean
*/
public boolean traverse(int transition)
{
int newState = getCurrentMachine()[state][transition];
if (newState > -1) {
state=newState;
return true;
}
Logger.msg("StateMachine.traverse() - Illegal transition "+Transitions.getTransitionName(transition)+" from "+States.getStateName(state));
return false;
}
public int simulate(int transition)
{
return getCurrentMachine()[state][transition];
}
/**
* Returns the ignorable.
* @return boolean
*/
public boolean getIgnorable()
{
return ((Boolean)activity.getProperties().get(IGNORABLE)).booleanValue();
}
/**
* Returns the repeatable.
* @return boolean
*/
public boolean getRepeatable()
{
return ((Boolean)activity.getProperties().get(REPEATABLE)).booleanValue();
}
/**
* Returns the skippable.
* @return boolean
*/
public boolean getSkippable()
{
return ((Boolean)activity.getProperties().get(SKIPPABLE)).booleanValue();
}
public boolean getAutoStart()
{
return ((Boolean)activity.getProperties().get(AUTOSTART)).booleanValue();
}
public boolean getActive()
{
return activity.getActive();
}
}
|