net.dpml.metro.runtime
Class DefaultStateMachine

java.lang.Object
  extended bynet.dpml.metro.runtime.DefaultStateMachine
All Implemented Interfaces:
EventHandler, StateMachine

public class DefaultStateMachine
extends Object
implements StateMachine, EventHandler

Default state-machine implementation.

Version:
1.0.0
Author:
Digital Product Meta Library

Field Summary
static String PROPERTY_NAME
          Constant name used to reference a state change in a property event.
 
Constructor Summary
DefaultStateMachine(EventQueue queue, Logger logger, State state)
          Creation of a new state machine using a state graph.
 
Method Summary
 void addStateListener(StateListener listener)
          Add a state change listener to the state machine.
 State apply(String name, Object object)
          Apply a named transition to the target object.
 void dispose()
          Dispose of the state machine.
 Object execute(String name, Object object, Object[] args)
          Execute a named operation on the supplied object.
 EventListener[] getEventListeners()
          Return the assigned state event listeners.
 Action getInitializationAction()
          Locate and return the most immediate initialization action defined relative to the current state.
 Interface[] getInterfaces()
          Return all of the available interfaces relative to the current state.
 Operation[] getOperations()
          Return all of the available operations relative to the current state.
 State getState()
          Return the current state.
 Action getTerminationAction()
          Locate and return the most immediate termination action defined relative to the current state.
 Transition[] getTransitions()
          Return all of the available transitions relative to the current state.
 State initialize(Object object)
          Invoke initialization of the supplied object using the initialization action declared under the current state path.
 Object invoke(Object object, String method, Object[] args)
          Invoke a management method on the supplied object.
 boolean isActive()
          Returns the active status of the state machine.
 void processEvent(EventObject event)
          Process the supplied event.
 void removeStateListener(StateListener listener)
          Remove a state listener from the state machine.
 State terminate(Object object)
          Invoke termination of the supplied object using the termination action declared under the current state path.
static void validate(State state)
          Validate the state integrity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_NAME

public static final String PROPERTY_NAME
Constant name used to reference a state change in a property event.

See Also:
Constant Field Values
Constructor Detail

DefaultStateMachine

public DefaultStateMachine(EventQueue queue,
                           Logger logger,
                           State state)
                    throws RemoteException
Creation of a new state machine using a state graph.

Parameters:
queue - the event queue
logger - the logging channel
state - the state graph
Throws:
RemoteException - if RMI exception occurs
Method Detail

validate

public static void validate(State state)
Validate the state integrity.

Parameters:
state - the state to validate

addStateListener

public void addStateListener(StateListener listener)
Add a state change listener to the state machine.

Specified by:
addStateListener in interface StateMachine
Parameters:
listener - the state listener

removeStateListener

public void removeStateListener(StateListener listener)
Remove a state listener from the state machine.

Specified by:
removeStateListener in interface StateMachine
Parameters:
listener - the state listener

getEventListeners

public EventListener[] getEventListeners()
Return the assigned state event listeners.

Specified by:
getEventListeners in interface EventHandler
Returns:
the event listeners

processEvent

public void processEvent(EventObject event)
Process the supplied event.

Specified by:
processEvent in interface EventHandler
Parameters:
event - the event to process

getState

public State getState()
Return the current state.

Specified by:
getState in interface StateMachine
Returns:
the current state

getInitializationAction

public Action getInitializationAction()
Locate and return the most immediate initialization action defined relative to the current state. If an action is located within the current state it will be return otherwise the search will continue up the state graph until either an action is located or no further parent state is available in which case a null value is returned.

Returns:
the initialization action or null if no action declared

getTerminationAction

public Action getTerminationAction()
Locate and return the most immediate termination action defined relative to the current state. If an action is located within the current state it will be return otherwise the search will continue up the state graph until either an action is located or no further parent state is available in which case a null value is returned.

Returns:
the termination action or null if no action declared

initialize

public State initialize(Object object)
                 throws InvocationTargetException
Invoke initialization of the supplied object using the initialization action declared under the current state path.

Specified by:
initialize in interface StateMachine
Parameters:
object - the object to initialize
Returns:
the state established as a sidee effect of the initialization
Throws:
InvocationTargetException - if an invocation error occurs as a result of initialization

execute

public Object execute(String name,
                      Object object,
                      Object[] args)
               throws UnknownOperationException,
                      InvocationTargetException
Execute a named operation on the supplied object.

Specified by:
execute in interface StateMachine
Parameters:
name - an operation name
object - the target object
args - operation arguments
Returns:
the result of operation invocation
Throws:
UnknownOperationException - if the operation is unknown
InvocationTargetException - if an invocation error occurs as a result of operation execution

invoke

public Object invoke(Object object,
                     String method,
                     Object[] args)
              throws UnknownOperationException,
                     InvocationTargetException,
                     IllegalStateException
Invoke a management method on the supplied object.

Specified by:
invoke in interface StateMachine
Parameters:
object - the target object
method - the method name
args - method parameter arguments
Returns:
the return value
Throws:
IllegalStateException - if the method is recognized but not available
UnknownOperationException - if the operation is unknown
InvocationTargetException - if an invocation error occurs as a result of operation execution

apply

public State apply(String name,
                   Object object)
            throws UnknownTransitionException,
                   InvocationTargetException
Apply a named transition to the target object.

Specified by:
apply in interface StateMachine
Parameters:
name - the transition name
object - the object against which any transition handler action are to be applied
Returns:
the state established by the application of the transition
Throws:
UnknownTransitionException - if the transition is unknown
InvocationTargetException - if an invocation error occurs as a result of transition invocation

getTransitions

public Transition[] getTransitions()
Return all of the available transitions relative to the current state.

Specified by:
getTransitions in interface StateMachine
Returns:
the available transitions

getOperations

public Operation[] getOperations()
Return all of the available operations relative to the current state.

Specified by:
getOperations in interface StateMachine
Returns:
the available operations

getInterfaces

public Interface[] getInterfaces()
Return all of the available interfaces relative to the current state.

Specified by:
getInterfaces in interface StateMachine
Returns:
the available interface declarations

terminate

public State terminate(Object object)
Invoke termination of the supplied object using the termination action declared under the current state path.

Specified by:
terminate in interface StateMachine
Parameters:
object - the object to terminate
Returns:
the state established as a side-effect of the termination

isActive

public boolean isActive()
Returns the active status of the state machine.

Specified by:
isActive in interface StateMachine
Returns:
TRUE if the state machine has invoked initialization and termination has not been performed otherwise FALSE

dispose

public void dispose()
Dispose of the state machine.