站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 3.2.7 common API Documentation 英文版文档

DefaultStateMachineModel (JBoss/Common API) - JBoss 3.2.7 common API Documentation 英文版文档


org.jboss.util.state
Class DefaultStateMachineModel

java.lang.Object
  extended byorg.jboss.util.CloneableObject
      extended byorg.jboss.util.state.DefaultStateMachineModel
All Implemented Interfaces:
Cloneable, CloneableObject.Cloneable, PrettyString.Appendable, Serializable, StateMachine.Model

public class DefaultStateMachineModel
extends CloneableObject
implements StateMachine.Model, Serializable, PrettyString.Appendable

A default implementation of a state machine model.

Accepting to acceptable state mappings are backed up by a HashMap and HashSets.

Implements clonable so that the model can be used as a prototype. Nested containers are cloned, so that changes will not effect the master or other clones.

Version:
$Revision: 1.5 $
Author:
Jason Dillon
See Also:
Serialized Form

Nested Class Summary
protected static class DefaultStateMachineModel.Entry
          A container for entiries in the state acceptable map.
 
Nested classes inherited from class org.jboss.util.CloneableObject
CloneableObject.Cloneable
 
Field Summary
protected  Map acceptingMap
          The mapping from State to Entry.
protected  DefaultStateMachineModel.Entry current
          The mapping entry for the current state.
protected  DefaultStateMachineModel.Entry initial
          The mapping entry for the initial state.
 
Constructor Summary
DefaultStateMachineModel()
          Construct a new DefaultStateMachineModel.
 
Method Summary
 Set acceptableStates(State state)
          Return an immutable set of the acceptable states for a given accepting state.
 Set addState(State state)
          Add a final state.
 Set addState(State state, Set acceptable)
          Add a non-final state.
 Set addState(State state, State acceptable)
           
 Set addState(State state, State[] acceptable)
          Add a non-final state.
 StringBuffer appendPrettyString(StringBuffer buff, String prefix)
          Appends a pretty representation of the object to the given buffer.
 void clear()
          Clear all accepting state mappings and reset the initial and current state to null.
 Object clone()
          Clone the object via Object.clone().
 boolean containsState(State state)
          Check if a give state is contained in the model.
 boolean equals(Object obj)
           
 State getCurrentState()
          Get the current state.
protected  DefaultStateMachineModel.Entry getEntry(State state)
          Get an entry from the map.
 State getInitialState()
          Return the initial state which the state machine should start in.
 State getMappedState(State state)
          Returns the state object mapped for the given state value.
 boolean isMappedState(State state)
          Determins if there is a mapping for the given state object.
protected  DefaultStateMachineModel.Entry putEntry(State state, Set acceptable)
          Put a new entry into the map.
 Set removeState(State state)
          Remove a state from the model.
 void setCurrentState(State state)
          Set the current state.
 void setInitialState(State state)
          Set the initial state.
 Set states()
          Return an immutable set of the accepting states.
 String toString()
           
protected  void updateAcceptableMapping(State state, boolean remove)
          Update acceptable mappings.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

acceptingMap

protected Map acceptingMap
The mapping from State to Entry.


initial

protected DefaultStateMachineModel.Entry initial
The mapping entry for the initial state.


current

protected DefaultStateMachineModel.Entry current
The mapping entry for the current state.

Constructor Detail

DefaultStateMachineModel

public DefaultStateMachineModel()
Construct a new DefaultStateMachineModel.

Method Detail

appendPrettyString

public StringBuffer appendPrettyString(StringBuffer buff,
                                       String prefix)
Description copied from interface: PrettyString.Appendable
Appends a pretty representation of the object to the given buffer.

Specified by:
appendPrettyString in interface PrettyString.Appendable
Parameters:
buff - The buffer to use while making pretty.
prefix - The string which all lines of the output must be prefixed with.
Returns:
The buffer.

toString

public String toString()

equals

public boolean equals(Object obj)

getEntry

protected DefaultStateMachineModel.Entry getEntry(State state)
Get an entry from the map.

Parameters:
state - The state of the entry; must not be null.

putEntry

protected DefaultStateMachineModel.Entry putEntry(State state,
                                                  Set acceptable)
Put a new entry into the map.

Returns:
The previous entry for the state or null if none.

isMappedState

public boolean isMappedState(State state)
Description copied from interface: StateMachine.Model
Determins if there is a mapping for the given state object.

Specified by:
isMappedState in interface StateMachine.Model
Parameters:
state - The state with the value of the bound state to check for; must not be null.
Returns:
True if the state is mapped; else false.

