You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Berg, T.W. (Tom) van den" <to...@tno.nl> on 2008/07/19 01:35:44 UTC

[SCXML] Access datamodel

I'm still sorting out basics before moving on to some real stuff.
 
I have a simple scxml document with a data model listed below. I execute
my program with a custom action (also shown further below).
 
I have a couple of questions:
 
1) For <assign location="Data(label, 'handle')" expr="'a test value'" />
I get the following error. Why?
 
19-jul-2008 1:15:51 org.apache.commons.scxml.Builtin dataNode
WARNING: Data(): No nodes matching the XPath expression "handle",
returning null
19-jul-2008 1:15:51 org.apache.commons.scxml.model.Assign execute
SEVERE: <assign>: location does not point to a <data> node

2)  Also for <rti:register name="result" expr="Data(label,'name')"/>  I
get an error. Why?
 
19-jul-2008 1:15:51 sc.Register execute
INFO: eval(Data(label,'name'))
19-jul-2008 1:15:51 org.apache.commons.scxml.Builtin dataNode
WARNING: Data(): No nodes matching the XPath expression "name",
returning null
19-jul-2008 1:15:51 sc.Register execute
INFO: <var>: Defined variable 'result' with initial value ''

3) How can I transer the result from rti:register back into the
datamodel's handle field from a) the SCXML document or b) the custom
action?

 
Thanks -- Tom
 
----
 
<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       xmlns:rti="http://rti.actions/CUSTOM"
       version="1.0"
       initialstate="SyncPoint">
 
 <state id="SyncPoint">
  
  <datamodel>
   <data name="label">
    <name>initial</name>
    <handle></handle>
   </data>
  </datamodel>
  
  <initial>
   <transition target="registered"/>
  </initial>
  
  <state id="registered">
   <onentry>
    <assign location="Data(label, 'handle')" expr="'a test value'" />
    <rti:register name="result" expr="Data(label,'name')"/>
    <rti:register name="result" expr="2 + 8"/>
   </onentry>        
   <transition event="confirmed" target="confirmed"/>
   <transition event="error" target="error"/>
  </state>
  
  <state id="confirmed">
   <onentry>
    <rti:confirm name="doConfirm" />
   </onentry>        
   <transition target="end"/>
   <transition event="error" target="error"/>
  </state>
  
  <final id="end"/>
  
  <state id="error"></state>
 </state>
 
</scxml>
 
----
 
public class Register extends Action {

<<... cut ...>>
 
