0

我正在使用 apache commons scxml 引擎运行微波炉 scxml 。我有扩展 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");
    }

}

现在当创建这个类的一个实例时,我得到一个异常

   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

我知道这与我的数据模型有关,因为数据模型不被视为 XML 节点,

4

1 回答 1

0

我发现了一些应该有所帮助的事情:

  • Apache commons-scxml 不喜欢标签datamodel="ecmascript"中的属性;<scxml>把它放在外面。
  • <assign>在查看 JEXL 评估器源之前,我一直遇到表达式问题;当我从切换locationname

<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>
...
于 2014-01-12T02:06:17.203 回答