[rules-users] dynamically generated classes, drools classloader, and jsr-94
Martin Schoch
mschoch at reisys.com
Tue Mar 13 16:34:17 EDT 2007
The application I'm working on will use facts which are dynamically
generated classes. After reading
http://jira.jboss.com/jira/browse/JBRULES-557 I figured out the trick to
get this working was to pass the ClassLoader responsible for the dynamic
classes to drools. So I set things up something like:
PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
pbc.setCompiler(PackageBuilderConfiguration.JANINO);
pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());
PackageBuilder builder = new PackageBuilder(pbc);
Using this approach I am able to execute rules which interact with the
properties of the dynamically generated classes. The problem I've run
into is that I'd really like to work with the JSR-94 API. I have two
questions:
1. Is the code I referenced above using the correct approach? Or am I
already headed down the wrong path?
2. Would passing additional configuration details into the properties
argument of the call
ruleExecutionSetProvider.createRuleExecutionSet(drlStream, properties)
be advisable? I have created a proof of concept to test this and
included a patch. Using this approach the application code looks
something like this:
PackageBuilderConfiguration pbc = new PackageBuilderConfiguration();
pbc.setCompiler(PackageBuilderConfiguration.JANINO);
pbc.setClassLoader(instanceOfDynamicallyGeneratedClass.getClass().getCla
ssLoader());
Map localProperties = new HashMap();
localProperties.put("packageBuilderConfiguration", pbc);
RuleExecutionSet ruleExecutionSet =
ruleExecutionSetProvider.createRuleExecutionSet(drlStream,
localProperties);
Obviously this introduces a JBossRules dependency into my application
code, but I am otherwise able to stick to the JSR-94 APIs.
I have attached a patch to support this new property and welcome
comments on this solution.
Thanks,
Marty Schoch
<mschoch at reisys.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pbc-jsr94.patch
Type: application/octet-stream
Size: 2009 bytes
Desc: pbc-jsr94.patch
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20070313/d211d89e/attachment.obj
More information about the rules-users
mailing list