There were a couple of ways mentioned in the Drools documentation for 4.0.7.
1) Eval is the Quick way to get this done. This does have a performance
penalty though
2) Read up on using the -> operator that allowed you to go deeper into the
object hierarchy.
3) A third way which I used was to write setter and getter methods for
fields I needed in the rules condition in the root class itself. Since Drools
introspects on setters and getters this seemed to work.
To take an example, if I have a class as follows:-
Class B{
int a;
public int geta() {};
public int seta() {};
}
Class A {
B b;
public int getA()
{
Return this.b.geta();
}
Public void seta(int b)
{
this.b.seta(b);
}
}
From: [email protected]
[mailto:[email protected]] On Behalf Of Divya Rajendranath
Sent: Monday, February 23, 2009 2:57 PM
To: [email protected]
Subject: [rules-users] Help on using Drools with embedded objects
Hi,
I am planning to use Drools - JBoss Rules Engine. My requirement is to disburse
mails from my application to different groups based on various criteria. I want
to use Drools here.
My object structure is as follows:
class A{
String B = "";
B b;
C c;
}
Hence Obj A has embedded objects within it, and obj B and C further has
embedded objects.
class B {
String X;
Z z;
}
class Z{
String t;
String s;
}
The decision on sending the mails based on the fields in embedded objects of A.
I pass instance of A to Drools
Format of drl file:
package...;
import ..;
rule "Test"
when $a:A(B(Z(s == "testvalue")))
then
$a.setSomething();
update($a);
end
I wanted to know if this (accessing fields in embedded/child object) is
feasible with Drools.
I get an error saying "UNable to compile myfile.drl when i try to fo this.
Could some one look into this issue and let me know the reason for this ?
Thanks
-D
MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of
Mastek Limited, unless specifically indicated to that effect. Mastek Limited
does not accept any responsibility or liability for it. This e-mail and
attachments (if any) transmitted with it are confidential and/or privileged and
solely for the use of the intended person or entity to which it is addressed.
Any review, re-transmission, dissemination or other use of or taking of any
action in reliance upon this information by persons or entities other than the
intended recipient is prohibited. This e-mail and its attachments have been
scanned for the presence of computer viruses. It is the responsibility of the
recipient to run the virus check on e-mails and attachments before opening
them. If you have received this e-mail in error, kindly delete this e-mail from
desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users