com.taserv.SMS
Class SMCompositeState

java.lang.Object
  extended by com.taserv.SMS.SMCompositeState
All Implemented Interfaces:
SimpleStateMachineIF, SMStateIF

public class SMCompositeState
extends java.lang.Object
implements SimpleStateMachineIF, SMStateIF

Composite state implementation. Composite state is state machine itself. During event handling composite state will pass event to its internal state machine, if not consumed by the internal SM, event will be handled by the state.


Constructor Summary
SMCompositeState(java.lang.Enum stateID)
           
SMCompositeState(SMState state)
           
 
Method Summary
 void _entryTransition()
          Performs the state entry transisions, it should not be used or overloaded by user SM.
 void _exitTransition()
          Performs the state exit transisions, it should not be used or overloaded by user SM.
 void addEntryTransition(EntryStateTransition trans)
          Adds entry transition to be perfomed every time the state becomes current
 void addEntryTransition(java.lang.Object state, EntryStateTransition trans)
          Adds entry transition to the state.
 void addExitTransition(ExitStateTransition trans)
          Adds exit transition to be perfomed every time other state replaces the state as current
 void addExitTransition(java.lang.Object state, ExitStateTransition trans)
          Adds exit transition to the state.
 void addState(java.lang.Enum stateID)
          Adds new state to SM or replaces existing state.
 void addState(SMStateIF state)
          Adds new state to SM or replaces existing state.
 void addTransition(java.lang.Class triggerEventCls, StateTransition transition)
          Adds transition to the state.
 void addTransition(java.lang.Class triggerEventCls, StateTransition transition, java.lang.Enum newState)
          Adds transition to the state.
 void addTransition(java.lang.Enum origStateEnum, java.lang.Class triggerEventCls, StateTransition transition)
          Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class.
 void addTransition(java.lang.Enum origStateEnum, java.lang.Class triggerEventCls, StateTransition transition, java.lang.Enum newState)
          Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class.
 void addTransition(SMStateIF origState, java.lang.Class triggerEventCls, StateTransition transition)
          Adds new transition to the SM or replaces existing transition identified by the origState and the event class.
 void addTransition(SMStateIF origState, java.lang.Class triggerEventCls, StateTransition transition, java.lang.Enum newState)
          Adds new transition to the SM or replaces existing transition identified by the origState and the event class.
 void copy(SMStateIF state)
          Copies state data such as transitions from the parameter state to the state
 void entryTransition()
           
 boolean equals(java.lang.Object state)
           
 void exitTransition()
           
 SMStateIF getCurrentState()
          Returns current SM state
 java.util.HashSet<EntryStateTransition> getEntryTransitions()
          Returns the collection of the defined entry transitions
 java.util.HashMap<java.lang.Class,SMState.TransitionSegment> getEventTransitions()
          Returns collection of the transistions defined in the state
 java.util.HashSet<ExitStateTransition> getExitTransitions()
          Returns the collection of the defined exit transitions
 StateTransition getLastPerformedTrans()
          Returns the last transition performed by the state
 SimpleStateMachineIF getSMMachineIF(java.lang.Enum state)
          Returns SimpleStateMachineIF interface for the state identified by state Enum
 java.lang.Enum getStateID()
          Returns the Enum indetifying the state
 java.lang.String getStateMachineName()
          Returns SM name
 java.lang.String getStateName()
          Returns state name
 java.util.HashMap<java.lang.Enum,SMStateIF> getStates()
          Returns states defined in the SM
 boolean handleEvent(SMEvent event)
          Event passed to the internal SM, the state event handling will not be attempted even if event was not consumed by the internal SM.
 int hashCode()
           
 void removeEntryTransition(EntryStateTransition trans)
          Removed entry transition
 void removeEntryTransition(java.lang.Object stateObj, EntryStateTransition trans)
          Removes entry transition.
 void setCurrentState(java.lang.Enum stateID)
          Sets current SM state to the state identified by stateID
 void setCurrentState(SMStateIF state)
          Sets current SM state to the state
 void setSMMatrix(java.lang.Object[][] smMatrix)
          Adds states and transitions identified by smMatrix to the SM.
 void setSMMatrix(java.lang.Object stateObj, java.lang.Object[][] smMatrix)
          Adds states and transitions identified by smMatrix to the state identified by stateObj.
 java.lang.Enum stateHandleEvent(SMEvent event)
          Event passed to the internal SM, if not consumed by the internal SM, the state handling will be attempted.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMCompositeState

