[rules-users] Issues with groovy fact objects not matching

Ilya Sterin sterini at gmail.com
Mon Oct 26 23:51:18 EDT 2009


I figured it out, this was a class loader issue.  I wrote up a blog
post on the issue...

http://www.ilyasterin.com/blog/2009/10/java-multiple-class-loaders-issue.html

On Sun, Oct 25, 2009 at 4:06 PM, Ilya Sterin <sterini at gmail.com> wrote:
> 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
>




More information about the rules-users mailing list