diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-07-16 17:26:58 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-09-16 12:39:07 +0200 |
| commit | beb0d5c91f228728092063a87827d5ecc4dd318f (patch) | |
| tree | 35bb09ffa8a5157a5c08943687886d88598377d9 | |
| parent | d1b306fc340224f476385a67f0c7501c22bad9d3 (diff) | |
More
7 files changed, 38 insertions, 235 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java deleted file mode 100644 index 76c8282..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java +++ /dev/null @@ -1,137 +0,0 @@ -
-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 OldStateMachine 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";
-
-
- /**
- * Method StateMachine.
- * @param act
- */
- public OldStateMachine(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,REASSIGN,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()?5:-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 OldStateMachine()
- {
- }
-
- /**
- * 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 getActive()
- {
- return activity.getActive();
- }
-
-}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java index 315ea3f..8c5924b 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java @@ -8,7 +8,7 @@ public class State implements Serializable { int code;
String name;
- boolean proceeds; // If true, this state deactivates the current activity and the lifecycle proceeds
+ boolean proceeds = false; // If true, this state deactivates the current activity and the lifecycle proceeds
ArrayList<Integer> possibleTransitionIds;
ArrayList<Transition> possibleTransitions;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java index fea9c3f..fe3e74b 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java @@ -5,11 +5,6 @@ import java.io.Serializable; import java.util.ArrayList;
import java.util.HashMap;
-/**
- * @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 String machineName;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java deleted file mode 100644 index b142e35..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.c2kernel.lifecycle.instance.stateMachine;
-
-
-/**
- * @author XSeb74
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class States
-{
- public final static int WAITING = 0;
- public final static int RESERVED = 1;
- public final static int STARTED = 2;
- public final static int SUSPENDED = 3;
- public final static int FINISHED = 4;
- public final static int RWAITING = 5;
- public final static int RRESERVED = 6;
- public final static int RSTARTED = 7;
- public final static int RSUSPENDED = 8;
-
- //everything less that this constant is NOT a repeating state
- public final static int REPEATSTATESTART = 5;
-
- public static final String[] states = { "Waiting", "Reserved", "Started", "Suspended", "Finished", "Waiting(R)", "Reserved(R)", "Started(R)", "Suspended(R)" };
-
- public static String getStateName(int state)
- {
- try
- {
- return states[state];
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return "Invalid State: " + state;
- }
- }
-}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java index 57f5818..85383f7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java @@ -10,26 +10,25 @@ public class Transition implements Serializable { int code;
String name;
- String originStateCode;
- String terminalStateCode;
+ int originStateCode;
+ int terminalStateCode;
State originState;
State terminalState;
String enabledProp; // Boolean property that permits this transition e.g. 'Skippable'
// activation properties
- boolean requiresActive; // Whether the activity must be active for this transition to be available
- boolean changesState; // If true, then performing this transition will change the state of the activity
- boolean newActiveState; // New activity state when changed
+ boolean requiresActive = true; // Whether the activity must be active for this transition to be available
+
+ // permissions
+ String roleOverride;
// schema properties
- String outcomeSchemaName, outcomeSchemaVersion; // Name & version of the schema of the data required for this transition
- String schemaNameProperty, schemaVersionProperty; // Activity property that gives the schema name & version
- boolean outcomeRequired; // If true, then the data must be supplied to perform the transition, otherwise it is optional
+ String outcomeSchemaName, outcomeSchemaVersion; // Name & version of the schema of the data required for this transition.
+ boolean outcomeRequired = true; // If true, then the data must be supplied to perform the transition, otherwise it is optional
// script properties
String scriptName, scriptVersion; // Name & version of the script to be run by the agent during this transition
- String scriptNameProperty, scriptVersionProperty; // Activity properties dictating the above.
public Transition() {
}
@@ -47,6 +46,14 @@ public class Transition implements Serializable { return allFound;
}
+ public int getOriginStateCode() {
+ return originStateCode;
+ }
+
+ public void setOriginStateCode(int originStateCode) {
+ this.originStateCode = originStateCode;
+ }
+
public int getCode() {
return code;
}
@@ -55,11 +62,11 @@ public class Transition implements Serializable { this.code = code;
}
- public String getTerminalStateCode() {
+ public int getTerminalStateCode() {
return terminalStateCode;
}
- public void setTerminalStateCode(String terminalStateCode) {
+ public void setTerminalStateCode(int terminalStateCode) {
this.terminalStateCode = terminalStateCode;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java deleted file mode 100644 index 4239baa..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.c2kernel.lifecycle.instance.stateMachine;
-
-import com.c2kernel.utils.Language;
-
-/**
- * @author XSeb74
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class Transitions
-{
- public final static int RESERVE = 0;
- public final static int START = 1;
- public final static int SKIP = 2;
- public final static int DONE = 3;
- public final static int COMPLETE = 4;
- public final static int SUSPEND = 5;
- public final static int REASSIGN = 6;
- public final static int RESUME = 7;
- public final static int REPEAT = 8;
- public final static int IGNORE = 9;
- public final static int PROCEED = 10;
- public final static int ACTIVATION = 11;
-
- private static String[] transitions = { "reserve", "start", "skip", "done", "complete", "suspend", "reassign", "resume", "repeat","ignore","proceed","activation" };
-
- public static String getTransitionName(int trans)
- {
- try
- {
- return Language.translate(transitions[trans]);
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return "Invalid Transition: " + trans;
- }
- }
-}
diff --git a/src/test/resources/TestStateMachine.xml b/src/test/resources/TestStateMachine.xml new file mode 100644 index 0000000..b9a557f --- /dev/null +++ b/src/test/resources/TestStateMachine.xml @@ -0,0 +1,19 @@ +<StateMachine initialState="0">
+ <State id="0" name="Waiting"/>
+ <State id="1" name="Started"/>
+ <State id="2" name="Finished" proceeds="true"/>
+ <State id="3" name="Suspended"/>
+
+ <Transition id="0" name="Start" origin="0" terminus="1"/>
+ <Transition id="1" name="Ignore" origin="1" terminus="0" enablingProperty="Ignorable"/>
+ <Transition id="2" name="Complete" origin="1" terminus="2">
+ <Outcome name="${SchemaType}" version="${SchemaVersion}"/>
+ <Script name="${ScriptName}" version="${ScriptVersion}"/>
+ </Transition>
+ <Transition id="2" name="Suspend" origin="1" terminus="3">
+ <Outcome name="Errors" version="0"/>
+ </Transition>
+ <Transition id="3" name="Retry" origin="3" terminus="1" roleOverride="Admin"/>
+</StateMachine>
+
+
|
