[rules-users] Pass Parameter to drools file dynamically

rjr201 rich.j.riley at gmail.com
Fri Mar 15 06:34:54 EDT 2013


I'm a bit confused as to how this relates to your previous post. Where are
you getting the exception?

Something like this would work: 

 File dsl = new File("Path of your rule");
 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbuilder.add(ResourceFactory.newFileResource(dsl), ResourceType.DRL); 
 
 KnowledgeBase kbase = kbuilder.newKnowledgeBase();
 StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
        
 FactType airlineType = kbase.getFactType("droolshelloworld", "Airline"); 
 Object ob = airlineType.newInstance(); 
 airlineType.set(ob, "name", "//Airline"); 
        
 session.insert(ob); 
 session.fireAllRules(); 

And your rule looks like this: 

declare Airline 
 name:String 
end 

rule"Test"
 
when 
	message:Airline(name=="//Airline") 
then 
	System.out.println("Hello Richa....."); 
end

As I said in my previous post. You really need to read some tutorials on
this. 



--
View this message in context: http://drools.46999.n3.nabble.com/Pass-Parameter-to-drools-file-dynamically-tp4022820p4022835.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list