 public void execute(final EventDispatcher evtDispatcher,
  final ErrorReporter errRep, final SCInstance scInstance,
  final Log appLog, final Collection derivedEvents)
  throws ModelException, SCXMLExpressionException {
  
  Context ctx = scInstance.getContext(getParentState());
  Evaluator eval = scInstance.getEvaluator();
  
  ctx.setLocal(getNamespacesKey(), getNamespaces());
  
  appLog.info("eval("+expr+")");
  
  Object varObj = eval.eval(ctx, expr);
  
  ctx.setLocal(getNamespacesKey(), null);
  ctx.setLocal(name, varObj);
  
  appLog.info("<var>: Defined variable '" + name + "' with initial value
'" + String.valueOf(varObj) + "'");
  
  TriggerEvent ev = new TriggerEvent(name + ".change",
TriggerEvent.CHANGE_EVENT);
  derivedEvents.add(ev);
 }
 
This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html

Re: [SCXML] Access datamodel

Posted by Rahul Akolkar <ra...@gmail.com>.
On Mon, Jul 21, 2008 at 3:22 AM, Daniel Schwager
<Da...@dtnet.de> wrote:
> Hi Rahul,
>
> maybe "adapting"  http://commons.apache.org/scxml/guide/datamodel.html
> related to your answer will help other users (like me also ;-) to hit
> not this pitfall.
>
<snip/>

Indeed, thanks for pointing this out.

I've limited dev time for much of this week. If you want to track
this, please open an improvement request in JIRA [1]. If you want to
contribute to the documentation based on your experience, you can
submit a patch [2] to the source for that page [3].

-Rahul

[1] http://commons.apache.org/scxml/issue-tracking.html
[2] http://commons.apache.org/patches.html
[3] http://svn.apache.org/repos/asf/commons/proper/scxml/trunk/xdocs/guide/datamodel.xml


> Regards
> Danny
>
>> SCXML documents are namespace aware. <data> elements are recommended
>> to have a "root" such as:
>>
>> <data name="foo">
>>     <root xmlns="">
>>         <!-- Note xmlns above, obviously element name
>>                    doesn't have to be root -->
>>     </root>
>> </data>
>>
>> Can you try that -- it may solve some of the questions below. Then we
>> can look at the remaining ones, if any.
>>
>> -Rahul
>

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


AW: [SCXML] Access datamodel

Posted by Daniel Schwager <Da...@dtnet.de>.
Hi Rahul,

maybe "adapting"  http://commons.apache.org/scxml/guide/datamodel.html
related to your answer will help other users (like me also ;-) to hit
not this pitfall.

Regards
Danny

> SCXML documents are namespace aware. <data> elements are recommended
> to have a "root" such as:
> 
> <data name="foo">
>     <root xmlns="">
>         <!-- Note xmlns above, obviously element name
>                    doesn't have to be root -->
>     </root>
> </data>
> 
> Can you try that -- it may solve some of the questions below. Then we
> can look at the remaining ones, if any.
> 
> -Rahul

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


Re: [SCXML] Access datamodel

Posted by Rahul Akolkar <ra...@gmail.com>.
On Fri, Jul 18, 2008 at 7:35 PM, Berg, T.W. (Tom) van den
<to...@tno.nl> wrote:
> I'm still sorting out basics before moving on to some real stuff.
>
> I have a simple scxml document with a data model listed below. I execute
> my program with a custom action (also shown further below).
>
> I have a couple of questions:
>
> 1) For <assign location="Data(label, 'handle')" expr="'a test value'" />
> I get the following error. Why?
>
<snip/>

SCXML documents are namespace aware. <data> elements are recommended
to have a "root" such as:

<data name="foo">
    <root xmlns="">
        <!-- Note xmlns above, obviously element name
                   doesn't have to be root -->
    </root>
</data>

Can you try that -- it may solve some of the questions below. Then we
can look at the remaining ones, if any.

-Rahul


> 19-jul-2008 1:15:51 org.apache.commons.scxml.Builtin dataNode
> WARNING: Data(): No nodes matching the XPath expression "handle",
> returning null
> 19-jul-2008 1:15:51 org.apache.commons.scxml.model.Assign execute
> SEVERE: <assign>: location does not point to a <data> node
>
> 2)  Also for <rti:register name="result" expr="Data(label,'name')"/>  I
> get an error. Why?
>
> 19-jul-2008 1:15:51 sc.Register execute
> INFO: eval(Data(label,'name'))
> 19-jul-2008 1:15:51 org.apache.commons.scxml.Builtin dataNode
> WARNING: Data(): No nodes matching the XPath expression "name",
> returning null
> 19-jul-2008 1:15:51 sc.Register execute
> INFO: <var>: Defined variable 'result' with initial value ''
>
> 3) How can I transer the result from rti:register back into the
> datamodel's handle field from a) the SCXML document or b) the custom
> action?
>
>
> Thanks -- Tom
>
> ----
>
> <?xml version="1.0"?>
> <scxml xmlns="http://www.w3.org/2005/07/scxml"
>       xmlns:rti="http://rti.actions/CUSTOM"
>       version="1.0"
>       initialstate="SyncPoint">
>
>  <state id="SyncPoint">
>
>  <datamodel>
>   <data name="label">
>    <name>initial</name>
>    <handle></handle>
>   </data>
>  </datamodel>
>
>  <initial>
>   <transition target="registered"/>
>  </initial>
>
>  <state id="registered">
>   <onentry>
>    <assign location="Data(label, 'handle')" expr="'a test value'" />
>    <rti:register name="result" expr="Data(label,'name')"/>
>    <rti:register name="result" expr="2 + 8"/>
>   </onentry>
>   <transition event="confirmed" target="confirmed"/>
>   <transition event="error" target="error"/>
>  </state>
>
>  <state id="confirmed">
>   <onentry>
>    <rti:confirm name="doConfirm" />
>   </onentry>
>   <transition target="end"/>
>   <transition event="error" target="error"/>
>  </state>
>
>  <final id="end"/>
>
>  <state id="error"></state>
>  </state>
>
> </scxml>
>
> ----
>
> public class Register extends Action {
>
> <<... cut ...>>
>
>  public void execute(final EventDispatcher evtDispatcher,
>  final ErrorReporter errRep, final SCInstance scInstance,
>  final Log appLog, final Collection derivedEvents)
>  throws ModelException, SCXMLExpressionException {
>
>  Context ctx = scInstance.getContext(getParentState());
>  Evaluator eval = scInstance.getEvaluator();
>
>  ctx.setLocal(getNamespacesKey(), getNamespaces());
>
>  appLog.info("eval("+expr+")");
>
>  Object varObj = eval.eval(ctx, expr);
>
>  ctx.setLocal(getNamespacesKey(), null);
>  ctx.setLocal(name, varObj);
>
>  appLog.info("<var>: Defined variable '" + name + "' with initial value
> '" + String.valueOf(varObj) + "'");
>
>  TriggerEvent ev = new TriggerEvent(name + ".change",
> TriggerEvent.CHANGE_EVENT);
>  derivedEvents.add(ev);
>  }
>

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