public SMCompositeState(java.lang.Enum stateID)

SMCompositeState

public SMCompositeState(SMState state)
                 throws SMStateCanNotCopy
Throws:
SMStateCanNotCopy
Method Detail

getStateID

public java.lang.Enum getStateID()
Description copied from interface: SMStateIF
Returns the Enum indetifying the state

Specified by:
getStateID in interface SMStateIF

getStateName

public java.lang.String getStateName()
Description copied from interface: SMStateIF
Returns state name

Specified by:
getStateName in interface SMStateIF

equals

public boolean equals(java.lang.Object state)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

addState

public void addState(java.lang.Enum stateID)
              throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new state to SM or replaces existing state. In case of replace existing state data such as events, transitions, etc. copied into new state.

Specified by:
addState in interface SimpleStateMachineIF
Parameters:
stateID - enum id of the state to be added
Throws:
SMStateCanNotCopy - Thrown if the new state can not copy existing state into itself

addState

public void addState(SMStateIF state)
              throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new state to SM or replaces existing state. In case of replace existing state data such as events, transitions, etc. copied into new state.

Specified by:
addState in interface SimpleStateMachineIF
Parameters:
state - state to be added
Throws:
SMStateCanNotCopy - Thrown if the new state can not copy existing state into itself

setCurrentState

public void setCurrentState(SMStateIF state)
                     throws SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Sets current SM state to the state

Specified by:
setCurrentState in interface SimpleStateMachineIF
Parameters:
state - the state to be set current
Throws:
SMStateNotFound - Thrown if the state does not exist in the SM

setCurrentState

public void setCurrentState(java.lang.Enum stateID)
                     throws SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Sets current SM state to the state identified by stateID

Specified by:
setCurrentState in interface SimpleStateMachineIF
Parameters:
stateID - enum id of the state to be set current
Throws:
SMStateNotFound - Thrown if the state does not exist in the SM

addTransition

public void addTransition(SMStateIF origState,
                          java.lang.Class triggerEventCls,
                          StateTransition transition)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origState and the event class. The new state after execution of the transition identified by the return value of transition.

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origState - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(SMStateIF origState,
                          java.lang.Class triggerEventCls,
                          StateTransition transition,
                          java.lang.Enum newState)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origState and the event class. The new state after execution of the transition identified by newState if the return value of transition is NULL, otherwise the new states set to the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origState - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
newState - enum id of the state to set current after execution of the transition if the return value of the transition is NULL
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(java.lang.Enum origStateEnum,
                          java.lang.Class triggerEventCls,
                          StateTransition transition,
                          java.lang.Enum newState)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class. The new state after execution of the transition identified by newState if the return value of transition is NULL, otherwise the new states set to the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origStateEnum - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
newState - enum id of the state to set current after execution of the transition if the return value of the transition is NULL
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(java.lang.Enum origStateEnum,
                          java.lang.Class triggerEventCls,
                          StateTransition transition)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class. The new state after execution of the transition identified by the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origStateEnum - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(java.lang.Class triggerEventCls,
                          StateTransition transition)
Description copied from interface: SMStateIF
Adds transition to the state. If the transition for triggerEventCls exists, it will be replaced. New state returned by stateHandleEvent after executing the transition identified by the return value of the transition.

Specified by:
addTransition in interface SMStateIF
Parameters:
triggerEventCls - the class of the event that will trigger the transitions
transition - the transition object to be added

addTransition

public void addTransition(java.lang.Class triggerEventCls,
                          StateTransition transition,
                          java.lang.Enum newState)
Description copied from interface: SMStateIF
Adds transition to the state. If the transition for triggerEventCls exists, it will be replaced. New state returned by stateHandleEvent after executing the transition is newState if the return value of the transition is NULL

