在scxml中调用转换cond评估中的自定义函数

时间:2016-12-06 14:35:22

标签: xml state-machine scxml apache-commons-scxml

我想在评估script块中的cond时调用transition标记中定义的自定义函数。

例如,我想将函数定义为:

<datamodel>
    <data expr="1" id="xOccurrences"/>
    <data expr="0" id="yOccurrences"/>
</datamodel>
<script>
    def updateVars(hasXOccurred, hasYOccurred) {
        if(hasXOccurred) xOccurrences++
        if(hasYOccurred) yOccurrences++
    }

    def thresholdBreached(hasXOccurred, hasYOccurred) {
        updateVars(hasXOccurred, hasYOccurred)

        if(xOccurrences > 5 && yOccurrences > 8)
            return true

        return false
    }
</script>

然后我想在转换eval表达式中调用它们(带副作用):

<state id="StateA">
    <transition event="EventX" cond="thresholdBreached(_event.data.xOccurred, _event.data.yOccurred)" target="StateB"/>
</state>

是否可以在scxml状态机定义中完成此操作?

0 个答案:

没有答案