com.evelopers.unimod.core.stateworks
Class StateMachine

java.lang.Object
  extended bycom.evelopers.unimod.core.ModelElement
      extended bycom.evelopers.unimod.core.stateworks.ClassElement
          extended bycom.evelopers.unimod.core.stateworks.StateMachine
All Implemented Interfaces:
java.io.Serializable

public class StateMachine
extends ClassElement

Class StateMachine represents StateMachine abstraction. State machine "knows" directly only about it's top state and about all controlled objects and event providers. State machine must have top state.

Implements factory for State, Transition, Guard, Event, Action, Association, Parameter.

See Also:
Serialized Form

Field Summary
static java.lang.String STATEMACHINE_STEREOTYPE
           
static java.lang.String TOP_STATE_PROPERTY
           
protected  State topState
          Top state.
 
Fields inherited from class com.evelopers.unimod.core.stateworks.ClassElement
IMPL_NAME_PROPERTY, implName, INCOMING_ASSOCIATIONS_PROPERTY, incomingAssociations, OUTGOING_ASSOCIATIONS_PROPERTY, outgoingAssociations
 
Fields inherited from class com.evelopers.unimod.core.ModelElement
listeners, name, NAME_PROPERTY, stereotype, STEREOTYPE_PROPERTY
 
Constructor Summary
protected StateMachine(java.lang.String name)
          Creates empty state machine.
protected StateMachine(java.lang.String name, java.lang.String configStoreClassName)
          Creates empty state machine with given config store.
 
Method Summary
 void addContolledObjectHandler(ControlledObjectHandler controlledObjectHandler)
          Creates new association with the given controlled object handler as a supplier and this state machine as a client.
protected  void addIncomingAssociation(Association association)
           
protected  void addOutgoingAssociation(Association association)
           Adds an association to state machine.
 void addStateMachine(StateMachine sm)
           
 Action createAction(java.lang.String identifier)
          Creates Action (Input or Output).
 Guard createGuard(java.lang.String expr)
          Creates guard condition
 Association createIncomingAssociation(ClassElement client)
           
 Association createIncomingAssociation(ClassElement client, java.lang.String clientRole)
           
 Association createIncomingAssociation(ClassElement client, java.lang.String supplierRole, java.lang.String clientRole)
           
 Association createOutgoingAssociation(ClassElement supplier)
           
 Association createOutgoingAssociation(ClassElement supplier, java.lang.String supplierRole)
           
 Association createOutgoingAssociation(ClassElement supplier, java.lang.String supplierRole, java.lang.String clientRole)
           
 State createState(java.lang.String name, StateType type)
          Creates state
 State createTopState(java.lang.String name)
           
 Transition createTransition(State sourceState, State targetState, Guard guard, Event event)
          Creates transition
 boolean equals(java.lang.Object o)
          Checks if this state machine equals to the given object.
 State findState(java.lang.String name)
           
 StateMachine findSubmachine(java.lang.String name)
           
 java.util.List getAllStates()
          Return new set that contains all states
protected  java.util.List getAllStates(State root)
          Return new set that are contained by the given root directly (as substates) or indirectly (as substates of substates etc.)
 java.util.List getAllTransition()
          Returns all transitions
 ClassElement getClassElement(java.lang.String name)
          Returns associated class element with given supplier role name
 java.lang.String getConfigManagerClassName()
           
 ControlledObjectHandler getControlledObjectHandler(java.lang.String objectName)
          Returns controlled object handler with given name.
 java.util.List getControlledObjectHandlers()
          Returns all controlled object handlers
 java.util.List getEventProviderHandlers()
           
 StateMachine getStateMachine(java.lang.String smName)
          Returns associated state machine with given supplier role name
 java.util.List getStateMachines()
          Returns all associated state machines
 java.util.Set getSubmachines()
          Return all state machines included by all states of this state machine as submachines
 State getTop()
          Return top state.
 int hashCode()
          Returns hash code based on the name of this state machine.
 void removeControlledObjectHandler(ControlledObjectHandler controlledObjectHandler)
          Removes given controlled object handler from state machine.
 void setConfigManagerClassName(java.lang.String configManagerClassName)
           
 void setTop(State top)
          Set top state.
 java.lang.String toString()
          Returns class identifier
 
Methods inherited from class com.evelopers.unimod.core.stateworks.ClassElement
getImplName, getIncomingAssociations, getOutgoingAssociations, removeIncomingAssociation, removeOutgoingAssociation, setImplName
 
Methods inherited from class com.evelopers.unimod.core.ModelElement
accept, addPropertyChangeListener, firePropertyChange, getName, getStereotype, initListeners, removePropertyChangeListener, setName, setStereotype
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STATEMACHINE_STEREOTYPE

public static final java.lang.String STATEMACHINE_STEREOTYPE
See Also:
Constant Field Values

TOP_STATE_PROPERTY

public static final java.lang.String TOP_STATE_PROPERTY
See Also:
Constant Field Values

topState

protected State topState
Top state.

Constructor Detail

StateMachine

protected StateMachine(java.lang.String name)
Creates empty state machine.


StateMachine

protected StateMachine(java.lang.String name,
                       java.lang.String configStoreClassName)
Creates empty state machine with given config store.

Method Detail

getTop

public State getTop()
Return top state.

Returns:
top state