Specified by:
addTransition in interface SMStateIF
Parameters:
triggerEventCls - the class of the event that will trigger the transitions
transition - the transition object to be added
newState - Enum identifying the new state after performing the transition

handleEvent

public boolean handleEvent(SMEvent event)
Event passed to the internal SM, the state event handling will not be attempted even if event was not consumed by the internal SM.

Specified by:
handleEvent in interface SimpleStateMachineIF
Parameters:
event - event to be handled by SM
Returns:
true if event was consumed by SM, false otherwise

stateHandleEvent

public java.lang.Enum stateHandleEvent(SMEvent event)
                                throws SMStateCanNotHandleEvent
Event passed to the internal SM, if not consumed by the internal SM, the state handling will be attempted.

Specified by:
stateHandleEvent in interface SMStateIF
Parameters:
event - the event to be handled
Returns:
new state to set current. If transition object retuns non-NULL value, it is returned as new state, otherwise predefined newState returned
Throws:
SMStateCanNotHandleEvent - thrown if the state does not have a transition for the event class

getLastPerformedTrans

public StateTransition getLastPerformedTrans()
Description copied from interface: SMStateIF
Returns the last transition performed by the state

Specified by:
getLastPerformedTrans in interface SMStateIF

setSMMatrix

public void setSMMatrix(java.lang.Object[][] smMatrix)
                 throws SMBadMatrix,
                        SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds states and transitions identified by smMatrix to the SM.

Specified by:
setSMMatrix in interface SimpleStateMachineIF
Parameters:
smMatrix - transitions matrix identifying the behavior of the SM. The matrix should have the following format:
    
{
 { state <Enum or SMStateIF>, eventClass<Class>, transitionObject<StateTransition>, newState <Enum>},
 { state1 <Enum or SMStateIF>, eventClass1<Class>, transitionObject1<StateTransition>, newState1 <Enum>},
 …
}
Throws:
SMBadMatrix - if smMatrix format does not comform to the above format
SMStateCanNotCopy - if one of the states has to be replaced and the existing state data could not be copied to the new state

setSMMatrix

public void setSMMatrix(java.lang.Object stateObj,
                        java.lang.Object[][] smMatrix)
                 throws SMBadMatrix,
                        SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds states and transitions identified by smMatrix to the state identified by stateObj. The state identified by stateObj will be converted to SMCompositeState if needed.

Specified by:
setSMMatrix in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state that should have behavior identified by smMatrix
smMatrix - transitions matrix identifying the behavior of the state identified by stateObj The matrix should have the following format:
    
{
 { state <Enum or SMStateIF>, eventClass<Class>, transitionObject<StateTransition>, newState <Enum>},
 { state1 <Enum or SMStateIF>, eventClass1<Class>, transitionObject1<StateTransition>, newState1 <Enum>},
 …
}
Throws:
SMBadMatrix - if smMatrix format does not comform to the above format or stateObj is not Enum or SMStateIF
SMStateCanNotCopy - if one of the states has to be replaced and the existing state data could not be copied to the new state

_exitTransition

public void _exitTransition()
Description copied from interface: SMStateIF
Performs the state exit transisions, it should not be used or overloaded by user SM.

Specified by:
_exitTransition in interface SMStateIF

_entryTransition

public void _entryTransition()
Description copied from interface: SMStateIF
Performs the state entry transisions, it should not be used or overloaded by user SM.

Specified by:
_entryTransition in interface SMStateIF

entryTransition

public void entryTransition()
Specified by:
entryTransition in interface SMStateIF

exitTransition

public void exitTransition()
Specified by:
exitTransition in interface SMStateIF

addEntryTransition

public void addEntryTransition(EntryStateTransition trans)
Description copied from interface: SMStateIF
Adds entry transition to be perfomed every time the state becomes current

Specified by:
addEntryTransition in interface SMStateIF
Parameters:
trans - the transition to add

removeEntryTransition

public void removeEntryTransition(EntryStateTransition trans)
Description copied from interface: SMStateIF
Removed entry transition

