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] How to update the datamodel from inside a state's executable content?
Date Mon, 26 Apr 2010 19:23:50 GMT
On Mon, Apr 26, 2010 at 3:03 PM, Aarathi <aarathi@gmail.com> wrote:
>  In the listener:
>
> public void onEntry(TransitionTarget state) {
>  ....
>           // call method named as the state thru reflection
>           invokeState(state.getId(), state.getDatamodel()
>
> }
>
> stateP(Datamodel model){
>
> //  some new value for "data1" is generated, so update it on the datamodel
> String newData1Value = "15";
> boolean found = false;
>   List<Data> dataList =  datamodel.getData();
>   for(Data d : dataList){
>      if(d.getId().equals("data1"){
>         d.setExpr(newData1Value);
>         found = true;
>      }
>   }
>   if(!found){
>      Data d= new Data();
>      d.setId("data1");
>      d.setExpr("15");
>      model.addData(d);
>   }
> }
>
>
<snip/>

In the above code, you are modifying the model (i.e. the template)
rather than the instance.

What you need is to access the data via the state's context. The
listener pattern doesn't allow easy access to an individual state's
context. For that, you will need to use <assign> or a custom action.
The pattern does allow access to the root context easily, via the
private 'executor' field, so an alternative may be to move the <data>
to the root datamodel (i.e. <datamodel> child of <scxml> root element)
if that is feasible.

-Rahul


>
>
> On Mon, Apr 26, 2010 at 1:30 PM, Rahul Akolkar <rahul.akolkar@gmail.com>wrote:
>
>> On Mon, Apr 26, 2010 at 12:09 PM, Aarathi <aarathi@gmail.com> wrote:
>> > *Details on how I use the commons scxml api:*
>> > My state's scxml looks like this -
>> >
>> > <state id="stateP">
>> >      <datamodel>
>> >              <data name="data1" expr="11" />
>> >      </datamodel>
>> > <transition event="stateP.SUCCESS" cond="_eventdata.data2
>> > eq data1" target="stateQ" />
>> > <transition event="stateP.FAILURE" target="stateR" />
>> > </state>
>> >
>> > I use the commons scxml with the "listener" pattern. So when  the
>> > "onEntry()" is called in the SCXMLWorkflowListener, it does something
>> > similar  to AbstractStateMachine ie hand off to a method with the same
>> name
>> > as the stateName.
>> >
>> > So relating to the scxml above , I have a method stateP(). This method
>> holds
>> > the executable content for that state. Typically, in stateP(), the value
>> of
>> > data1 is changed and then control is handed off to an async call. When
>> this
>> > async call returns it fires the events that the transitions need.
>> >
>> > *Question:*
>> > While evaluating the condition on the transition, the value of data1 is
>> > always what it was initialized to ie 11. The updates I make in the
>> > executable content in stateP() never kicks in. So obviously, the
>> transition
>> > is never taken. What am I missing?
>> >
>>
>> There are many occassions where we update data models in executable
>> content in our tests (such as, via <assign> or even programmatically)
>> so this seems specific to a particular usage pattern you have.
>>
>> Please say a little more, perhaps with a snippet showing a simplified
>> stateP() impl, as to how you update data1 and what the said async call
>> looks like.
>>
>> -Rahul
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>

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


Mime
View raw message