commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Micka <mickamus...@gmail.com>
Subject SCXML : getCurrentStateS
Date Sat, 11 Dec 2010 11:26:48 GMT
Hi,


I'm trying to get the currentStates in case we have multiple states.

by example :


<?xml version="1.0" encoding="UTF-8"?>

<scxml xmlns="http://www.w3.org/2005/07/scxml"    version="1.0"
initialstate="start">

   <parallel id="start">

       <state id="simulatedUser">
           <datamodel>
               <data name="one" expr="1" />
               <data name="two" expr="2" />
           </datamodel>

           <onentry>
               <send event="'event.bar'" namelist="one two"
delay="'100ms'"/>
           </onentry>
           <transition event="event.bar">
               <log label="'simulatedUser'"
expr="_eventdatamap['event.bar'].one + ', ' +
_eventdatamap['event.bar'].two"/>
           </transition>
       </state>

       <state id="counter">
           <initial>
               <transition target="twenty"/>
           </initial>

           <state id="twenty">
               <transition event="event.bar"
                   cond="_eventdatamap['event.bar'].one +
_eventdatamap['event.bar'].two eq 3"
                   target="thirty"/>
               <transition event="event.bar">
                   <log label="'event.bar in twenty state'"
expr="_eventdatamap['event.bar'].one + ', ' +
_eventdatamap['event.bar'].two"/>
               </transition>
           </state>

           <state id="thirty" final="true"/>
       </state>

   </parallel>

</scxml>

theoretically , the current states is :  *simulatedUser *and *twenty*

I tried to code something but i'm getting : twenty+thirty#simulatedUser
I should have twenty#simulatedUser !! instead i get all the state inside
counter ......... :(

do you have an answer and a solution for that ?

    public String getCurrentStates() {
        Set states = exec.getCurrentStatus().getStates();
        Iterator<State> it = states.iterator();
        State state;
        String sid="";
        while(it.hasNext()){
            state = it.next();
            sid+=stateToString(state,"+-*(){}/");
            if(it.hasNext())sid+="#";
        }
        return ((State)
exec.getCurrentStatus().getStates().iterator().next())
                .getId();
    }
    public String stateToString(State state,String separators){
        String sid="";
        boolean test= state.isComposite();
        if( test && separators.length()>0){
            char separator=separators.charAt(0);
            separators=separators.substring(1);
            Map states = state.getChildren();
            Iterator<State> it = states.values().iterator();
            while(it.hasNext()){
                state = it.next();
                sid+=stateToString(state,separators);
                if(it.hasNext())sid+=separator;
            }
            return sid;
        }else{
            return state.getId();
        }
    }

It will be helpfull to have a solution for that, because it is the same
problem for the checkIfAbleToChangeState() function.


Thank you !!



( And thanks for this amazing work )

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message