<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>How do i Load &amp; Execute specific rules in my drl file</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Verdana">How do i load &amp; execute specific rules in my drl file? For ex.,</FONT>

<BR><FONT SIZE=2 FACE="Verdana">I have 5 rules defined in rules.drl</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;1&quot;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B></B><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">cond #1</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">Applying Rule 1&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>

<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">2</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B></B><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">cond #2</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">Applying Rule 2&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>

<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">3</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B></B><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">cond #3</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">Applying Rule 3&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>

<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">4</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B></B><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">cond #4</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">Applying Rule 4&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>

<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">5</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B></B><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">cond #5</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">Applying Rule 5&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>

<P><FONT SIZE=2 FACE="Verdana">From my Java class, based on some conditions, i should call the respective rules.</FONT>
</P>

<P><FONT SIZE=2 FACE="Verdana">public void CheckRules(){</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">if (some Condition){</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">// Execute rule1, rule2</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">}else if&nbsp; (some Condition){</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">// Execute rule1, rule3</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">}else if (some Condition){</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">// Execute rule3, rule5</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">}else if (some Condition){</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">// Execute rule1,rule2,rule3,rule5</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=2 FACE="Verdana">}</FONT>

<BR><FONT SIZE=2 FACE="Verdana">}</FONT>
</P>

<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">PackageBuilder builder =</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> PackageBuilder();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">builder.addPackageFromDrl(</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> InputStreamReader(FieldValidation.</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">class</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New">.getResourceAsStream(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;/BizRules.drl&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">)));</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">RuleBase rulebase = RuleBaseFactory.<I>newRuleBase</I>();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">rulebase.addPackage(builder.getPackage());</FONT>

<BR><B><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">WorkingMemory workingMemory = rulebase.newWorkingMemory();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT> </I></B>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory.assertObject(</FONT><I></I><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">object1</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory.assertObject(</FONT><I></I><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">object2</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory.fireAllRules(</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> RuleNameEqualsAgendaFilter(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;1&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">));</FONT>

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory.clearAgenda();</FONT>

<BR><B><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">WorkingMemory workingMemory1 = rulebase.newWorkingMemory();</FONT></I></B>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory1.assertObject(</FONT><I></I><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">object1</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory1.assertObject(</FONT><I></I><I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">object2</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">workingMemory1.fireAllRules(</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> RuleNameEqualsAgendaFilter(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">2</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">));</FONT>
</P>

<P><FONT SIZE=2 FACE="Verdana">Is there any way by which we can add specific rules to the Agendafilter and call fireAllRules() with the rulelist as parameter.</FONT></P>

</BODY>
</HTML>