I have an application that dynamically compiles a groovy object with
properties and uses it as a bean class. The object is a statically
defined object, though...
package com.buycentives.types
import com.buycentives.incengine.*
class TestIncentive extends IncentiveData<MonetaryIncentive> {
String name
Integer age
}
The rules compile just fine, as I load the groovy class using a
GroovyClassLoader and inject the groovy class loader like this...
PackageBuilderConfiguration config = new PackageBuilderConfiguration();
config.setClassLoader(loader);
JavaDialectConfiguration dialectConf = (JavaDialectConfiguration)
config.getDialectConfiguration("java");
dialectConf.setCompiler(JavaDialectConfiguration.JANINO);
KnowledgeBuilder kBldr = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
/// Here I add some rules to the builder...
KnowledgeBase kb = KnowledgeBaseFactory.newKnowledgeBase(new
RuleBaseConfiguration(loader));
kb.addKnowledgePackages(kBldr.getKnowledgePackages());
So the rule actually resolves the TestIncentive type just fine, but it
never fires the side effect, as the pattern never seems to match.
TestIncentive incentive = new TestIncentive();
incentive.setAge(25);
// Below never matches...
$input: TestIncentive( age >= 20, age < 30 )
I verify that the injected object actually has an age of 25...
The crazy thing is, that this rule...
$input: Object()
matches the TestIncentive fact in the knowledge base and when I print
out the object in the side effect, it's the same as the one injected,
so it should match the pattern above just fine.
The same rules work just fine when I use a plain Java object or if I
declare a fact type in the drl file.
Any ideas?
Ilya Sterin