commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Akolkar <rahul.akol...@gmail.com>
Subject Re: [scxml] templating/src/xinclude and returning a value(through datamodel/donedata)
Date Thu, 06 May 2010 16:52:56 GMT
On Thu, May 6, 2010 at 11:34 AM, Fabrizio Morbini <fmorbini@gmail.com> wrote:
> Hi, i'm experimenting with the src attribute to reuse fsm. I'm having
> some trouble with returning a value from an included fsm to the
> calling state.
>
> I'm using this description at
> http://shale.apache.org/shale-dialog-scxml/index.html, in particular
> the section about subdialogs from which it seems possible to return a
> value from an included scxml fsm.
> However i have been unable to do so. I've tried several variants but
> none with the expected outcome.
<snip/>

The Commons SCXML v0.9 release does not use a flat / global datamodel
by default, therefore the value would need to be copied up to a
datamodel with a superior position in the states topology (such as
document root to be available across any other state). I will outline
this approach using your example below.

Alternatively, provide the SCXMLExecutor with a custom Evaluator
implementation that returns the same context (the root context) on
every Evaluator#newContext() call to obtain a flat datamodel. If you
do this, there would be no changes required to the example below.

Now, for the first approach with the default cascading datamodel, see below:


> Here is the current variant:
>
> =============file a.scxml=====================================
> <?xml version="1.0"?>
> <scxml xmlns="http://www.w3.org/2005/07/scxml"
>                xmlns:cs="http://commons.apache.org/scxml"
>       version="1.0"
>       profile="ecmascript"
>       initial="s1">
>
>  <!--  trivial 5 second microwave oven example -->
>  <!--  see http://commons.apache.org/scxml/guide/datamodel.html for
> different way to access the datamodel -->
>  <datamodel>
>    <data id="cook_time" expr="10"/>
<snap/>

Define a global 'aaa' variable here, say like so (note different case
used here, i.e. chose a different name of choice):

    <data id="AAA" />


>  </datamodel>
>
>  <state id="s1">
>    <!-- off state -->
>    <transition target="s2"/>
>  </state>
>
>  <state id="s2" src="b.scxml#s111">
>
>    <!-- on/pause state -->
>
>    <transition event="s2.done" cond="aaa eq 's3'" target="s3"/>
>    <transition event="s2.done" cond="aaa eq 's4'" target="s4"/>
>    <transition event="s2.done" target="s5"/>
>
>  </state>
>
>    <final id="s3"/>
>    <final id="s4"/>
>    <final id="s5"/>
> </scxml>
> =============end of file a.scxml==============================
>
> =============file b.scxml=====================================
> <?xml version="1.0" encoding="us-ascii"?>
> <scxml version="1.0" xmlns="http://www.w3.org/2005/07/scxml"
> xmlns:cs="http://commons.apache.org/scxml" initial="s111">
>        <state id="s111">
>        <initial><transition target="s11"/></initial>
>        <datamodel><data id="aaa"/></datamodel>
>
>    <state id="s11">
>                <transition target="s12">
>                                <!--<cs:var name="aaa" expr="'s3'"
/>-->
>                                <assign location="aaa" expr="'s3'"/>
<snip/>

Change the above to point to the variable defined in the parent
document above like so:

        <assign location="AAA" expr="'s3'"/>

Obviously, this would imply that b.scxml could only be executed when
included in a.scxml since it references a datamodel variable in
a.scxml. If that is not desired, the second approach i.e. the flat
datamodel approach should be used.


>                </transition>
>    </state>
>
>        <final id="s12">
>        </final>
>        </state>
> </scxml>
> =============end of file b.scxml==============================
>
> i tried to use also <var> instead of a previously defined variable in
> the datamodel, without success.
>
> the simple way would be to use the donedata in a final state in the
> included fsm but it doesn't seem that donedata is supported, is this
> correct?
>
<snap/>

Yes, not in v0.9, we will look to add it soon. You could open a JIRA
issue as a reminder.


> given that src is not going to be supported in the next standard, do
> you have some pointer to examples/doc of how to use xinclude to do
> what the src is supposed to do?
>
<snip/>

Don't have a ready example, but the idea is to pull in as much of the
document as needs to be reused using XInclude. See XInclude
specification for more details. It certain cases, the XInclude
approach requires more work but is favored since its a standard way to
do includes.

-Rahul


> thanks,
> fabrizio.
>

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


Mime
View raw message