[rules-users] Challenge! Using javassist and drools presents an issue with drl

markricard markricard at gmail.com
Wed Apr 28 12:40:29 EDT 2010


In order to make writing drl files easy and not requiring writers to be
developers, I have written some JavaAssist code that dynamically creates a
subclass and new methods in memory.   

If for example there is a REAL java class called 'com.foo.Instance'.  Via
javasssist, I create a new in-memory subclass called 'com.foo.InstanceEx'.  
The new class dynamically creates a new getter called getFoo().    The drl
writer would like to directly reference 'foo' in the drl file like so:

when
     i : Instance(foo == 'fee')

The problem is, in order to reference foo, I would need the drl file to do
this:

import com.rrd.xspace.drools.InstanceEx;

But I cannot do that because InstanceEx does not exist at runtime.   The
error I get, which is an obvious one, is "Unable to create Field Extractor
for 'foo' of '[ClassObjectType class=com.foo.Instance]' in rule 'Test' :
[Rule name='Test']"

Is there a way to include a dynamic import of a JavaAssist class while I am
constructing the KnowledgeBase instances to run the rules so that I can
reference that new method?

I would hope to have something similar to:

KnowledgeBuilder kbuilder = ....
kbuilder.addImport("com.foo.InstanceEx")

or 

kbuilder.addClass(Class.forName("com.foo.InstanceEx"))


Any help GREATLY appreciated.
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Challenge-Using-javassist-and-drools-presents-an-issue-with-drl-tp763086p763086.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list