[rules-users] How do i Load & Execute specific rules in my drl file

Mark Proctor mproctor at codehaus.org
Wed Jan 17 19:54:25 EST 2007


Rules are not functions, they cannot be called, they execute in response 
to changes in the working memory.

Mark
Raja.Bobbala at sanofi-aventis.com wrote:
>
> How do i load & execute specific rules in my drl file? For ex.,
> I have 5 rules defined in rules.drl
> *rule* "1"
>        * when*
>                 cond #1
>        * then*
>                 System.out.println("Applying Rule 1");
> *end*
>
> *rule* "2"
>        * when*
>                 cond #2
>        * then*
>                 System.out.println("Applying Rule 2");
> *end*
>
> *rule* "3"
>        * when*
>                 cond #3
>        * then*
>                 System.out.println("Applying Rule 3");
> *end*
>
> *rule* "4"
>        * when*
>                 cond #4
>        * then*
>                 System.out.println("Applying Rule 4");
> *end*
>
> *rule* "5"
>        * when*
>                 cond #5
>        * then*
>                 System.out.println("Applying Rule 5");
> *end*
>
> From my Java class, based on some conditions, i should call the 
> respective rules.
>
> public void CheckRules(){
>        
>         if (some Condition){
>                 // Execute rule1, rule2
>         }else if  (some Condition){
>                 // Execute rule1, rule3
>         }else if (some Condition){
>                 // Execute rule3, rule5
>         }else if (some Condition){
>                 // Execute rule1,rule2,rule3,rule5
>         }
> }
>
> PackageBuilder builder =* new* PackageBuilder();
> builder.addPackageFromDrl(*new* 
> InputStreamReader(FieldValidation.*class*.getResourceAsStream("/BizRules.drl"))); 
>
> RuleBase rulebase = RuleBaseFactory./newRuleBase/();
> rulebase.addPackage(builder.getPackage());
> */WorkingMemory workingMemory = rulebase.newWorkingMemory();      /*
> workingMemory.assertObject(/object1/);
> workingMemory.assertObject(/object2/);
> workingMemory.fireAllRules(*new* RuleNameEqualsAgendaFilter("1"));
>                
> workingMemory.clearAgenda();
> */WorkingMemory workingMemory1 = rulebase.newWorkingMemory();/*
> workingMemory1.assertObject(/object1/);
> workingMemory1.assertObject(/object2/);
> workingMemory1.fireAllRules(*new* RuleNameEqualsAgendaFilter("2"));
>
> Is there any way by which we can add specific rules to the 
> Agendafilter and call fireAllRules() with the rulelist as parameter.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070118/ab0c0d2c/attachment.html 


More information about the rules-users mailing list