Thanks for the information.
 
I am trying to get the value in the when condition from a function(that returns a value). But facing some errors in doing that...May be I am doing some mistake in creating drl.
 
Below is my drl and the Pojo that I am using, please guide me on this :
 
Drl :
 
 
 #created on: Aug 5, 2011
package com.sample
import com.sample.Customer

rule "Below 100"

when
$c:Customer()
$c.getSi() < 100

then
$c.setVal("<100");

end

rule "Below 200"

when
$c:Customer()
$c.getSi() < 200

then
$c.setVal("<200");

end


rule "Below 300"

when
$c:Customer()
$c.getSi() < 300

then
$c.setVal("<300");

end
 
 
 
 
Pojo :
 
package com.sample;

public class Customer {

private double si;
private String val;

public double getSi() {
return si;
}
public double setSi(double p,double r, double t) {
si = (p*r*t)/100;
return si;
}
public String getVal() {
return val;
}
public void setVal(String val) {
this.val = val;
}

}
 
The error that I get while executing is :
 
 

[9,13]: unknown:9:13 mismatched token: [@33,126:126='<',<79>,9:13]; expecting type THEN[20,13]: unknown:20:13 mismatched token: [@67,224:224='<',<79>,20:13]; expecting type THEN[32,13]: unknown:32:13 mismatched token: [@101,323:323='<',<79>,32:13]; expecting type THEN
java.lang.RuntimeException: Unable to compile "methodCall.drl".
at com.sample.Calling.createRuleBase(Calling.java:48)
at com.sample.Calling.main(Calling.java:24)

 

and my calling class is :

 

package com.sample;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;

public class Calling {


public static void main(String[] args)throws IOException {


Customer c1 = new Customer();
c1.setSi(1000, 5, 2);

try {

RuleBase ruleBase = createRuleBase();
StatefulSession session = ruleBase.newStatefulSession ();

session.insert(c1);
session.fireAllRules();
session.dispose();

System.out.println("Interest is : "+c1.getVal());

}
catch (Throwable t) {
t.printStackTrace();
}
}

private static RuleBase createRuleBase() throws Exception
{
Reader source = new InputStreamReader(Calling.class.getResourceAsStream( "methodCall.drl" ) );

PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );

if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "Unable to compile \"methodCall.drl\".");
}

Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );

return ruleBase;

}

}

 

 
 

Thanks & Regards,
Gaurav Silakari
Mailto: gaurav.silakari@tcs.com




    From:

Wolfgang Laun <wolfgang.laun@gmail.com>

    To:

Rules Users List <rules-users@lists.jboss.org>

    Date:

08/04/2011 04:05 PM

    Subject:

Re: [rules-users] Some basic queries

    Sent by:

rules-users-bounces@lists.jboss.org






2011/8/4 Gaurav Silakari <gaurav.silakari@tcs.com>
Whatever would you need the binding for? MyClass.class.getName() is also the constructor's name.

 
    2) Is it possible to call a parameterised (single parameter) method of a class (by giving class reference as bind variable and class being declared in 'import' syntax ) in LHS of the rule

If the Class object is an attribute of some fact it can be bound and you can use
reflection to call the method. This could be written as a DRL function.

 
    3) Is it possible to call a parameterised method (with single parameter) in the RHS of the rule (The method would be pertaining to the class imported in the 'import' syntax and method name being invoked through the bind variable reference )

Assuming the method name (or the Method object) comes from a field in some fact, it can be bound to a variable. On the RHS you proceed as in Java.

-W

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


=====-----=====-----=====
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