Exception while running Apache SCXML engine. Argument type mismatch -

339 views Asked by At

Im running the Microwave oven scxml with apache commons scxml engine. I have my Custom class that extends the AbstarctStateMachine

 public class MicrowaveOwenStateMachine extends AbstractStateMachine {

    public MicrowaveOwenStateMachine() {
        
        super(MicrowaveOwenStateMachine.class.getClassLoader().getResource("mOwen.xml"));
        
    }
    
    public State getCurrentState() {

        Set<?> states = getEngine().getCurrentStatus().getStates();
        return ( (State) states.iterator().next());

    }

    public void oven(){
        System.out.println("State :oven");

    }
    public void engine(){
        System.out.println("State : Engine");
    }
    public void off(){
        System.out.println("State : off");
    }
    public void on(){
        System.out.println("State : on");
    }
    public void idle(){
        System.out.println("State : Idle");
    }
    public void cooking(){
        System.out.println("State : Cooking");
    }
    public void door(){
        System.out.println("State : Door");
    }
    public void closed(){
        System.out.println("State : Closed");
    }
    public void open(){
        System.out.println("State : Open");
    }

}

Now when creating an instance of this class ,im getting an exception

   java.lang.IllegalArgumentException: Cannot invoke org.apache.commons.scxml.model.SCXML.setDatamodel on bean class 'class org.apache.commons.scxml.model.SCXML' - argument type mismatch - had objects of type "java.lang.String" but expected signature "org.apache.commons.scxml.model.Datamodel"
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2235)
    at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2151)
    at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1957)
    at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2064)
    at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1017)
    at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830)
    at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433)
    at org.apache.commons.digester.SetPropertiesRule.begin(SetPropertiesRule.java:252)
    at org.apache.commons.digester.Rule.begin(Rule.java:175)
    at org.apache.commons.digester.Digester.startElement(Digester.java:1464)
    at

I know that its something to do with my datamodel as the datamodel is not taken as an XML node,

1

There are 1 answers

0
pmorken On

I discovered a couple of things that should help:

  • Apache commons-scxml does not like the datamodel="ecmascript" attribute in the <scxml> tag; leave it out.
  • I was having trouble with <assign> expressions until I looked at the JEXL evaluator source; it seems to work when I switched from location to name:

<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="init"
<datamodel>
  <data id="loop_ctr" expr="0"/>
</datamodel>
...
<state id="in_progress">
  <onentry>
    <assign name="loop_ctr" expr="loop_ctr + 1"/>
  </onentry>
  <transition event="complete" target="in_review"></transition>
</state>
...