Hi All,
I like the look of Drools 3 very much and especially the use of expanders. I
have one slight query though. In the examples you give as follows:
package test
#must be in the following order.
import org.drools.Person
import org.drools.Cheese
#refer to test_expander.dsl
expander test_expander.dsl
global java.util.List messages;
rule "my rule"
when
#Person(name=="Bob", likes=="stilton")
#Cheese(type=="stilton")
There is a person with the name of Bob who likes stilton
There is some stilton cheese available
then
Add the message "We have a winner"
#messages.add("We have a winner");
end
Which is invoked using the following code:
public void testWithExpanderDSL() throws Exception {
PackageBuilder builder = new PackageBuilder();
Reader source = new
InputStreamReader(getClass().getResourceAsStream(
"rule_with_expander_dsl.drl" ));
Reader dsl = new
InputStreamReader(getClass().getResourceAsStream( "test_expander.dsl"
));
builder.addPackageFromDrl( source, dsl );
//the compiled package
Package pkg = builder.getPackage();
assertTrue( pkg.isValid() );
assertEquals(null, pkg.getErrorSummary());
//Check errors
String err = builder.printErrors();
assertEquals("", err);
assertEquals(0, builder.getErrors().length);
RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
WorkingMemory wm = ruleBase.newWorkingMemory();
wm.assertObject( new Person("Bob", "stilton") );
wm.assertObject( new Cheese("stilton", 42) );
List messages = new ArrayList();
wm.setGlobal( "messages", messages );
wm.fireAllRules();
//should have fired
assertEquals(1, messages.size());
}
Why is it necessary to specify the expander dsl file in both the .drl file
and as a parameter to the PackageBuilder.addPackageFromDrl method. Surely if
you are specifying the expander dsl in the drl file you shouldn't need to
pass it in as a parameter to the PackageBuilder method?
Nice work though guys. It's looking pretty damn good.