setTop

public void setTop(State top)
Set top state.

Parameters:
top - new top state

getConfigManagerClassName

public java.lang.String getConfigManagerClassName()

setConfigManagerClassName

public void setConfigManagerClassName(java.lang.String configManagerClassName)

addOutgoingAssociation

protected void addOutgoingAssociation(Association association)

Adds an association to state machine.

Note: this method should be invoked only from method Association.reconnect(com.evelopers.unimod.core.stateworks.ClassElement, com.evelopers.unimod.core.stateworks.ClassElement) or its extensions and implementations.

Overrides:
addOutgoingAssociation in class ClassElement
Parameters:
association - association to add
Throws:
java.lang.IllegalArgumentException - if given association is null or its supplier is not this state machine

addIncomingAssociation

protected void addIncomingAssociation(Association association)
Overrides:
addIncomingAssociation in class ClassElement

hashCode

public int hashCode()
Returns hash code based on the name of this state machine.

Overrides:
hashCode in class ClassElement
Returns:
hash code based on the name of this state machine

equals

public boolean equals(java.lang.Object o)
Checks if this state machine equals to the given object. Two state machines are equal if they have same names.

Overrides:
equals in class ClassElement
Parameters:
o - an object to compare this machine to
Returns:
whether this state machine is equal to the given object

toString

public java.lang.String toString()
Description copied from class: ClassElement
Returns class identifier

Overrides:
toString in class ClassElement
Returns:
class identifier

addContolledObjectHandler

public void addContolledObjectHandler(ControlledObjectHandler controlledObjectHandler)
Creates new association with the given controlled object handler as a supplier and this state machine as a client. As a result in the association's constructor the association is added to the association list of this state machine and to the association list of given controlled object handler.

Parameters:
controlledObjectHandler - controlled object handler to add

addStateMachine

public void addStateMachine(StateMachine sm)

removeControlledObjectHandler

public void removeControlledObjectHandler(ControlledObjectHandler controlledObjectHandler)
Removes given controlled object handler from state machine. It means that all association having given controlled object handler as supplier will be removed from this state machine.

Parameters:
controlledObjectHandler - controlled object handler to remove

getControlledObjectHandlers

public java.util.List getControlledObjectHandlers()
Returns all controlled object handlers

Returns:
all controlled object handlers

getStateMachines

public java.util.List getStateMachines()
Returns all associated state machines

Returns:
all controlled object handlers

getEventProviderHandlers

public java.util.List getEventProviderHandlers()

getControlledObjectHandler

public ControlledObjectHandler getControlledObjectHandler(java.lang.String objectName)
Returns controlled object handler with given name. To achieve this method iterates through associations and returns supplier of first association that has supplier role equal to given objectName.

Parameters:
objectName - controlled object handler name
Returns:
controlled object handler

getStateMachine

public StateMachine getStateMachine(java.lang.String smName)
Returns associated state machine with given supplier role name

Parameters:
smName -
Returns:

getClassElement

public ClassElement getClassElement(java.lang.String name)
Returns associated class element with given supplier role name

Parameters:
name -
Returns:

getSubmachines

public java.util.Set getSubmachines()
Return all state machines included by all states of this state machine as submachines

Returns:
included state machines

getAllStates

public java.util.List getAllStates()
Return new set that contains all states

Returns:
all states

getAllStates

protected java.util.List getAllStates(State root)
Return new set that are contained by the given root directly (as substates) or indirectly (as substates of substates etc.)

Parameters:
root - root state
Returns:
all states contained by root

getAllTransition

public java.util.List getAllTransition()
Returns all transitions

Returns:
all transitions

findState

public State findState(java.lang.String name)

findSubmachine

public StateMachine findSubmachine(java.lang.String name)

createState

public State createState(java.lang.String name,
                         StateType type)
Creates state

Parameters:
name - state name
type - state type
Returns:
newly created state

createTopState

public State createTopState(java.lang.String name)

createTransition

public Transition createTransition(State sourceState,
                                   State targetState,
                                   Guard guard,
                                   Event event)
Creates transition

Parameters:
sourceState - source state
targetState - target state
guard - guard condition
event - trigger event
Returns:
newly created transition

createGuard

public Guard createGuard(java.lang.String expr)
Creates guard condition

Parameters:
expr - guard condition logical expression parser will check return types and throw ParserException if it wrong.
Returns:
newly created guard condition

createOutgoingAssociation

public Association createOutgoingAssociation(ClassElement supplier,
                                             java.lang.String supplierRole,
                                             java.lang.String clientRole)

createOutgoingAssociation

public final Association createOutgoingAssociation(ClassElement supplier,
                                                   java.lang.String supplierRole)

createOutgoingAssociation

public final Association createOutgoingAssociation(ClassElement supplier)

createIncomingAssociation

public Association createIncomingAssociation(ClassElement client,
                                             java.lang.String supplierRole,
                                             java.lang.String clientRole)

createIncomingAssociation

public final Association createIncomingAssociation(ClassElement client,
                                                   java.lang.String clientRole)

createIncomingAssociation

public final Association createIncomingAssociation(ClassElement client)

createAction

public Action createAction(java.lang.String identifier)
Creates Action (Input or Output).

Parameters:
identifier - action ident in form o1.z1 or a1.e1
Returns:
newly created Action