[rules-users] import static function with varargs as one of the parameters doesn't work?

Jane James jane6210 at yahoo.com
Mon Nov 2 19:52:08 EST 2009


Hi guys,
    I have a question regarding the import function feature in Drools 5.1.0M.

    I am reading the Drools JBoss Rules 5.0 book Developer's guide by Michal Bali and tried one of the examples but somehow I couldn't get my rules work with the method that has varargs. 

Here's what I have (copied from page 123):

public class ValidationHelper {
    public static void error (RuleContext kcontext, Object... context) {
        KnowledgeRuntime knowledgeRuntime = kcontext.getKnowledgeRuntime();
        ValidationReport validationReport = (ValidationReport)knowledgeRuntime.getGlobal("validationReport");
        ReportFactory reportFactory = (ReportFactory) knowledgeRuntime.getGlobal("reportFactory");

        kcontext.insertLogical(reportFactory.createMessage(
                Message.Type.ERROR, kcontext.getRule().getName(),
                context));
    }
}


then in my drools file (copied from page 42): 
i have

import org.drools.runtime.rule.RuleContext;
import function ValidationHelper.error;
...
rule test
when
   #condition
 then
    error(drools)


but when I ran the test, I got error message:

Exception in thread "main" org.drools.runtime.rule.ConsequenceException: [Error: unable to resolve method: ValidationHelper.error(org.drools.base.DefaultKnowledgeHelper) [arglength=1]]

If I remove the parameter Object... context, then everything worked. But I do need the varargs here because I need my error message to be more specific.

Did anyone else encounter the same problems?


thanks!


      



More information about the rules-users mailing list