You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Anna Klisiewicz <an...@googlemail.com> on 2008/08/19 01:14:52 UTC

SCXML and data structures

Hi,

Is it possible to initialize data structures like stack or queue as elements
of <data> in SXML code?

Thanks,
Anna

Re: SCXML and data structures

Posted by Anna Klisiewicz <an...@googlemail.com>.
Has anyone have some examples of e code which uses data structures in <data>
element at least? This problem stops me from further progress in my project,
so I would be very grateful.

Anna

Re: SCXML and data structures

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Aug 20, 2008 at 10:00 PM, Anna Klisiewicz
<an...@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 <ra...@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


Re: SCXML and data structures

Posted by Anna Klisiewicz <an...@googlemail.com>.
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...

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.

2008/8/19 Rahul Akolkar <ra...@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

Re: SCXML and data structures

Posted by Rahul Akolkar <ra...@gmail.com>.
On Mon, Aug 18, 2008 at 7:14 PM, Anna Klisiewicz
<an...@googlemail.com> wrote:
> Hi,
>
> Is it possible to initialize data structures like stack or queue as elements
> of <data> in SXML code?
>
<snip/>

I'm short on time this week, so I'll try to point to some existing
docs. See bit on contexts and evaluators (on how to get the said data
structures initialized), as well as method invocation (on how to
perform operations on the said data structures):

  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)

-Rahul


> Thanks,
> Anna
>

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