预订演示

请注意 : 本帮助页面不适用于最新版本的Enterprise Architect. 最新的帮助文档在这里.

前页 后页

Java Code Generated From Legacy状态机模板

UML State-machine Diagram in Sparx Systems Enterprise Architect.

私有枚举状态类型: int

{

ProcessOrder_Delivered,

ProcessOrder_Packed,

ProcessOrder_Closed,

ProcessOrder_Dispatched,

ProcessOrder_New,

ST_NOSTATE

}

私有枚举TransitionType: int

{

ProcessOrder_Delivered_to_ProcessOrder_Closed,

TT_NOTRANSITION

}

私有枚举 CommandType

{

做,

入口,

出口

}

私有StateType currState;

私有状态类型下一个状态;

私有TransitionType currTransition;

私有布尔超越;

私有StateType ProcessOrder_history;

private void processOrder_Delivered(CommandType 命令)

{

开关(命令)

{

案例做:

{

// 做行为..

设置状态(已交付);

//状态的转换

如果((状态==已交付))

{

nextState = StateType.ProcessOrder_Closed;

currTransition = TransitionType.ProcessOrder_Delivered_to_ProcessOrder_Closed;

}

休息;

}

默认:

{

休息;

}

}

}

private void processOrder_Packed(CommandType 命令)

{

开关(命令)

{

案例做:

{

// 做行为..

设置状态(打包);

//状态的转换

nextState = StateType.ProcessOrder_Dispatched;

休息;

}

默认:

{

休息;

}

}

}

private void processOrder_Closed(CommandType 命令)

{

开关(命令)

{

案例做:

{

// 做行为..

//状态的转换

休息;

}

默认:

{

休息;

}

}

}

private void processOrder_Dispatched(CommandType 命令)

{

开关(命令)

{

案例做:

{

// 做行为..

设置状态(已调度);

//状态的转换

nextState = StateType.ProcessOrder_Delivered;

休息;

}

默认:

{

休息;

}

}

}

私人void processOrder_New(CommandType 命令)

{

开关(命令)

{

案例做:

{

// 做行为..

设置状态(新);

//状态的转换

nextState = StateType.ProcessOrder_Packed;

休息;

}

默认:

{

休息;

}

}

}

私人void StatesProc(StateType currState,CommandType命令)

{

开关(当前状态)

{

案例 ProcessOrder_Delivered:

{

processOrder_Delivered(命令);

休息;

}

案例 ProcessOrder_Packed:

{

processOrder_Packed(命令);

休息;

}

案例 ProcessOrder_Closed:

{

processOrder_Closed(命令);

休息;

}

案例 ProcessOrder_Dispatched:

{

processOrder_Dispatched(命令);

休息;

}

案例 ProcessOrder_New:

{

processOrder_New(命令);

休息;

}

默认:

休息;

}

}

私人void TransitionsProc(TransitionType过渡)

{

开关(过渡)

{

案例 ProcessOrder_Delivered_to_ProcessOrder_Closed:

{

设置状态(关闭);

休息;

}

默认:

休息;

}

}

私人void初始化状态机()

{

currState = StateType.ProcessOrder_New;

nextState = StateType.ST_NOSTATE;

currTransition = TransitionType.TT_NOTRANSITION;

}

私人void运行状态机()

{

而(真)

{

if (currState == StateType.ST_NOSTATE)

{

休息;

}

currTransition = TransitionType.TT_NOTRANSITION;

StatesProc(currState, CommandType.Do);

// 然后检查在 do 行为之后是否分配了任何有效的转换

if (nextState == StateType.ST_NOSTATE)

{

休息;

}

if (currTransition != TransitionType.TT_NOTRANSITION)

{

TransitionsProc(currTransition);

}

if (currState != nextState)

{

StatesProc(currState, CommandType.Exit);

StatesProc(nextState, CommandType.Entry);

当前状态 = 下一个状态;

}

}

}