0

昨天我在将不同类型的参数传递给函数时发布了一个关于严格模式的问题,一个 laune 找到了解决方案。按照建议,我现在使用 drools 5.6 版。

现在,我仍然有严格模式错误,但对于另一种情况。不幸的是,我不能应用相同的解决方案。函数 creerAction() 返回不同类型的对象。有人对这种情况有想法吗?

这是错误

Unable to Analyse Expression $noeud = creerAction($action,"EvaluerMessageActivable",drools); $action.noeud = $noeud;
    $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, "CN_Raccrocher");
    $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal'):
[Error: unable to resolve method using strict-mode: java.lang.Object.prochaineActionSiBlocage()]
[Near : {... $noeud.prochaineActionSiBlocage = obt ....}]
[Line: 34, Column: 0] : [Rule name='Row 1 DT-625 Evaluer blocage general']

这是我的流口水文件。

package com.desjardins.gtd.dpsccc.routage.vpa.actionsdialogue

import org.drools.spi.KnowledgeHelper;

function Object creerAction(Action actionCourante, String type, KnowledgeHelper drools) {
    if(actionCourante.getNoeud()!=null){
        String nomActionCourante = actionCourante.getNoeud().getClass().getSimpleName(); 
        if(!nomActionCourante .equals(type)) 
            throw new RuntimeException("Ne peut pas redéfinir le type de " + actionCourante.getNom() + ". Le type était: " + nomActionCourante + " spécifié: " + type);
        return actionCourante.getNoeud();
    }
    else if("EvaluerMessageActivable".equals(type)) return new EvaluerMessageActivable();
    else if("Terminer".equals(type)) return new Terminer();

    return null;
}

declare Action
    nom: String
    noeud: java.lang.Object
    compteur: Integer
end 

declare EvaluerMessageActivable
    message: String
    prochaineActionSiBlocage: String
end 

declare Terminer
    nom: String
end 

rule "Row 1 DT-625 Evaluer blocage general"
salience 100079 
    agenda-group "level0"
    dialect "mvel"
    when
        $action:Action(nom =='EM_UrgenceGlobal')
    then
        $noeud = creerAction($action,'EvaluerMessageActivable',drools); $action.noeud = $noeud
        $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, 'CN_Raccrocher')
        $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal')
end

谢谢你的帮助。

4

2 回答 2

0

这行代码

$noeud = creerAction(...);

将返回值赋给creerAction未声明的变量。由于函数返回java.lang.Object,使用

Object $noeud = creerAction(...);

解决这个问题。当然,后续使用 of$noeud可能必须使用强制转换来允许编译器找到正确的方法或其他任何东西。

不要认为 Drools 或 MVEL 废除了 Java 的所有类型系统。(老天爷!)

于 2015-05-06T19:45:57.060 回答
0

对于我的测试,我使用的是 Jetty 版本 6.1.26,并且该版本存在流口水问题。我尝试了 8.1.2 版本,它工作正常。

我还禁用了严格模式: System.setProperty("drools.dialect.mvel.strict", "false");

于 2015-06-03T15:38:54.213 回答