On 10 August 2011 17:14, Sumeet Karawal <sumeet.karawal@tcs.com> wrote:
package rules.person
import com.person.Age
Import com.person.Classification
rule "Check_person.option1"
when
$age : com.person.Age()
$classification : com.person.Classification()
eval ($age.getClassification("16"))
then
modify ($classification) {$classification.setResult('"Teenager"; }
end
rule "Check_person.option2"
when
$age : com.person.Age()
$classification : com.person.Classification()
eval ($age.getClassification("40"))
then
modify ($classification) {$classification.setResult('"Adult"; }
end
Application Class :
public class Age
{
public string getClassification(String name) {
<Logic of the application>
return str;
}
}
public class Classification
{
public void setResult(String name) {
<Logic of the application>
}
}
Queries :
Please let me know if I am using the 'when' part correctly.
And please check for the use of the object 'classification' in my
application (as return value to the application)
From: Wolfgang Laun <wolfgang.laun@gmail.com>
To: Rules Users List <rules-users@lists.jboss.org>
Date: 08/10/2011 03:03 PM
Subject: Re: [rules-users] Calling a method in when part
Sent by: rules-users-bounces@lists.jboss.org
If you don't show your code we can't tell you what is wrong with it. So I
think what you may have to do is
when
$someObj: SomeClass() # matches each WME of SomeClass
eval( $someObj.getValueBoolean("abc"))
then
There is not much to be gained by using a DRL function; it would have to be
called like
eval( someFunction( $someObj, "abc" ) )
-W
On 10 August 2011 11:05, Sumeet Karawal <sumeet.karawal@tcs.com> wrote:
Hi,
I have a requirement where there is a customized Java class having a
method
that returns some value.
like:
getValueBoolean("Some String")
{ //some calculation
// returns a boolean value
}
The default getters and setters are not being used in the Application.
The
value that is being returned by the method needs to be checked in
the .drl
file.
There are different Java classes with these kind of methods. Where the
string and integer value is also returned. I have gone through the
documentation for Drools-Expert but have only found the implementation
for
the method in the consequence part, i.e., the then part.
This is how I tried:
importing the class
in when
binding the a variable to the Class name suppose $c
eval ($c.getValueBoolean("abc"))
then
System.out.println("the value is true")
It didn't work this way.
I tried by another way like :
creating a function in the .drl itself that calls the method of that
class
and returns a value
then calling this drl function in the when part and carrying on.
It would be very helpful if some body could let me know how to do this in
the .drl.
Thanks & Regards,
Sumeet Karawal
Mailto: sumeet.karawal@tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users