it.amattioli.workstate.core
Class MetaState

Show UML class diagram
java.lang.Object
  extended by it.amattioli.workstate.core.MetaState
All Implemented Interfaces:
Receiver
Direct Known Subclasses:
MetaPseudoState, MetaRealState

public abstract class MetaState
extends Object
implements Receiver

A MetaState represents the configuration of a possible state of a Machine. Every instance of the machine will use the same MetaState to retrieve configuration informations like:

This class is the root of the inheritance tree for meta-states and implements basic functionalities.


Constructor Summary
MetaState()
           
 
Method Summary
 void addAvailableEvents(Collection<MetaEvent> coll)
          Add to the passed collection all the MetaEvents receivable by the machine when it is in a state based on this.
 void addTransition(Transition transition)
          Add a Transition exiting from this meta-state.
protected  void checkParentState(CompositeState parent)
          Check if the parameter could be the parent state of a State based on this.
 boolean descendFrom(MetaCompositeState metaState)
          Check if the parameter is an ancestor of this meta-state.
 Transition findTriggeredTransition(Event event, State state)
          Find a transition triggered by a given Event when the machine is in a State based on this.
 Collection<MetaEvent> getAvailableEvents()
          Return all the MetaEvents receivable by the machine when it is in a state based on this.
 Configuration getConfig()
           
 MetaCompositeState getParent()
          Return the parent meta-state
abstract  State newState(CompositeState parent)
          Create a new State based on this meta-state.
 void setParent(MetaCompositeState parent)
          Set the parent of this meta-state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.amattioli.workstate.info.Receiver
receive
 

Constructor Detail

MetaState

public MetaState()
Method Detail

newState

public abstract State newState(CompositeState parent)
Create a new State based on this meta-state. Implementations of this method must call checkParentState(CompositeState) to check that the passed state is admittable as parent state for the state that will be created.

Parameters:
parent - the parent state for the state that will be created
Returns:
the new state
Throws:
IllegalArgumentException - if the parameter is not admittable as parent state for the state that will be created

setParent

public void setParent(MetaCompositeState parent)
Set the parent of this meta-state. When a new MetaState is created the parent is set to null. This means that the meta-state is a root one but can be later changed using this method. This method doesn't check that the parent state has this as one of its sub-states. It is a caller responsibility to assure this.

Parameters:
parent - the new parent meta-state

getParent

public MetaCompositeState getParent()
Return the parent meta-state

Returns:
the parent meta-state

checkParentState

protected void checkParentState(CompositeState parent)
Check if the parameter could be the parent state of a State based on this. If it is not so an exception will be raised.

Parameters:
parent - the state to be checked
Throws:
IllegalArgumentException - if the parameter cannot be the parent state of a State based on this

descendFrom

public boolean descendFrom(MetaCompositeState metaState)
Check if the parameter is an ancestor of this meta-state.

Parameters:
metaState -
Returns:
true if the parameter is an ancestor of this meta-state, false otherwise
Throws:
NullPointerException - if the parameter is null

addTransition

public void addTransition(Transition transition)
Add a Transition exiting from this meta-state.

Parameters:
transition - the new transition that will exit this meta-state
Throws:
NullPointerException - if the parameter is null
IllegalArgumentException - if already exists a transition exiting from this meta-state triggered by the same event and with an identical guard

findTriggeredTransition

public Transition findTriggeredTransition(Event event,
                                          State state)
Find a transition triggered by a given Event when the machine is in a State based on this. Only the transitions directly exiting from this meta-state will be searched.

Parameters:
event - the received event
state - the current state
Returns:
the found transition or null

getConfig

public Configuration getConfig()

addAvailableEvents

public void addAvailableEvents(Collection<MetaEvent> coll)
Add to the passed collection all the MetaEvents receivable by the machine when it is in a state based on this.

Parameters:
coll - the collection to which the MetaEvents will be added

getAvailableEvents

public Collection<MetaEvent> getAvailableEvents()
Return all the MetaEvents receivable by the machine when it is in a state based on this.

Returns:
all the MetaEvents receivable by the machine when it is in a state based on this


Copyright © 2011. All Rights Reserved.