You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Linda Erlenhov <li...@gmail.com> on 2009/05/05 13:53:39 UTC

[SCXML] Polling in datamodel

Hello.
I´m back with another thousand questions!

Still with my datamodel like this:
------------------------------------
<scxml version="1.0" initialstate="176" xmlns:cs="
http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml">

<datamodel>
<data name="DynamicData">
<Data_1 xmlns="" id="1" type="Integer">0</Data_1>
<Data_2 xmlns="" id="2" type="Integer">0</Data_2>
<Data_3 xmlns="" id="3" type="String">none</Data_2>
</data>
<data name="DDChange"/>
<data name="DDValue"/>
<data name="DDType"/>
<data name="Indication_1" expr="false"/>
</datamodel>
.......................................snip.......
Later on i set the data:
...........................................snip.....
<state id="StateB">
<onentry>
<log label="Renegade" expr="'Entering state: StateB'"/>
<log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
<assign location="Data(DynamicData,'Data_1')"
expr="Data(DynamicData,'Data_1')+1"/>
<assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
<assign name="DDChange" expr="'Data_1'"/>
<log label="Renegade" expr="Data(DynamicData,'Data_1')"/>

</onentry>
..........snip--------------------

So now here´s the problem.

As you see I haven´t used the custom action, but an rather ugly hack where I
do an assign name after I do the assign location to trigger a call to the
"set" function in the context.

In this version I also do another assign where I assign another name with
the value. All my data are named Data_XX so i screen the calls to set byt
looking for the ones that are named Data_XX. When I recieve a call for
Data_XX I would like to know what the value is, which I in this case have
solved by assigning another variable with it earlier, when i get a "set"
call named Data_xx i know that the variable DDValue contains the value of
this data. Not pretty, but OK and working so far.
Now I would like to be able to see what "type" the data is aswell. How do I
do that? And: Is there a less spaghetti way to poll the value of the data
from where I am (In the context) when I have the "name" of it. (The name in
this case is Data_1, Data_2 or Data_3, I also know that the data=name is
DynamicData) .

Due to lack of time I would prefer if i wouldn´t have to "redo" to much of
the scxml, but is this possible to do it my way otherwise? Or do I have to
do it over.

Best Regards
//Linda

Re: [SCXML] Polling in datamodel

Posted by Ingmar Kliche <in...@googlemail.com>.
Hi Linda,
I'm not sure if I understood how you integrate with the environment and
whether my hints are useful. But if you look into assign's implementation
(method execute())

http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Assign.java?view=markup

you'll see that "assign location" calls the evalLocation() method at the
evaluator. There you have the DOM nodes. evalLocation() is used to retrieve
the DOM nodes for "location" and "expr" (here is the implementation of the
JexlEvaluator:
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java?view=markup)
and assign's execute() then manuipulates the DOM Node directly (removes old
children and adds new children).

Again, I don't know if this solves your problem, but may be it helps...

Regards,
Ingmar.


2009/5/11 Linda Erlenhov <li...@gmail.com>

