<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div><div><font face="Arial" size="2">Hi all,</font></div>
<div> </div>
<div><font face="Arial" size="2">I has a problem in executing the drool code. I have
2 rules with a condition and an action.<br>The order of execution is <br><br></font>executeCondition1<br>executeCondition2<br>executeAction2()<br>executeAction1()<br><br>but to fullfill my requirements i need the sequence to be executed as <br>executeCondition1<br>
executeAction1()<br>
executeCondition2<br>
executeAction2()<br><br>Is there any to get way to execute the sequence as above. Kindly suggest<br><br>Here is Drool Code and Implementation Java Code<br><font face="Arial" size="2"><br><br>Sample.drl<br>========<br> </font></div>
<div>package com.sample<br>import com.sample.DroolsTest.MyDeligate;<br>rule "Rule1"<br> salience 2<br> when<br> delegate: MyDeligate()<br> eval(delegate.executeCondition1());<br> then <br> delegate.executeAction1();<br>end<br><br>rule "Rule2"<br> salience 1<br> when<br> delegate: MyDeligate()<br> eval(delegate.executeCondition2());<br> then <br> delegate.executeAction2();<br>end<br><br></div>
DroolTest.java<br>===========<br><br>package com.sample;<br><br>import java.io.InputStreamReader;<br>import java.io.Reader;<br>import org.drools.RuleBase;<br>import org.drools.RuleBaseFactory;<br>import org.drools.WorkingMemory;<br>import org.drools.compiler.PackageBuilder;<br>import org.drools.rule.Package;<br><br>public class DroolsTest {<br><br> public static final void main(String[] args) {<br> try {<br> RuleBase ruleBase = readRule();<br> WorkingMemory workingMemory = ruleBase.newWorkingMemory();<br> MyDeligate delegate = new MyDeligate();<br>
workingMemory.assertObject(delegate);<br> workingMemory.fireAllRules(); <br> } catch (Throwable t) {<br> t.printStackTrace();<br> }<br> }<br><br> private static RuleBase readRule() throws Exception <br> {<br> Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );<br> PackageBuilder builder = new PackageBuilder();<br> builder.addPackageFromDrl( source );<br> Package pkg = builder.getPackage();<br> RuleBase ruleBase =
RuleBaseFactory.newRuleBase();<br> ruleBase.addPackage( pkg );<br> return ruleBase;<br> }<br> public static class MyDeligate <br> {<br> public boolean executeCondition1()<br> {<br> System.out.println("Executed Condition1");<br> return true;<br> }<br> public boolean executeCondition2()<br> {<br> System.out.println("Executed Condition2");<br> return true;<br> }<br>
public boolean executeCondition3()<br> {<br> System.out.println("Executed Condition3");<br> return true;<br> }<br> <br> public boolean executeAction1()<br> {<br> System.out.println("Executed Action1");<br> return true;<br> }<br> public boolean executeAction2()<br> {<br> System.out.println("Executed Action2");<br>
return true;<br> }<br> public boolean executeAction3()<br> {<br> System.out.println("Executed Action3");<br> return true;<br> }<br> }<br>}<br><br>Regards<br>Ramarao</div></div><br>
<!--1--><hr size=1></hr> Download prohibited? No problem. <a href="http://in.rd.yahoo.com/tagline_webmessenger_1/*http://in.messenger.yahoo.com/webmessengerpromo.php">CHAT</a> from any browser, without download.</body></html>