Specified by:
removeEntryTransition in interface SMStateIF
Parameters:
trans - the transition to remove

addExitTransition

public void addExitTransition(ExitStateTransition trans)
Description copied from interface: SMStateIF
Adds exit transition to be perfomed every time other state replaces the state as current

Specified by:
addExitTransition in interface SMStateIF
Parameters:
trans - the transition to add

addEntryTransition

public void addEntryTransition(java.lang.Object state,
                               EntryStateTransition trans)
                        throws SMBadMatrix,
                               SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds entry transition to the state. The transition will be preformed every time the SM current state changes to the state

Specified by:
addEntryTransition in interface SimpleStateMachineIF
Parameters:
state - Enum or SMStateIF identifying the state
trans - the entry transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF
SMStateCanNotCopy - if can not copy state data

removeEntryTransition

public void removeEntryTransition(java.lang.Object stateObj,
                                  EntryStateTransition trans)
                           throws SMBadMatrix
Description copied from interface: SimpleStateMachineIF
Removes entry transition.

Specified by:
removeEntryTransition in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state
trans - the entry transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF

addExitTransition

public void addExitTransition(java.lang.Object state,
                              ExitStateTransition trans)
                       throws SMBadMatrix,
                              SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds exit transition to the state. The transition will be preformed every time the SM current state changes from the state to any other state

Specified by:
addExitTransition in interface SimpleStateMachineIF
Parameters:
state - Enum or SMStateIF identifying the state
trans - the exit transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF
SMStateCanNotCopy - if can not copy state data

getSMMachineIF

public SimpleStateMachineIF getSMMachineIF(java.lang.Enum state)
                                    throws SMNotCompositeState,
                                           SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Returns SimpleStateMachineIF interface for the state identified by state Enum

Specified by:
getSMMachineIF in interface SimpleStateMachineIF
Parameters:
state - Enum identifying the state
Returns:
SimpleStateMachineIF interface if the state is composite, otherwise throws SMNotCompositeState
Throws:
SMNotCompositeState - if the state is not composite
SMStateNotFound - if the state does not exist

copy

public void copy(SMStateIF state)
          throws SMStateCanNotCopy
Description copied from interface: SMStateIF
Copies state data such as transitions from the parameter state to the state

Specified by:
copy in interface SMStateIF
Parameters:
state - the state to copy data from
Throws:
SMStateCanNotCopy

getStates

public java.util.HashMap<java.lang.Enum,SMStateIF> getStates()
Description copied from interface: SimpleStateMachineIF
Returns states defined in the SM

Specified by:
getStates in interface SimpleStateMachineIF
Returns:
copy of the defined states collection

getEventTransitions

public java.util.HashMap<java.lang.Class,SMState.TransitionSegment> getEventTransitions()
Description copied from interface: SMStateIF
Returns collection of the transistions defined in the state

Specified by:
getEventTransitions in interface SMStateIF
Returns:
the copy of the map of the defined transitions, the keys are the event classes that will trigger transitions

getEntryTransitions

public java.util.HashSet<EntryStateTransition> getEntryTransitions()
Description copied from interface: SMStateIF
Returns the collection of the defined entry transitions

Specified by:
getEntryTransitions in interface SMStateIF
Returns:
the copy of the Set of the entry transitions

getExitTransitions

public java.util.HashSet<ExitStateTransition> getExitTransitions()
Description copied from interface: SMStateIF
Returns the collection of the defined exit transitions

Specified by:
getExitTransitions in interface SMStateIF
Returns:
the copy of the Set of the exit transitions

getStateMachineName

public java.lang.String getStateMachineName()
Description copied from interface: SimpleStateMachineIF
Returns SM name

Specified by:
getStateMachineName in interface SimpleStateMachineIF

getCurrentState

public SMStateIF getCurrentState()
Description copied from interface: SimpleStateMachineIF
Returns current SM state

Specified by:
getCurrentState in interface SimpleStateMachineIF


Copyright © 2004 TAServ. All Rights Reserved.