org.apache.commons.scxml.env
Class AbstractStateMachine

java.lang.Object
  extended by org.apache.commons.scxml.env.AbstractStateMachine

public abstract class AbstractStateMachine
extends Object

This class demonstrates one approach for providing the base functionality needed by classes representing stateful entities, whose behaviors are defined via SCXML documents.

SCXML documents (more generically, UML state chart diagrams) can be used to define stateful behavior of objects, and Commons SCXML enables developers to use this model directly into the corresponding code artifacts. The resulting artifacts tend to be much simpler, embody a useful separation of concerns and are easier to understand and maintain. As the size of the modeled entity grows, these benefits become more apparent.

This approach functions by registering an SCXMLListener that gets notified onentry, and calls the namesake method for each state that has been entered.

This class swallows all exceptions only to log them. Developers of subclasses should think of themselves as "component developers" catering to other end users, and therefore ensure that the subclasses are free of ModelExceptions and the like. Most methods are protected for ease of subclassing.


Nested Class Summary
protected  class AbstractStateMachine.EntryListener
          A SCXMLListener that is only concerned about "onentry" notifications.
 
Constructor Summary
AbstractStateMachine(SCXML stateMachine)
          Convenience constructor.
AbstractStateMachine(SCXML stateMachine, Context rootCtx, Evaluator evaluator)
          Primary constructor.
AbstractStateMachine(URL scxmlDocument)
          Convenience constructor, object instantiation incurs parsing cost.
AbstractStateMachine(URL scxmlDocument, Context rootCtx, Evaluator evaluator)
          Primary constructor, object instantiation incurs parsing cost.
 
Method Summary
 boolean fireEvent(String event)
          Fire an event on the SCXML engine.
 SCXMLExecutor getEngine()
          Get the SCXML engine driving the "lifecycle" of the instances of this class.
 org.apache.commons.logging.Log getLog()
          Get the log for this class.
static SCXML getStateMachine()
          Deprecated. Returns null, use getEngine().getStateMachine() instead
 boolean invoke(String methodName)
          Invoke the no argument method with the following name.
protected  void logError(Exception exception)
          Utility method for logging error.
 boolean resetMachine()
          Reset the state machine.
 void setLog(org.apache.commons.logging.Log log)
          Set the log for this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStateMachine

public AbstractStateMachine(URL scxmlDocument)
Convenience constructor, object instantiation incurs parsing cost.

Parameters:
scxmlDocument - The URL pointing to the SCXML document that describes the "lifecycle" of the instances of this class.

AbstractStateMachine

public AbstractStateMachine(URL scxmlDocument,
                            Context rootCtx,
                            Evaluator evaluator)
Primary constructor, object instantiation incurs parsing cost.

Parameters:
scxmlDocument - The URL pointing to the SCXML document that describes the "lifecycle" of the instances of this class.
rootCtx - The root context for this instance.
evaluator - The expression evaluator for this instance.
See Also:
Context, Evaluator

AbstractStateMachine

public AbstractStateMachine(SCXML stateMachine)
Convenience constructor.

Parameters:
stateMachine - The parsed SCXML instance that describes the "lifecycle" of the instances of this class.
Since:
0.7

AbstractStateMachine

public AbstractStateMachine(SCXML stateMachine,
                            Context rootCtx,
                            Evaluator evaluator)
Primary constructor.

Parameters:
stateMachine - The parsed SCXML instance that describes the "lifecycle" of the instances of this class.
rootCtx - The root context for this instance.
evaluator - The expression evaluator for this instance.
Since:
0.7
See Also:
Context, Evaluator
Method Detail

fireEvent

public boolean fireEvent(String event)
Fire an event on the SCXML engine.

Parameters:
event - The event name.
Returns:
Whether the state machine has reached a "final" configuration.

getStateMachine

public static SCXML getStateMachine()
Deprecated. Returns null, use getEngine().getStateMachine() instead

Get the SCXML object representing this state machine.

Returns:
Returns the stateMachine.

getEngine

public SCXMLExecutor getEngine()
Get the SCXML engine driving the "lifecycle" of the instances of this class.

Returns:
Returns the engine.

getLog

public org.apache.commons.logging.Log getLog()
Get the log for this class.

Returns:
Returns the log.

setLog

public void setLog(org.apache.commons.logging.Log log)
Set the log for this class.

Parameters:
log - The log to set.

invoke

public boolean invoke(String methodName)
Invoke the no argument method with the following name.

Parameters:
methodName - The method to invoke.
Returns:
Whether the invoke was successful.

resetMachine

public boolean resetMachine()
Reset the state machine.

Returns:
Whether the reset was successful.

logError

protected void logError(Exception exception)
Utility method for logging error.

Parameters:
exception - The exception leading to this error condition.


Copyright © 2005-2008 The Apache Software Foundation. All Rights Reserved.