|
Extension SDK | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectoracle.ide.panels.FSM
FSM
is a complete implementation of a finite state
machine (a.k.a. deterministic finite automaton). The FSM is
represented as a Map
, so clients will need to provide a
properly formatted Map
object to initialize the FSM.
The recommended way to build this Map
is to use the
FSMBuilder
class, which provides an API abstraction for
building the FSM data structure.
An FSM
returns an FSMStateInfo
every time a
client class asks for the next or previous state. The interpretation
of the FSMStateInfo
object's contents is left to the
client class's implementation.
The FSM
encapsulates fairly complex behavior. An
FSM
:
FSM
has halted. By definition, a halted FSM is one that has
completed its final state (and a particular FSM specification may contain
more than one final state). A final state is said to be "completed" when
its activity (represented by the Step
) has finished and Step's
Traversable
does not specify an exit transition that leaves the
final state.This means that it is possible to transition out of a final state into a non-final state or even another final state. The computational model for deterministic finite automata (DFA) allows for this, so this implementation simply follows suit. From a practical standpoint, most FSM's should need only one final state, and implementors should strive to have only one final state (with no transitions out of it) unless there is a specific feature that cannot be implemented otherwise.
The design of this class and its methods are based on the concepts behind the UML State Machine diagram, the UML Activity diagram, and the computational model of a deterministic finite automaton.
FSMBuilder
,
Step
,
Traversable
Field Summary | |
static java.lang.String |
ANY_TRANS
Special FSM state name representing all transitions that are not explicitly handled. |
static java.lang.String |
FSMState_OBJ
State property for the state object. |
static java.lang.String |
IS_FINAL_STATE
State property that indicates that the state is a final state. |
static java.lang.String |
START_STATE
Special FSM state name for the FSM's starting state. |
static java.lang.String |
TRANSITIONS
State property for the Map that tells how transitions
lead out of a state to other states in the FSM. |
Constructor Summary | |
FSM()
Initializes this instance to have a null FSM specification. |
|
FSM(java.util.Map fsmSpec)
This constructor takes an FSM specification in the form of a Map instance and initializes this FSM
instance to use it. |
Method Summary | |
int |
getStateIndex()
Returns the state number of the current top-level state. |
int |
getStepNumber()
Returns how many steps into the FSM that execution has
progressed through repeated invocations of nextState(Object) . |
int |
getTotalStepCount()
Returns the total number of steps in this FSM Note: This does not take into account steps in any sub-FSM |
boolean |
inFinalState()
Tests if the FSM is in a final state. |
boolean |
isFinishPageAdded()
Returns true if a finish page has been added, false otherwise |
boolean |
isHalted()
Tests if the FSM has halted. |
boolean |
isStarting()
|
boolean |
isWelcomePageAdded()
Returns true if a welcome page has been added, false otherwise |
FSMStateInfo |
nextState(java.lang.Object transition)
Updates the internal state of the FSM and returns the next FSMStateInfo object. |
FSMStateInfo |
previousState()
Rolls back the FSM to its previous state and returns
the corresponding FSMStateInfo object. |
void |
reset()
Resets the FSM state to its start state. |
void |
setFinishPageAdded(boolean pageAdded)
Sets whether a finish page has been added |
void |
setFSM(java.util.Map fsmSpec)
Sets the FSM specification that is to be used by this FSM
instance. |
void |
setWelcomePageAdded(boolean pageAdded)
Sets whether or not a welcome page has been added |
static void |
validateFSM(java.util.Map fsm)
This method validates the given FSM specification, verifying that it has an appropriate structure. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String START_STATE
public static final java.lang.String IS_FINAL_STATE
public static final java.lang.String FSMState_OBJ
Step
instance.
public static final java.lang.String TRANSITIONS
Map
that tells how transitions
lead out of a state to other states in the FSM.
public static final java.lang.String ANY_TRANS
Constructor Detail |
public FSM()
null
FSM specification.
public FSM(java.util.Map fsmSpec) throws FSMInvalidException
Map
instance and initializes this FSM
instance to use it. The FSM specification is validated before it
is set (see the comments for validateFSM(Map)
for details).
If any errors are found, then an FSMException
is thrown.
At that point the FSM
instance is invalid and cannot be
used until setFSM(Map)
is called with a valid FSM
specification.
Method Detail |
public void setFSM(java.util.Map fsmSpec) throws FSMInvalidException
FSM
instance. If the FSM
instance already has an FSM
specification, then an FSMException
is thrown. Otherwise
the FSM specification is validated before it is set.
FSMInvalidException
public void reset()
nextState(Object)
after a call to reset()
returns the FSM's starting state.
public int getStateIndex()
public int getStepNumber()
FSM
that execution has
progressed through repeated invocations of nextState(Object)
.
FSM
. By definition, 1
is the start state.
A return value of 0
means that the FSM is about to
enter the start state (i.e. the next call to nextState(Object)
will return the start state).public boolean isStarting()
public boolean inFinalState()
FSM
is in a final state. An FSM
that is in its final state is about to halt. This information can be
useful to UI that needs to be updated when the FSM
reaches its last step.
By definition, an FSM
is in its final state if its
current state is a final state and the sub-FSM, if any, is also in
its final state.
true
if the FSM
is in a final state;
false
otherwise.public boolean isHalted()
FSM
has halted. A halted FSM is one that
has entered a final state and successfully completed it without
transitioning to a non-final state.
true
if the FSM
has halted;
false
otherwise.public FSMStateInfo nextState(java.lang.Object transition) throws FSMException
FSMStateInfo
object. If the FSM
is newly
created or has just had its reset()
method called, then
then the starting FSMStateInfo
is returned no matter what
the transition is (i.e. a sub-FSM is ignored). If the FSM
has reached a final state and there are no transitions out of the final
state, then the FSM halts, and this method returns null
.
If the given transition does not lead to a defined state, then
nextState(Object)
throws an FSMTransitionException
.
In this case, the FSM
's state does not change. Any
subsequent call to nextState(Object)
with a valid transition
will cause the FSM
object to resume normal operation.
However, if the FSM
is already in a final state and there
are no transitions out of that state, then this method should throw
FSMTransitionException
for all transitions.
A null
transition, though unusual, should be accepted as
a valid, distinct transition.
If the FSM
has already halted, then this method will
always return null
; no exception is thrown.
The implementation of nextState(Object)
caches the
FSMStateInfo
object that is returned so that the same
FSMStateInfo
instance is returned if it is ever requested
again. This is important for handling calls to the
previousState()
method properly, which may be called to
retreat through the steps of the FSM
. Classes that
operate an FSM
can therefore rely on the FSM
to return the same FSMStateInfo
instances as before, if
the user visits the same state at the same step by following the same
transition.
transition
- The transition that should be followed to reach
the next state.
Throws
- FSMTransitionException
if the given
transition does not lead to a defined state.
Throws
- FSMException
if an internal error
occurs that cannot other wise be a FSMTransitionException
.
FSMException
public FSMStateInfo previousState() throws FSMException
FSM
to its previous state and returns
the corresponding FSMStateInfo
object. When returning a
previous state, the FSM
should return the same
FSMStateInfo
instance that was initially returned by
nextState(Object)
.
If the FSM is in the start state, then null
is returned,
and no exception is thrown. If calling previousState()
causes the FSM to move from a final state to a non-final state, the
return value of inFinalState()
should reflect this.
FSMStateInfo
that was returned by
this FSM
. The state of the FSM is also rolled back to
that state.
FSMException
nextState()
public static final void validateFSM(java.util.Map fsm) throws FSMInvalidException
FSMException
is thrown with an explanatory message. If
this method returns without throwing an FSMException
, the
FSM is valid.
By definition, an FSM specification is said to be valid if all
of the following requirements are met:
Notably missing from the definition of a valid FSM specification are
the following, which may be implemented in the future:
null
.
Map
is itself an
instance of Map
. Each of these maps are referred
to as a "state node" within the FSM specification.
Step
.
Map
. This value is referred to as a "transition
map". The keys of a transition map are transitions names, and
the values are state names.
FSMInvalidException
public void setWelcomePageAdded(boolean pageAdded)
public boolean isWelcomePageAdded()
public void setFinishPageAdded(boolean pageAdded)
public boolean isFinishPageAdded()
public int getTotalStepCount()
|
Extension SDK | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright ©1997, 2003, Oracle. All rights reserved.