【问题标题】:unable to resolve method using strict-mode with object type无法使用对象类型的严格模式解析方法
【发布时间】:2015-07-17 02:10:35
【问题描述】:

昨天我post 向函数传递不同类型的参数时提出了一个关于严格模式的问题,并找到了解决方案。按照建议,我现在使用 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

感谢您的帮助。

【问题讨论】:

    标签: java drools strict-mode


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      这行代码

      $noeud = creerAction(...);
      

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

      Object $noeud = creerAction(...);
      

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

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

      【讨论】:

      • 我对 $noeud = creerAction() 没有问题。问题是当我尝试使用该对象的属性时(例如:$noeud.prochaineActionSiBlocage)。我试过 Object $noeud = creerAction()EvaluerMessageActivable $noeud = creerAction() ,结果相同。 (a t'on le droit de parler français ici?)
      • 重点是 Object(显式或隐式)切断了所有类型信息,并且没有编译器允许将某个类的字段或方法用于纯 Object 类型的对象。 (在 le droit de parler Français mais les réponses seront Rares。)
      • Ce qui m'embête, c'est que notre système qui est présentement en production fonctionne avec ces règles là。 Les règles sont géréré par Genesys Rule Authoring et sont exécuté par Genesys Rule Engine。 Tout deux Roule 流口水 5.2 版。 Par contre, je ne sais pas si le déploiement de GRAT vers GRE modifie d'une façon quelqu'onque les règles...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 2012-06-15
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多