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

Raja.Bobbala at sanofi-aventis.com Raja.Bobbala at sanofi-aventis.com
Wed Jan 17 11:14:32 EST 2007


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070117/224a1f00/attachment.html 


More information about the rules-users mailing list