public class SCXMLSemanticsImpl extends Object implements SCXMLSemantics
Custom semantics can be created by sub-classing this implementation.
This implementation is full stateless and all methods are public accessible to make it easier to extend, reuse and test its behavior.
Modifier and Type | Field and Description |
---|---|
static String |
ERR_ILLEGAL_ALLOC
Suffix for error event that are triggered in reaction to invalid data
model locations.
|
Constructor and Description |
---|
SCXMLSemanticsImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addAncestorStatesToEnter(SCXMLExecutionContext exctx,
Step step,
TransitionTarget tt,
TransitionTarget ancestor)
This method corresponds to the Algorithm for SCXML processing addAncestorStatesToEnter() procedure.
|
void |
addDescendantStatesToEnter(SCXMLExecutionContext exctx,
Step step,
TransitionTarget tt)
This method corresponds to the Algorithm for SCXML processing addDescendantStatesToEnter() procedure.
|
void |
buildStep(SCXMLExecutionContext exctx,
Step step)
buildStep builds the exitSet and entrySet for the current configuration given the transitionList on the step.
|
void |
computeEntrySet(SCXMLExecutionContext exctx,
Step step)
Compute and store the set of states to enter for the current list of transitions in the provided step.
|
void |
computeExitSet(SimpleTransition transition,
Set<EnterableState> exitSet,
Set<EnterableState> activeStates)
Compute and store the set of states to exit for one specific transition in the provided step.
|
void |
computeExitSet(Step step,
StateConfiguration stateConfiguration)
Compute and store the set of states to exit for the current list of transitions in the provided step.
|
boolean |
containsDescendant(Set<EnterableState> states,
EnterableState state) |
void |
enterStates(SCXMLExecutionContext exctx,
Step step,
Set<TransitionalState> statesToInvoke)
This method corresponds to the Algorithm for SCXML processing enterStates() procedure, where the states to enter
already have been pre-computed in
microStep(SCXMLExecutionContext, Step, java.util.Set) . |
void |
executeContent(SCXMLExecutionContext exctx,
Executable exec)
Executes the executable content for a specific executable in the micro step
|
void |
executeGlobalScript(SCXMLExecutionContext exctx)
Executes the global SCXML script element
|
void |
executeTransitionContent(SCXMLExecutionContext exctx,
Step step)
Executes the executable content for all transitions in the micro step
|
void |
exitStates(SCXMLExecutionContext exctx,
Step step,
Set<TransitionalState> statesToInvoke)
This method corresponds to the Algorithm for SCXML processing exitStates() procedure, where the states to exit
already have been pre-computed in
microStep(SCXMLExecutionContext, Step, java.util.Set) . |
void |
finalStep(SCXMLExecutionContext exctx)
The final step in the execution of an SCXML state machine.
|
void |
firstStep(SCXMLExecutionContext exctx)
First step in the execution of an SCXML state machine.
|
void |
initiateInvokes(SCXMLExecutionContext exctx,
Set<TransitionalState> statesToInvoke)
Initiate any new invoked activities.
|
boolean |
isCancelEvent(TriggerEvent event)
Check if an external event indicates the state machine execution must be cancelled.
|
boolean |
isInFinalState(EnterableState es,
Set<EnterableState> configuration)
This method corresponds to the Algorithm for SCXML processing isFinalState() function.
|
boolean |
isInvokerEvent(String invokerId,
TriggerEvent event)
Checks if an external event was send (back) by an specific Invoker
|
boolean |
isLegalConfiguration(Set<EnterableState> states,
ErrorReporter errRep)
Checks whether a given set of states is a legal Harel State Table
configuration (with the respect to the definition of the OR and AND
states).
|
void |
macroStep(SCXMLExecutionContext exctx,
Set<TransitionalState> statesToInvoke)
Perform a macro step in the execution of a state machine.
|
boolean |
matchTransition(SCXMLExecutionContext exctx,
Transition transition,
String eventName) |
void |
microStep(SCXMLExecutionContext exctx,
Step step,
Set<TransitionalState> statesToInvoke)
Perform a micro step in the execution of a state machine.
|
void |
nextStep(SCXMLExecutionContext exctx,
TriggerEvent event)
Next step in the execution of an SCXML state machine.
|
SCXML |
normalizeStateMachine(SCXML input,
ErrorReporter errRep)
Optional post processing immediately following SCXMLReader.
|
void |
notifyOnTransition(SCXMLExecutionContext exctx,
Transition t,
TransitionTarget target)
Notifies SCXMLListeners on the transition taken
|
void |
processInvokes(SCXMLExecutionContext exctx,
TriggerEvent event)
Forward events to invoked activities, execute finalize handlers.
|
void |
recordHistory(Step step,
Set<EnterableState> atomicStates,
Set<EnterableState> activeStates)
Record the history configurations for states to exit if applicable and temporarily store this in the step.
|
void |
removeConflictingTransitions(SCXMLExecutionContext exctx,
Step step,
List<Transition> enabledTransitions)
This method corresponds to the Algorithm for SCXML processing removeConflictingTransitions() procedure.
|
void |
selectTransitions(SCXMLExecutionContext exctx,
Step step)
This method corresponds to the Algorithm for SCXML processing selectTransitions() as well as the
selectEventlessTransitions() procedure, depending on the event (or null) in the provided step
|
void |
setSystemEventVariable(SCInstance scInstance,
TriggerEvent event,
boolean internal)
Stores the provided event in the system context
For the event a EventVariable is instantiated and the provided event its type is mapped to the one of the
SCXML specification predefined types.
|
public static final String ERR_ILLEGAL_ALLOC
public SCXMLSemanticsImpl()
public SCXML normalizeStateMachine(SCXML input, ErrorReporter errRep)
normalizeStateMachine
in interface SCXMLSemantics
input
- SCXML state machineerrRep
- ErrorReporter callbackpublic void firstStep(SCXMLExecutionContext exctx) throws ModelException
This will first (re)initialize the state machine instance, destroying any existing state!
The first step is corresponding to the Algorithm for SCXML processing from the interpret() procedure to the mainLoop() procedure up to the blocking wait for an external event.
This step will thus complete the SCXML initial execution and a subsequent macroStep to stabilize the state machine again before returning.
If the state machine no longer is running after all this, first the finalStep(SCXMLExecutionContext)
will be called for cleanup before returning.
firstStep
in interface SCXMLSemantics
exctx
- The execution context for this stepModelException
- if the state machine instance failed to initialize or a SCXML model error occurred during
the execution.public void nextStep(SCXMLExecutionContext exctx, TriggerEvent event) throws ModelException
The next step is corresponding to the Algorithm for SCXML processing mainEventLoop() procedure after receiving an external event, up to the blocking wait for another external event.
If the state machine isn't SCXMLExecutionContext.isRunning()
(any more), invoking this method will simply
do nothing.
If the provided event is a TriggerEvent.CANCEL_EVENT
, the state machine will stop running.
Otherwise, the event is set in the SCXMLSystemContext
and processing of the event then is started, and
if the event leads to any transitions a microStep for this event will be performed, followed up by a macroStep
to stabilize the state machine again before returning.
If the state machine no longer is running after all this, first the finalStep(SCXMLExecutionContext)
will be called for cleanup before returning.
nextStep
in interface SCXMLSemantics
exctx
- The execution context for this stepevent
- The event to processModelException
- if a SCXML model error occurred during the execution.public void finalStep(SCXMLExecutionContext exctx) throws ModelException
This final step is corresponding to the Algorithm for SCXML processing exitInterpreter() procedure, after the state machine stopped running.
If the state machine still is SCXMLExecutionContext.isRunning()
invoking this method will simply
do nothing.
This final step will exit all remaining active states and cancel any active invokers.
TODO: the current implementation does not yet provide final donedata handling.
finalStep
in interface SCXMLSemantics
exctx
- The execution context for this stepModelException
- if a SCXML model error occurred during the execution.public void microStep(SCXMLExecutionContext exctx, Step step, Set<TransitionalState> statesToInvoke) throws ModelException
This micro step is corresponding to the Algorithm for SCXML processing microstep() procedure.
exctx
- The execution context for this stepstep
- The current micro stepstatesToInvoke
- the set of activated states which invokes need to be invoked at the end of the current
macro stepModelException
- if a SCXML model error occurred during the execution.public void buildStep(SCXMLExecutionContext exctx, Step step) throws ModelException
exctx
- The SCXML execution contextstep
- The step containing the list of transitions to be takenModelException
- if the result of taking the transitions would lead to an illegal configurationpublic void macroStep(SCXMLExecutionContext exctx, Set<TransitionalState> statesToInvoke) throws ModelException
This macro step is corresponding to the Algorithm for SCXML processing mainEventLoop() procedure macro step sub-flow, which are the first 3 steps of the described 4, so everything up to the blocking wait for an external event.
exctx
- The execution context for this stepstatesToInvoke
- the set of activated states which invokes need to be invoked at the end of the current
macro stepModelException
- if a SCXML model error occurred during the execution.public void computeExitSet(Step step, StateConfiguration stateConfiguration)
This method corresponds to the Algorithm for SCXML processing computeExitSet() procedure.
step
- The step containing the list of transitions to be takenstateConfiguration
- The current configuration of the state machine (SCInstance.getStateConfiguration()
).public void computeExitSet(SimpleTransition transition, Set<EnterableState> exitSet, Set<EnterableState> activeStates)
This method corresponds to the Algorithm for SCXML processing computeExitSet() procedure.
transition
- The transition to compute the states to exit fromexitSet
- The set for adding the states to exit toactiveStates
- The current active states of the state machine (StateConfiguration.getActiveStates()
).public void recordHistory(Step step, Set<EnterableState> atomicStates, Set<EnterableState> activeStates)
These history configurations must be pre-recorded as they might impact (re)entrance calculation during
computeEntrySet(SCXMLExecutionContext, Step)
.
Only after the new configuration has been validated (see: isLegalConfiguration(Set, ErrorReporter)
), the
history configurations will be persisted during the actual exitStates(SCXMLExecutionContext, Step, Set)
processing.
step
- The step containing the list of states to exit, and the map to record the new history configurationsatomicStates
- The current set of active atomic states in the state machineactiveStates
- The current set of all active states in the state machinepublic void computeEntrySet(SCXMLExecutionContext exctx, Step step)
This method corresponds to the Algorithm for SCXML processing computeEntrySet() procedure.
exctx
- The execution context for this stepstep
- The step containing the list of transitions to be takenpublic void addDescendantStatesToEnter(SCXMLExecutionContext exctx, Step step, TransitionTarget tt)
exctx
- The execution context for this stepstep
- The steptt
- The TransitionTargetpublic void addAncestorStatesToEnter(SCXMLExecutionContext exctx, Step step, TransitionTarget tt, TransitionTarget ancestor)
exctx
- The execution context for this stepstep
- The steptt
- The TransitionTargetancestor
- The ancestor TransitionTargetpublic boolean containsDescendant(Set<EnterableState> states, EnterableState state)
states
- the set of states to check for descendantsstate
- the state to check withpublic void selectTransitions(SCXMLExecutionContext exctx, Step step) throws ModelException
exctx
- The execution context for this stepstep
- The stepModelException
public void removeConflictingTransitions(SCXMLExecutionContext exctx, Step step, List<Transition> enabledTransitions)
exctx
- The execution context for this stepstep
- The stepenabledTransitions
- The list of enabled transitionspublic boolean matchTransition(SCXMLExecutionContext exctx, Transition transition, String eventName)
exctx
- The execution context for this steptransition
- The transitioneventName
- The (optional) event name to match againstpublic boolean isInFinalState(EnterableState es, Set<EnterableState> configuration)
es
- the enterable state to checkconfiguration
- the current state machine configurationpublic boolean isInvokerEvent(String invokerId, TriggerEvent event)
invokerId
- the invokerIdevent
- received external eventpublic boolean isCancelEvent(TriggerEvent event)
event
- received external eventTriggerEvent.CANCEL_EVENT
.public boolean isLegalConfiguration(Set<EnterableState> states, ErrorReporter errRep)
isLegalConfiguration
in interface SCXMLSemantics
states
- a set of stateserrRep
- ErrorReporter to report detailed error info if neededpublic void setSystemEventVariable(SCInstance scInstance, TriggerEvent event, boolean internal)
For the event a EventVariable is instantiated and the provided event its type is mapped to the one of the SCXML specification predefined types.
scInstance
- the state machine instance holding the system contextevent
- The event being storedinternal
- Flag indicating the event was received internally or externallypublic void executeGlobalScript(SCXMLExecutionContext exctx) throws ModelException
exctx
- The execution contextModelException
- if a SCXML model error occurred during the execution.public void exitStates(SCXMLExecutionContext exctx, Step step, Set<TransitionalState> statesToInvoke) throws ModelException
microStep(SCXMLExecutionContext, Step, java.util.Set)
.exctx
- The execution context for this micro stepstep
- the stepstatesToInvoke
- the set of activated states which invokes need to be invoked at the end of the current
macro stepModelException
- if a SCXML model error occurred during the execution.public void executeTransitionContent(SCXMLExecutionContext exctx, Step step) throws ModelException
exctx
- The execution context for this micro stepstep
- the stepModelException
- if a SCXML model error occurred during the execution.public void executeContent(SCXMLExecutionContext exctx, Executable exec) throws ModelException
exctx
- The execution context for this micro stepexec
- the executable providing the execution contentModelException
- if a SCXML model error occurred during the execution.public void notifyOnTransition(SCXMLExecutionContext exctx, Transition t, TransitionTarget target)
exctx
- The execution context for this micro stept
- The Transition takentarget
- The target of the Transitionpublic void enterStates(SCXMLExecutionContext exctx, Step step, Set<TransitionalState> statesToInvoke) throws ModelException
microStep(SCXMLExecutionContext, Step, java.util.Set)
.exctx
- The execution context for this micro stepstep
- the stepstatesToInvoke
- the set of activated states which invokes need to be invoked at the end of the current
macro stepModelException
- if a SCXML model error occurred during the execution.public void initiateInvokes(SCXMLExecutionContext exctx, Set<TransitionalState> statesToInvoke) throws ModelException
exctx
- provides the execution contextstatesToInvoke
- the set of activated states which invokes need to be invokedModelException
public void processInvokes(SCXMLExecutionContext exctx, TriggerEvent event) throws ModelException
exctx
- provides the execution contextevent
- The events to be forwardedModelException
- in case there is a fatal SCXML object model problem.Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.