getMappedState

public State getMappedState(State state)
Description copied from interface: StateMachine.Model
Returns the state object mapped for the given state value.

Since states with the same value are equivlent, this provides access to the actual state instance which is bound in the model.

Specified by:
getMappedState in interface StateMachine.Model
Parameters:
state - The state with the value of the bound state to return; null will return false.
Returns:
The bound state instance.

addState

public Set addState(State state,
                    Set acceptable)
Description copied from interface: StateMachine.Model
Add a non-final state.

Existing acceptable states will be replaced by the given states.

Acceptable states which are not registered as accepting states will be added as final states.

If the acceptable set is null, then the added state will be final.

Note, states are added based on the valid states which can be transitioned to from the given state, not on the states which accept the given state.

For example, if adding state A which accepts B and C, this means that when the machine is in state A, it will allow transitions to B or C and not from C to A or B to A (unless of course a state mapping is setup up such that C and B both accept A).

Specified by:
addState in interface StateMachine.Model
Parameters:
state - The accepting state; must not be null.
acceptable - The valid acceptable states; must not contain null elements.

addState

public Set addState(State state,
                    State[] acceptable)
Description copied from interface: StateMachine.Model
Add a non-final state.

Specified by:
addState in interface StateMachine.Model
Parameters:
state - The accepting state; must not be null.
acceptable - The valid acceptable states; must not contain null elements.
See Also:
StateMachine.Model.addState(State,Set)

addState

public Set addState(State state,
                    State acceptable)

addState

public Set addState(State state)
Description copied from interface: StateMachine.Model
Add a final state.

Note, if the given state implements StateMachine.Acceptable then the final determiniation of its finality will be unknown until runtime.

Specified by:
addState in interface StateMachine.Model
Parameters:
state - The final state; must not be null.

setInitialState

public void setInitialState(State state)
Description copied from interface: StateMachine.Model
Set the initial state.

Does not need to validate the state, StateMachine will handle those details.

Specified by:
setInitialState in interface StateMachine.Model
Parameters:
state - The initial state; must not be null.

getInitialState

public State getInitialState()
Description copied from interface: StateMachine.Model
Return the initial state which the state machine should start in.

Specified by:
getInitialState in interface StateMachine.Model
Returns:
The initial state of the state machine; must not be null.

setCurrentState

public void setCurrentState(State state)
Description copied from interface: StateMachine.Model
Set the current state.

Does not need to validate the state, StateMachine will handle those details.

Specified by:
setCurrentState in interface StateMachine.Model
Parameters:
state - The current state; must not be null.

getCurrentState

public State getCurrentState()
Description copied from interface: StateMachine.Model
Get the current state.

Specified by:
getCurrentState in interface StateMachine.Model
Returns:
The current state; can be null if not used by a state machine. Once it has been given to a state machine this must not be null.

containsState

public boolean containsState(State state)
Description copied from interface: StateMachine.Model
Check if a give state is contained in the model.

Specified by:
containsState in interface StateMachine.Model
Parameters:
state - The state to look for.
Returns:
True if the state is contained in the model; false if not.

removeState

public Set removeState(State state)
Description copied from interface: StateMachine.Model
Remove a state from the model.

Specified by:
removeState in interface StateMachine.Model
Parameters:
state - The state to remove.
Returns:
The acceptable states for the removed state or null.

updateAcceptableMapping

protected void updateAcceptableMapping(State state,
                                       boolean remove)
Update acceptable mappings.

Parameters:
state - The state value to update or remove
remove - True to remove the state from all mappings.

states

public Set states()
Description copied from interface: StateMachine.Model
Return an immutable set of the accepting states.

Specified by:
states in interface StateMachine.Model
Returns:
A set of accepting states.

acceptableStates

public Set acceptableStates(State state)
Description copied from interface: StateMachine.Model
Return an immutable set of the acceptable states for a given accepting state.

Specified by:
acceptableStates in interface StateMachine.Model
Parameters:
state - The accepting state to get acceptable states for; must not be null.
Returns:
A set of accepting states.

clear

public void clear()
Description copied from interface: StateMachine.Model
Clear all accepting state mappings and reset the initial and current state to null.

Specified by:
clear in interface StateMachine.Model

clone

public Object clone()
Description copied from class: CloneableObject
Clone the object via Object.clone(). This will return and object of the correct type, with all fields shallowly cloned.

Specified by:
clone in interface CloneableObject.Cloneable
Overrides:
clone in class CloneableObject


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.