it.amattioli.workstate.core
Class State

Show UML class diagram
java.lang.Object
  extended by it.amattioli.workstate.core.State
All Implemented Interfaces:
AttributeReader
Direct Known Subclasses:
PseudoState, RealState

public abstract class State
extends Object
implements AttributeReader

Represent a generic state. Each state is associated to a MetaState that represents its configuration. After creation a state is not active and only the enter() method can be called on it. This method activate the state and initialize it. Calling exit() the state will be exited and it will be no more active. At creation time a unuique id will be created for the state.


Constructor Summary
State(MetaState metastate, CompositeState parent)
           
 
Method Summary
 void addAvailableEvents(Collection<MetaEvent> coll)
           
abstract  boolean admitEvent(Event event)
           
 Event buildEvent(String name, Map<String,Object> stringParameters)
           
protected  void checkActive()
          Verifies if this state is active.
 void enter()
          Enter this state and activate it.
 boolean equals(Object o)
           
 void exit()
          Exit a state and de-activate it.
 CompositeState findAncestor(MetaState ancestorMetaState)
          Search for an ancestor of this state whose MetaState is given.
 Map<String,Object> getAllAttributes()
          Return all the attributes of this state.
 Object getAttribute(String tag)
          Return the value of an attribute of this state.
 Collection<MetaEvent> getAvailableEvents()
           
 String getId()
          Return the identifier of this state.
 StateMemento getMemento()
           
protected abstract  StateMemento getMemento(StateMemento parent)
           
 CompositeState getParent()
          Return the composite state that is parent of this state.
 Machine getRootMachine()
           
 boolean hasMetaState(MetaState metastate)
          Check if the given MetaState is this state meta-state.
 boolean isActive()
          Verifies if this state is active.
 boolean isRegion()
          Check if this state is a region of a ConcurrentState.
abstract  void receiveEvent(Event event)
           
protected  void reEnter()
          Re-enter a state that was exited for exception handling purposes.
protected  void reExit()
          Re-exit a state that was entered for exception handling purposes.
abstract  void restore(StateMemento memento)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

State

public State(MetaState metastate,
             CompositeState parent)
Method Detail

enter

public void enter()
           throws WorkflowException
Enter this state and activate it.

Throws:
IllegalStateException - if this state is already
WorkflowException

reEnter

protected void reEnter()
Re-enter a state that was exited for exception handling purposes.


exit

public void exit()
          throws WorkflowException
Exit a state and de-activate it.

Throws:
IllegalStateException - if the state is not active
WorkflowException

reExit

protected void reExit()
Re-exit a state that was entered for exception handling purposes.


getParent

public CompositeState getParent()
Return the composite state that is parent of this state.

Returns:
the composite state that is parent of this state or null if this is root

findAncestor

public CompositeState findAncestor(MetaState ancestorMetaState)
Search for an ancestor of this state whose MetaState is given.

Throws:
IllegalArgumentException - if no ancestor of this has the given MetaState

isActive

public boolean isActive()
Verifies if this state is active.

Returns:
true if this state is active, false otherwise

checkActive

protected void checkActive()
Verifies if this state is active. If this state is not active an exception will be raised.

Throws:
IllegalStateException - if this state is not active

hasMetaState

public boolean hasMetaState(MetaState metastate)
Check if the given MetaState is this state meta-state.

Parameters:
metastate - the MetaState to be checked
Returns:
true if the given MetaState is this state meta-state, false otherwise

getRootMachine

public Machine getRootMachine()

receiveEvent

public abstract void receiveEvent(Event event)
                           throws WorkflowException
Throws:
WorkflowException

admitEvent

public abstract boolean admitEvent(Event event)

getAttribute

public Object getAttribute(String tag)
Return the value of an attribute of this state. A generic state has no attributes. Sub-class of this must implement this method so to handle attributes.

Specified by:
getAttribute in interface AttributeReader
Parameters:
tag - the attribute tag
Returns:
the attribute value
Throws:
IllegalStateException - if the state is not active
IllegalArgumentException - if there is no attribute with the given name

getAllAttributes

public Map<String,Object> getAllAttributes()
Return all the attributes of this state. A generic state has no attributes. Sub-class of this must implement this method so to handle attributes.

Specified by:
getAllAttributes in interface AttributeReader

getId

public String getId()
Return the identifier of this state. The identifier is a random string generated when the state is created.

Returns:
this state identifier

getMemento

protected abstract StateMemento getMemento(StateMemento parent)

getMemento

public StateMemento getMemento()

restore

public abstract void restore(StateMemento memento)
                      throws WorkflowException
Throws:
WorkflowException

equals

public boolean equals(Object o)
Overrides:
equals in class Object

isRegion

public boolean isRegion()
Check if this state is a region of a ConcurrentState. Only SequentialStates can be regions so the default implementation of this method return false.

Returns:
true if this state is a region of a ConcurrentState, false otherwise

buildEvent

public Event buildEvent(String name,
                        Map<String,Object> stringParameters)
                 throws WorkflowException
Throws:
WorkflowException

addAvailableEvents

public void addAvailableEvents(Collection<MetaEvent> coll)

getAvailableEvents

public Collection<MetaEvent> getAvailableEvents()


Copyright © 2011. All Rights Reserved.