You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2006/05/20 00:28:20 UTC

[Jakarta-commons Wiki] Update of "SCXML/Tutorials/History - Remembering State Information" by FasihullahAskiri

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by FasihullahAskiri:
http://wiki.apache.org/jakarta-commons/SCXML/Tutorials/History_-_Remembering_State_Information

New page:
## page was renamed from SCXML/HomePage/Tutorials/Templating
##language:en
== A tutorial on SCXML History Element ==
An SCXML with a complex state (A state with substates/parallel elements) can be made to preserve its state information on exit. When a complex state with a ''history'' is entered again, it enters the state it was last in rather than the initial state which it would have otherwise entered.

=== Use Case ===
To define an ''error-handler''. In many cases, it might be desirable to have the error-handling logic at one place which can be re-used in all the error conditions. Normally, the flow would be,
action1-state [act] do action1 on error do error-handling back to action1-state else
action2-state [act] do action1 on error do error-handling back to action2-state else
action3-state [act] do action1 on error do error-handling back to action3-state else

=== Example based on the use case above ===
{{{
<scxml
  xmlns="http://www.w3.org/2005/07/SCXML"
  version="1.0" 
  xmlns:somespace="http://stack.mera.com/CCXML"
  initialstate="action1-state">

  <state id="action1-state">
    <transition event="act" target="action2-state"/>
  </state>
  <state id="action2-state">
    <onentry>
      <somespace:some-action/>
    </onentry>
    <transition event="act" target="action3-state"/>
    <transition event="application.error" target="action2-error-handler"/>
  </state>
  <state id="action3-state">
    <onentry>
      <somespace:some-action/>
    </onentry>
    <transition event="act" target="action4-state"/>
    <transition event="application.error" target="action3-error-handler"/>
  </state>
  <state id="action4-state" final="true"/>
  <state id="action2-error-handler">
    <onentry>
      <somespace:handle-error/>
    </onentry>
    <transition target="action2-state"/>
  </state>
  <state id="action3-error-handler">
    <onentry>
      <somespace:handle-error/>
    </onentry>
    <transition target="action3-state"/>
  </state>
  <state id="action4-state" final="true"/>
</scxml>

}}} 
=== SCXML Using history element ===

{{{
<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/SCXML"
       xmlns:my="http://my.custom-actions.domain/CUSTOM"
       version="1.0"
       initialstate="universe">
    <state id="universe">
    	<initial>
    		<transition target="history-actions"/>
    	</initial>
    	<transition event="application.error" target="error-handler"/>
    	<history type="deep" id="history-actions">
   			<transition target="action-1"/>
		</history>
		<state id="action-1">
			<transition event="action.done" target="action-2"/>
		</state>
		<state id="action-2">
   			<transition event="action.done" target="action-3"/>
   		</state>
		<state id="action-3" final="true"/>
	</state>
  	<state id="error-handler">
		<transition event="error.handled" target="universe"/>
	</state>
</scxml>
}}}
=== Explanation ===
TODO
=== Source Code ===
TODO

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org