> Hello!
>
> The thing here is that the value is never a DOM node. Hence my question. I
> previousley asked why the "assign location" didn´t call for the "set"
> function in the Context and got the answere that the "assign location"
> doesn´t work as "assign name", "assign name" calls the set function and
> sets
> a variable, "assign location" manipulates the XML tree as it is. The advice
> was to make an "custom action" instead or do the ugly hack I did: do an
> "assign name" with the name after the "assign location" has executed.
> What I wanted to know is if there is any way of fetching the "tree" or
> whatever it is to get the data associatet to a name, according to the model
> below.
> If you look at my example below, I will always "know" the name of the
> datamodel in this case: "DynamicData", and I will recieve the "name" of the
> specific tag in this data, in this case "Data_1", "Data_2" or "Data_3". In
> my model below I have done an ugly way of finding out what the value is but
> i realized that that was not enough, i need to know the "type" aswell. And
> that I don´t know how to find.
>
> Does anybody have a solution to this, or some kind of idea on how to solve
> this?
>
> best regards
> //Linda
>
> On Tue, May 5, 2009 at 3:50 PM, Ingmar Kliche
> <in...@googlemail.com>wrote:
>
> > Linda,
> > you should be able to use the DOM API to read the values. In
> > context.set(name, value) you should check whether the value is a DOM
> node:
> >
> > import import org.w3c.dom.Node;
> >
> > ...
> > ... set(String name, Object value) {
> >
> >        if (value instanceof Node) {
> >            Node nodeValue = (Node) value;
> >        }
> >
> > scope.put(name, scope, value);
> >
> >
> > 2009/5/5 Linda Erlenhov <li...@gmail.com>
> >
> > > Hello.
> > > I´m back with another thousand questions!
> > >
> > > Still with my datamodel like this:
> > > ------------------------------------
> > > <scxml version="1.0" initialstate="176" xmlns:cs="
> > > http://commons.apache.org/scxml" xmlns="
> http://www.w3.org/2005/07/scxml
> > ">
> > >
> > > <datamodel>
> > > <data name="DynamicData">
> > > <Data_1 xmlns="" id="1" type="Integer">0</Data_1>
> > > <Data_2 xmlns="" id="2" type="Integer">0</Data_2>
> > > <Data_3 xmlns="" id="3" type="String">none</Data_2>
> > > </data>
> > > <data name="DDChange"/>
> > > <data name="DDValue"/>
> > > <data name="DDType"/>
> > > <data name="Indication_1" expr="false"/>
> > > </datamodel>
> > > .......................................snip.......
> > > Later on i set the data:
> > > ...........................................snip.....
> > > <state id="StateB">
> > > <onentry>
> > > <log label="Renegade" expr="'Entering state: StateB'"/>
> > > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> > > <assign location="Data(DynamicData,'Data_1')"
> > > expr="Data(DynamicData,'Data_1')+1"/>
> > > <assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
> > > <assign name="DDChange" expr="'Data_1'"/>
> > > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> > >
> > > </onentry>
> > > ..........snip--------------------
> > >
> > > So now here´s the problem.
> > >
> > > As you see I haven´t used the custom action, but an rather ugly hack
> > where
> > > I
> > > do an assign name after I do the assign location to trigger a call to
> the
> > > "set" function in the context.
> > >
> > > In this version I also do another assign where I assign another name
> with
> > > the value. All my data are named Data_XX so i screen the calls to set
> byt
> > > looking for the ones that are named Data_XX. When I recieve a call for
> > > Data_XX I would like to know what the value is, which I in this case
> have
> > > solved by assigning another variable with it earlier, when i get a
> "set"
> > > call named Data_xx i know that the variable DDValue contains the value
> of
> > > this data. Not pretty, but OK and working so far.
> > > Now I would like to be able to see what "type" the data is aswell. How
> do
> > I
> > > do that? And: Is there a less spaghetti way to poll the value of the
> data
> > > from where I am (In the context) when I have the "name" of it. (The
> name
> > in
> > > this case is Data_1, Data_2 or Data_3, I also know that the data=name
> is
> > > DynamicData) .
> > >
> > > Due to lack of time I would prefer if i wouldn´t have to "redo" to much
> > of
> > > the scxml, but is this possible to do it my way otherwise? Or do I have
> > to
> > > do it over.
> > >
> > > Best Regards
> > > //Linda
> > >
> >
>

Re: [SCXML] Polling in datamodel

Posted by Rahul Akolkar <ra...@gmail.com>.
On Mon, May 11, 2009 at 9:28 AM, Linda Erlenhov
<li...@gmail.com> wrote:
> Hello!
>
> The thing here is that the value is never a DOM node. Hence my question. I
> previousley asked why the "assign location" didn´t call for the "set"
> function in the Context and got the answere that the "assign location"
> doesn´t work as "assign name", "assign name" calls the set function and sets
> a variable, "assign location" manipulates the XML tree as it is. The advice
> was to make an "custom action" instead or do the ugly hack I did: do an
> "assign name" with the name after the "assign location" has executed.
> What I wanted to know is if there is any way of fetching the "tree" or
> whatever it is to get the data associatet to a name, according to the model
> below.
> If you look at my example below, I will always "know" the name of the
> datamodel in this case: "DynamicData", and I will recieve the "name" of the
> specific tag in this data, in this case "Data_1", "Data_2" or "Data_3". In
> my model below I have done an ugly way of finding out what the value is but
> i realized that that was not enough, i need to know the "type" aswell. And
> that I don´t know how to find.
>
<snip/>

XPath into it. TBH, I'm losing track of the example, but if you want
to stay the course of the example below, DDType can be found as
follows (third assign, first two copied as-is for code context):

<assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
<assign name="DDChange" expr="'Data_1'"/>
<assign name="DDType" expr="'Data(DynamicData,'Data_1/@type')'"/>

Programmatically, you could also use Context#get('DynamicData') to get
the <data> DOM Node and when you know the tag name, you can use the
Java XPath API to XPath into it.

-Rahul



> Does anybody have a solution to this, or some kind of idea on how to solve
> this?
>
> best regards
> //Linda
>
> On Tue, May 5, 2009 at 3:50 PM, Ingmar Kliche
> <in...@googlemail.com>wrote:
>
>> Linda,
>> you should be able to use the DOM API to read the values. In
>> context.set(name, value) you should check whether the value is a DOM node:
>>
>> import import org.w3c.dom.Node;
>>
>> ...
>> ... set(String name, Object value) {
>>
>>        if (value instanceof Node) {
>>            Node nodeValue = (Node) value;
>>        }
>>
>> scope.put(name, scope, value);
>>
>>
>> 2009/5/5 Linda Erlenhov <li...@gmail.com>
>>
>> > Hello.
>> > I´m back with another thousand questions!
>> >
>> > Still with my datamodel like this:
>> > ------------------------------------
>> > <scxml version="1.0" initialstate="176" xmlns:cs="
>> > http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml
>> ">
>> >
>> > <datamodel>
>> > <data name="DynamicData">
>> > <Data_1 xmlns="" id="1" type="Integer">0</Data_1>
>> > <Data_2 xmlns="" id="2" type="Integer">0</Data_2>
>> > <Data_3 xmlns="" id="3" type="String">none</Data_2>
>> > </data>
>> > <data name="DDChange"/>
>> > <data name="DDValue"/>
>> > <data name="DDType"/>
>> > <data name="Indication_1" expr="false"/>
>> > </datamodel>
>> > .......................................snip.......
>> > Later on i set the data:
>> > ...........................................snip.....
>> > <state id="StateB">
>> > <onentry>
>> > <log label="Renegade" expr="'Entering state: StateB'"/>
>> > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
>> > <assign location="Data(DynamicData,'Data_1')"
>> > expr="Data(DynamicData,'Data_1')+1"/>
>> > <assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
>> > <assign name="DDChange" expr="'Data_1'"/>
>> > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
>> >
>> > </onentry>
>> > ..........snip--------------------
>> >
>> > So now here´s the problem.
>> >
>> > As you see I haven´t used the custom action, but an rather ugly hack
>> where
>> > I
>> > do an assign name after I do the assign location to trigger a call to the
>> > "set" function in the context.
>> >
>> > In this version I also do another assign where I assign another name with
>> > the value. All my data are named Data_XX so i screen the calls to set byt
>> > looking for the ones that are named Data_XX. When I recieve a call for
>> > Data_XX I would like to know what the value is, which I in this case have
>> > solved by assigning another variable with it earlier, when i get a "set"
>> > call named Data_xx i know that the variable DDValue contains the value of
>> > this data. Not pretty, but OK and working so far.
>> > Now I would like to be able to see what "type" the data is aswell. How do
>> I
>> > do that? And: Is there a less spaghetti way to poll the value of the data
>> > from where I am (In the context) when I have the "name" of it. (The name
>> in
>> > this case is Data_1, Data_2 or Data_3, I also know that the data=name is
>> > DynamicData) .
>> >
>> > Due to lack of time I would prefer if i wouldn´t have to "redo" to much
>> of
>> > the scxml, but is this possible to do it my way otherwise? Or do I have
>> to
>> > do it over.
>> >
>> > Best Regards
>> > //Linda
>> >
>>
>

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


Re: [SCXML] Polling in datamodel

Posted by Linda Erlenhov <li...@gmail.com>.
Hello!

The thing here is that the value is never a DOM node. Hence my question. I
previousley asked why the "assign location" didn´t call for the "set"
function in the Context and got the answere that the "assign location"
doesn´t work as "assign name", "assign name" calls the set function and sets
a variable, "assign location" manipulates the XML tree as it is. The advice
was to make an "custom action" instead or do the ugly hack I did: do an
"assign name" with the name after the "assign location" has executed.
What I wanted to know is if there is any way of fetching the "tree" or
whatever it is to get the data associatet to a name, according to the model
below.
If you look at my example below, I will always "know" the name of the
datamodel in this case: "DynamicData", and I will recieve the "name" of the
specific tag in this data, in this case "Data_1", "Data_2" or "Data_3". In
my model below I have done an ugly way of finding out what the value is but
i realized that that was not enough, i need to know the "type" aswell. And
that I don´t know how to find.

Does anybody have a solution to this, or some kind of idea on how to solve
this?

best regards
//Linda

On Tue, May 5, 2009 at 3:50 PM, Ingmar Kliche
<in...@googlemail.com>wrote:

> Linda,
> you should be able to use the DOM API to read the values. In
> context.set(name, value) you should check whether the value is a DOM node:
>
> import import org.w3c.dom.Node;
>
> ...
> ... set(String name, Object value) {
>
>        if (value instanceof Node) {
>            Node nodeValue = (Node) value;
>        }
>
> scope.put(name, scope, value);
>
>
> 2009/5/5 Linda Erlenhov <li...@gmail.com>
>
> > Hello.
> > I´m back with another thousand questions!
> >
> > Still with my datamodel like this:
> > ------------------------------------
> > <scxml version="1.0" initialstate="176" xmlns:cs="
> > http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml
> ">
> >
> > <datamodel>
> > <data name="DynamicData">
> > <Data_1 xmlns="" id="1" type="Integer">0</Data_1>
> > <Data_2 xmlns="" id="2" type="Integer">0</Data_2>
> > <Data_3 xmlns="" id="3" type="String">none</Data_2>
> > </data>
> > <data name="DDChange"/>
> > <data name="DDValue"/>
> > <data name="DDType"/>
> > <data name="Indication_1" expr="false"/>
> > </datamodel>
> > .......................................snip.......
> > Later on i set the data:
> > ...........................................snip.....
> > <state id="StateB">
> > <onentry>
> > <log label="Renegade" expr="'Entering state: StateB'"/>
> > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> > <assign location="Data(DynamicData,'Data_1')"
> > expr="Data(DynamicData,'Data_1')+1"/>
> > <assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
> > <assign name="DDChange" expr="'Data_1'"/>
> > <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> >
> > </onentry>
> > ..........snip--------------------
> >
> > So now here´s the problem.
> >
> > As you see I haven´t used the custom action, but an rather ugly hack
> where
> > I
> > do an assign name after I do the assign location to trigger a call to the
> > "set" function in the context.
> >
> > In this version I also do another assign where I assign another name with
> > the value. All my data are named Data_XX so i screen the calls to set byt
> > looking for the ones that are named Data_XX. When I recieve a call for
> > Data_XX I would like to know what the value is, which I in this case have
> > solved by assigning another variable with it earlier, when i get a "set"
> > call named Data_xx i know that the variable DDValue contains the value of
> > this data. Not pretty, but OK and working so far.
> > Now I would like to be able to see what "type" the data is aswell. How do
> I
> > do that? And: Is there a less spaghetti way to poll the value of the data
> > from where I am (In the context) when I have the "name" of it. (The name
> in
> > this case is Data_1, Data_2 or Data_3, I also know that the data=name is
> > DynamicData) .
> >
> > Due to lack of time I would prefer if i wouldn´t have to "redo" to much
> of
> > the scxml, but is this possible to do it my way otherwise? Or do I have
> to
> > do it over.
> >
> > Best Regards
> > //Linda
> >
>

Re: [SCXML] Polling in datamodel

Posted by Ingmar Kliche <in...@googlemail.com>.
Linda,
you should be able to use the DOM API to read the values. In
context.set(name, value) you should check whether the value is a DOM node:

import import org.w3c.dom.Node;

...
... set(String name, Object value) {

        if (value instanceof Node) {
            Node nodeValue = (Node) value;
        }

scope.put(name, scope, value);


2009/5/5 Linda Erlenhov <li...@gmail.com>

> Hello.
> I´m back with another thousand questions!
>
> Still with my datamodel like this:
> ------------------------------------
> <scxml version="1.0" initialstate="176" xmlns:cs="
> http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml">
>
> <datamodel>
> <data name="DynamicData">
> <Data_1 xmlns="" id="1" type="Integer">0</Data_1>
> <Data_2 xmlns="" id="2" type="Integer">0</Data_2>
> <Data_3 xmlns="" id="3" type="String">none</Data_2>
> </data>
> <data name="DDChange"/>
> <data name="DDValue"/>
> <data name="DDType"/>
> <data name="Indication_1" expr="false"/>
> </datamodel>
> .......................................snip.......
> Later on i set the data:
> ...........................................snip.....
> <state id="StateB">
> <onentry>
> <log label="Renegade" expr="'Entering state: StateB'"/>
> <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> <assign location="Data(DynamicData,'Data_1')"
> expr="Data(DynamicData,'Data_1')+1"/>
> <assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
> <assign name="DDChange" expr="'Data_1'"/>
> <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
>
> </onentry>
> ..........snip--------------------
>
> So now here´s the problem.
>
> As you see I haven´t used the custom action, but an rather ugly hack where
> I
> do an assign name after I do the assign location to trigger a call to the
> "set" function in the context.
>
> In this version I also do another assign where I assign another name with
> the value. All my data are named Data_XX so i screen the calls to set byt
> looking for the ones that are named Data_XX. When I recieve a call for
> Data_XX I would like to know what the value is, which I in this case have
> solved by assigning another variable with it earlier, when i get a "set"
> call named Data_xx i know that the variable DDValue contains the value of
> this data. Not pretty, but OK and working so far.
> Now I would like to be able to see what "type" the data is aswell. How do I
> do that? And: Is there a less spaghetti way to poll the value of the data
> from where I am (In the context) when I have the "name" of it. (The name in
> this case is Data_1, Data_2 or Data_3, I also know that the data=name is
> DynamicData) .
>
> Due to lack of time I would prefer if i wouldn´t have to "redo" to much of
> the scxml, but is this possible to do it my way otherwise? Or do I have to
> do it over.
>
> Best Regards
> //Linda
>

Re: [SCXML] Polling in datamodel

Posted by Ingmar Kliche <in...@googlemail.com>.
Sorry, hit the send button to early:---

again: you should be able to use the DOM API to read the values. In set()
you should check whether the value is a DOM node:

import import org.w3c.dom.Node;
...
...
public void set(String name, Object value) {

        if (value instanceof Node) {
            Node nodeValue = (Node) value;


         // now you can use the DOM API to read the children of your node
         // http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html
         //
         // e.g. nodeValue.getAttributes() to read the attributes.
        ...
       }
    ....
  }
I haven't tried this code. But hope this helps.-- Ingmar.

2009/5/5 Linda Erlenhov <li...@gmail.com>

> Hello.
> I´m back with another thousand questions!
>
> Still with my datamodel like this:
> ------------------------------------
> <scxml version="1.0" initialstate="176" xmlns:cs="
> http://commons.apache.org/scxml" xmlns="http://www.w3.org/2005/07/scxml">
>
> <datamodel>
> <data name="DynamicData">
> <Data_1 xmlns="" id="1" type="Integer">0</Data_1>
> <Data_2 xmlns="" id="2" type="Integer">0</Data_2>
> <Data_3 xmlns="" id="3" type="String">none</Data_2>
> </data>
> <data name="DDChange"/>
> <data name="DDValue"/>
> <data name="DDType"/>
> <data name="Indication_1" expr="false"/>
> </datamodel>
> .......................................snip.......
> Later on i set the data:
> ...........................................snip.....
> <state id="StateB">
> <onentry>
> <log label="Renegade" expr="'Entering state: StateB'"/>
> <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
> <assign location="Data(DynamicData,'Data_1')"
> expr="Data(DynamicData,'Data_1')+1"/>
> <assign name="DDValue" expr="Data(DynamicData,'Data_1')"/>
> <assign name="DDChange" expr="'Data_1'"/>
> <log label="Renegade" expr="Data(DynamicData,'Data_1')"/>
>
> </onentry>
> ..........snip--------------------
>
> So now here´s the problem.
>
> As you see I haven´t used the custom action, but an rather ugly hack where
> I
> do an assign name after I do the assign location to trigger a call to the
> "set" function in the context.
>
> In this version I also do another assign where I assign another name with
> the value. All my data are named Data_XX so i screen the calls to set byt
> looking for the ones that are named Data_XX. When I recieve a call for
> Data_XX I would like to know what the value is, which I in this case have
> solved by assigning another variable with it earlier, when i get a "set"
> call named Data_xx i know that the variable DDValue contains the value of
> this data. Not pretty, but OK and working so far.
> Now I would like to be able to see what "type" the data is aswell. How do I
> do that? And: Is there a less spaghetti way to poll the value of the data
> from where I am (In the context) when I have the "name" of it. (The name in
> this case is Data_1, Data_2 or Data_3, I also know that the data=name is
> DynamicData) .
>
> Due to lack of time I would prefer if i wouldn´t have to "redo" to much of
> the scxml, but is this possible to do it my way otherwise? Or do I have to
> do it over.
>
> Best Regards
> //Linda
>