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 ModelException
s and the like. Most methods
are protected
for ease of subclassing.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractStateMachine.EntryListener
A SCXMLListener that is only concerned about "onentry"
notifications.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
public AbstractStateMachine(URL scxmlDocument) throws ModelException
scxmlDocument
- The URL pointing to the SCXML document that
describes the "lifecycle" of the
instances of this class.ModelException
public AbstractStateMachine(URL scxmlDocument, Context rootCtx, Evaluator evaluator) throws ModelException
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.ModelException
Context
,
Evaluator
public AbstractStateMachine(SCXML stateMachine) throws ModelException
stateMachine
- The parsed SCXML instance that
describes the "lifecycle" of the
instances of this class.ModelException
public AbstractStateMachine(SCXML stateMachine, Context rootCtx, Evaluator evaluator) throws ModelException
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.ModelException
Context
,
Evaluator
public boolean fireEvent(String event)
event
- The event name.public SCXMLExecutor getEngine()
public org.apache.commons.logging.Log getLog()
public void setLog(org.apache.commons.logging.Log log)
log
- The log to set.public boolean invoke(String methodName)
methodName
- The method to invoke.public boolean resetMachine()
Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.