我用apache commons scxml引擎运行Microwave oven 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
我知道它与我的datamodel有关,因为datamodel不被视为XML节点,
答案 0 :(得分:0)
我发现了一些应该有用的东西:
datamodel="ecmascript"
标记中的<scxml>
属性;把它留下来。<assign>
个表达式问题;当我从location
切换到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>
...