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 <datamodel> and data structures
Date Sun, 24 Aug 2008 16:49:31 GMT
On Wed, Aug 20, 2008 at 10:00 PM, Anna Klisiewicz
<anna.klisiewicz@googlemail.com> wrote:
> Tkank you Rahul for answer. I am sorry but I have to ask you for more
> explicit answer as I read the documentation and I still do not really know
> how to initialize those data stractures. I whish there were more examples
> avaliable...
>
<snip/>

Please continue to ask questions, thats no problem at all. At the end
of this thread, if you feel there is an example that makes things
clearer, please write it up and post it to JIRA we'll be happy to
consider adding it to the documentation.


> What should I do inside sxml code like:
>
> <datamodel>
>    <data>
>        <data1></data1>
>        <data2></data2>
>    </data>
> </datamodel>
>
> if I want data1 and data2 to be stacks.
>
<snap/>

What the <datamodel> element does is create variables in the
underlying context for the state (or the root document). So, for
example, this snippet of code ...

<scxml ...>

    <datamodel>
        <data name="foo">
            <root xmlns="">
                <!-- some application XML data -->
            </root>
        </data>
    </datamodel>

    <!-- states etc. -->

</scxml>

... creates a variable "foo" in the root context of the state machine
instance (root since its child of <scxml>, rather than any state)
whose value starts off as being the DOM Node containing pertinent
application data (as indicated by the comment above). I say starts off
because this value can be manipulated as the state machine progresses,
so in that sense it is a "live" copy of the data.

Commons SCXML also allows you to interact with the contexts (root, or
otherwise) programmatically. This is useful for injecting non-XML
data. So, given that you want data1 and data2 to be stacks, that would
look like:

    SCXMLExecutor exec;

    // Initialize the above executor appropriately

    exec.getRootContext().set("data1", new Stack());
    exec.getRootContext().set("data2", new Stack());

    // Set executor in motion

    try {
        exec.go();
    } catch (ModelException me) {
        // app-specific exception handling
    }

Given the above, the state machine definition itself (SCXML document)
could now use the above data structures as follows (say on entering
state "bar" you want to pop stack "data1" and do something with the
popped data):

    <state id="bar">
        <onentry>
            <cs:var name="data1item" expr="data1.pop()" />
            <!-- do something with 'data1item' -->
        </onentry>
        <!-- other comments of state 'bar' -->
    </state>

Note that it is possible to get the behavior of a stack purely using
XML data and SCXML actions (such as <assign>) but that discussion is
best saved for another time.

Finally, towards your question about JSP EL vs. JEXL in your original
email below, I'd recommend using JEXL (it doesn't appear your usecase
has anything to do with JSPs).

-Rahul


> 2008/8/19 Rahul Akolkar <rahul.akolkar@gmail.com>
>
>> <http://commons.apache.org/scxml/guide/contexts-evaluators.html>
>> To summarize, each context is populated by a combination of:
>>  * <data> elements at the corresponding location in the SCXML document
>>  * programmatic population using data structures that make sense to
>> the EL in use -- via Context#set(String, Object)
>
>
> What the Contex corresponds to? How to set it to point on data1 or data2.
> What is the "String" and "Object" in this case?
> I would like to use jsp and what would you advise, jsp or jexl?
>
> Thank you in advance,
> Anna
>

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


Mime
View raw message