it.amattioli.workstate.core
Class RealState

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

public abstract class RealState
extends State
implements AttributeHandler, Receiver

Represents a stable state in which a Machine can be after an event has been received. A real state can have attributes and can execute actions when entering and exiting it.


Constructor Summary
RealState(MetaRealState metaState, CompositeState parent)
           
 
Method Summary
protected  Map<String,Object> addAllAttributes(Map<String,Object> attributes)
          Add to the passed map all the attributes that are accessible from this state.
 void enter()
          Enter this state and activate it.
 boolean equals(Object o)
           
 void exit()
          Exit a state and de-activate it.
 Map<String,Object> getAllAttributes()
          Return a map containing all the attributes accessible from this state.
 Object getAttribute(String tag)
          Get the value of an attribute accessible to this state.
 Map<String,Object> getLocalAttributes()
          Return a map containing all the attributes of this state.
 String getTag()
          Return the tag of this state.
 boolean hasAllowedAttribute(String tag)
          Check if the passed string is the tag of an attribute that can be accessed by this state.
 boolean hasOwnAttribute(String tag)
          Check if the passed string is the tag of an attribute that belongs to this state.
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.
 void restore(StateMemento memento)
           
 void setAttribute(String tag, Object value)
          Set the value of an attribute accessible from this state.
 String toString()
           
 
Methods inherited from class it.amattioli.workstate.core.State
addAvailableEvents, admitEvent, buildEvent, checkActive, findAncestor, getAvailableEvents, getId, getMemento, getMemento, getParent, getRootMachine, hasMetaState, isActive, isRegion, receiveEvent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.amattioli.workstate.info.Receiver
receive
 

Constructor Detail

RealState

public RealState(MetaRealState metaState,
                 CompositeState parent)
Method Detail

getTag

public String getTag()
Return the tag of this state.

Returns:
the tag of this state

hasAllowedAttribute

public boolean hasAllowedAttribute(String tag)
Check if the passed string is the tag of an attribute that can be accessed by this state. An attribute is accessible if it belongs to this state or to one of its ancestors.

Parameters:
tag - the attribute tag
Returns:
true if the attribute is accessible, false otherwise

hasOwnAttribute

public boolean hasOwnAttribute(String tag)
Check if the passed string is the tag of an attribute that belongs to this state. If the attribute is accessible but belongs to an ancestor this method will return false.

Parameters:
the - attribute tag
Returns:
true if this state has an attribute with the given tag, false otherwise

getAttribute

public Object getAttribute(String tag)
Get the value of an attribute accessible to this state. An attribute is accessible if it belongs to this state or to one of its ancestors.

Specified by:
getAttribute in interface AttributeReader
Overrides:
getAttribute in class State
Parameters:
tag - the attribute tag
Returns:
the attribute value
Throws:
IllegalStateException - if this state is not active

getLocalAttributes

public Map<String,Object> getLocalAttributes()
Return a map containing all the attributes of this state. The map will contain only the attributes that belong to this state and not all the accessible attributes.

Returns:
a map containing all the attributes of this state

addAllAttributes

protected Map<String,Object> addAllAttributes(Map<String,Object> attributes)
Add to the passed map all the attributes that are accessible from this state. If the map contains a key identical to an attribute tag the old entry will be retained.


getAllAttributes

public Map<String,Object> getAllAttributes()
Return a map containing all the attributes accessible from this state. An attribute is accessible if it belongs to this state or to one of its ancestors.

Specified by:
getAllAttributes in interface AttributeReader
Overrides:
getAllAttributes in class State
Returns:
a map containing all the attributes accessible from this state

setAttribute

public void setAttribute(String tag,
                         Object value)
                  throws WorkflowException
Set the value of an attribute accessible from this state. An attribute is accessible if it belongs to this state or to one of its ancestors.

Specified by:
setAttribute in interface AttributeHandler
Parameters:
tag - the attribute tag
value - the new attribute value
Throws:
IllegalStateException - if the state is not active
IllegalArgumentException - if the passed string is not the tag of an accessible attribute
WorkflowException

enter

public void enter()
           throws WorkflowException
Description copied from class: State
Enter this state and activate it.

Overrides:
enter in class State
Throws:
WorkflowException

reEnter

protected void reEnter()
Description copied from class: State
Re-enter a state that was exited for exception handling purposes.

Overrides:
reEnter in class State

exit

public void exit()
          throws WorkflowException
Description copied from class: State
Exit a state and de-activate it.

Overrides:
exit in class State
Throws:
WorkflowException

reExit

protected void reExit()
Description copied from class: State
Re-exit a state that was entered for exception handling purposes.

Overrides:
reExit in class State

toString

public String toString()
Overrides:
toString in class Object

equals

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

restore

public void restore(StateMemento memento)
             throws WorkflowException
Specified by:
restore in class State
Throws:
WorkflowException


Copyright © 2011. All Rights Reserved.