Next: 8.1.4 Default Textual Interface
Up: 8.1 Java Code Design
Previous: 8.1.2 Numbering
Contents
Index
The following constants are defined in each model class. They contain
information about the model structure.
- private static final int StateNum. The number of states
in the model, not including the states in its submodels.
- private static final String[] EventNames. The names of
the events to be handled by the model, not including the events
handled by its submodels. The indexes of those event names
represent their IDs. Those IDs start from 0.
- private static final String[] StateNames. The full paths
of the states in the model, not including the states in its
submodels. The indexes of those full paths represent the IDs of
the states. Those IDs start from 0.
- private static final int[] ParentTable. The table of
parent-children relations in the model. ParentTable[i]
contains the ID of the parent of state i. This is the
inverse of the function in the abstract syntax.
- private static final boolean[][] Hierarchy. The children
function of the model (the same as the function in the
abstract syntax). Hierarchy[i] is an array over all the
states. Hierarchy[i][j] is true if and only if state
j is a child of state i.
- private static final int[] HistoryStateTable. The
definition of history states in the model. Each element in this
array has the following meaning:
- private static final String[] LeafStateTable. The
definition of leaf states in the model, including importation
states if any. If state i is a leaf state, LeafStateTable[i] is equal to the full path of state i;
otherwise, LeafStateTable[i] is equal to null.
The following are the Java data structures to store the state of the
model at run-time:
- private State state. The current leaf state list of the
model. Class State is a linked list of state IDs.
- private StateMachine[] Submodels. The submodels of the
model. Submodels[i] is not null if and only if state
i is an importation state and the submodel in it has been
loaded. Once the submodel is loaded, it is never deleted even if
the model leaves the importation state. The history recorded in
the submodel object is the history of the importation state.
- private History[] history. The history of each state in
the model. history[i] is not null if and only if a
history is recorded for state i. Class History is an
internal structure that records a single history. Its value is
changed as the model enters the state again and leaves it from
another substate.
As all of the attributes of a model class are private members, the
users can only access them by means of public methods. The following
list includes some of the important methods:
- public modelname(). Constructor of the model
class. (modelname is the name of the model.) The required
data structures are initialized. However, the model is not
initialized. Its current state is illegal.
- public void initModel(). Initializes the model. This
means to place the model in its default state(s). The initializer
of the model is executed.
- public boolean isInState(String s) and public
boolean isInState(int s). These two functions check whether the
model is in a certain state. The state can be specified with its
full path or with its integer ID. The second method is more
efficient since it does not require string comparison. The method
with a string parameter is kept only for interaction with the
model users, who do not know the internal state IDs.
- public boolean handleEvent(String se). The handler of
any event. The event is given as a string, and this function
automatically converts the string into its integer ID for internal
use. It tests the event ID with a switch-case control structure.
It checks the source states of the transitions and their guards.
If any enabled transition is found, the state variables are
changed according to the original design of the DCharts model.
This method also executes the output and the enter/exit actions
(if any) as the transition is fired. If the model changes to a
final state, it also executes the finalizer before returning.
- public void changeState(int s1, int s2, boolean
check_history). Changes the model from state s1 to s2. This method implements the state change triggered by a
transition from state s1 to s2. If check_history is true, the history of s2 or any state in
the path from state to state s2 is
considered (such a transition has a [HS] property in the
original DCharts model); otherwise, history is ignored even if it
is recorded.
public void changeState(int s1, int s2) is equivalent to
public void changeState(int s1, int s2, false).
- protected int eventStr2Int(String event). Converts a
string event name into its integer ID.
- protected StringList getCurrentStateList(). Retrieves
the current leaf state(s) of the model. The result is stored in a
linked list of strings. Its elements are instances of class StringList. This method looks up all the current leaf states in
the main model, as well as the current leaf states in all the
submodels. It is used internally in the Java class. To retrieve
the current states in a more understandable format, the designers
should use function public String getCurrentState().
- public String getCurrentState(). This method invokes
method protected StringList getCurrentStateList(), and
returns the current leaf state(s) as a string enclosed by a pair
of square brackets. Multiple states are separated by comma `` ,''.
- public int getParentState(int state). Returns the parent
state of the specified state.
- public boolean isHistoryState(int state). Tests if the
specified state has a history.
- public boolean isLeafState(String state). Tests if the
specified state is a leaf state.
- public Hierarchy getHierarchy(int start_level, String
state_prefix). Returns the state hierarchy structure of the
model. The hierarchy structure is a linked list. The Next
attribute of each element (if it is non-null) gives access to the
next element. Each element in this linked list has the following
attributes:
- public String StateName. The name of a state in the
model.
- public String PathName. The full path of the state.
- public int StateNum. The integer ID of the state.
- public int Level. An integer that denotes the level
which the state is at. The larger this number is, the deeper
the state is in the state hierarchy.
Parameter start_level is an integer to be added to the Level attributes of all the elements in the returned list. This
is useful for importation states. Suppose an importation state is
at level 5. It calls the getHierarchy method of the imported
model with start_level=5. The generated hierarchy starts
from level 6.
Parameter state_prefix is the prefix to be added to the
head of the PathName attributes of all the elements in the
returned list. For example, importation state ``A.B'' calls
the getHierarchy method of the imported model with state_prefix="A.B". The full paths in the generated hierarchy
start with ``A.B.''.
Next: 8.1.4 Default Textual Interface
Up: 8.1 Java Code Design
Previous: 8.1.2 Numbering
Contents
Index
Thomas Huining Feng
2004-04-28