[rules-users] Problems with custom functions and types in one drlfile

Rainer Schulz Rainer.Schulz at trivadis.com
Tue May 5 09:57:26 EDT 2009


Thank you for your fast answer. 

 

Thanks

 

Rainer

 

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Dienstag, 5. Mai 2009 14:50
To: Rules Users List
Subject: Re: [rules-users] Problems with custom functions and types in
one drlfile

 


   This is a bug that was fixed a few weeks ago. If you can use trunk,
you will not have this problem.

   []s
   Edson

2009/5/5 Rainer Schulz <Rainer.Schulz at trivadis.com>

Hi, 

i have some problems with custom functions and types. 

I m using Drools 5.0 and Eclipse 3.4.2 (have to use these eclipse
version, so my decision was to use the drools beta).

I declared a type in my rule file like : 

declare VarHolder

    var1 : String

    var2 : Long

    var3 : String

end

also i specified a custom function in the same file, which i have to use
in my rules (it's a example function) : 

function String hello(String name) {

    return "Hello "+name+"!";

}

.

The declared Type will be used  in the java code : 

// handle the type as necessary:

// create instances:

Object vars = varHolderTyp.newInstance();

// set attributes values

varHolderTyp.setFromMap(vars,varMap);

// insert fact into a session

StatefulKnowledgeSession ksession = ...

ksession.insert( vars );

When it comes to the "setFromMap", then I get a ClassCastException for
the VarHolderTyp. But when I remove the declaration of the function in
the rule file, then everything works fine (all variables will be filled
correctly). It seems, that the reflection mechanism will not work
correctly, when drools want to create the Pojo for VarHolder and the
Static Method for the function. But it s very difficult to debug,
because the exception fires in the drools engine. 

Maybe I've make a mistake so anyone  knows a solution for this problem
or can tell me, where my mistake is. It will be nice, when I can declare
a type and a function together in one rule file.  At the moment, I
created a java class for VarHolder, so the exception does not appear,
but I m losing a lot of dynamic. 

Please give me a hint


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090505/d2f9aef4/attachment.html 


More information about the rules-users mailing list