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

Mark Proctor mproctor at codehaus.org
Tue Sep 28 11:26:22 EDT 2010


  On 29/04/2010 09:38, Swindells, Thomas wrote:
> Isn't the simplest solution just to add the imports at the start of the imported drl file?
> That is the users don't need to worry about writing the imports but before you feed the files into your code simply prepends the required imports.
>
> You can do this easily in memory with something like the following:
> StringWriter drlContents = new StringWriter();
> drlContents.write("import ...\n");
> FileInputStream stream = new FileInputStream(drlFile);
> InputStreamReader inR = new InputStreamReader(stream, "UTF-8");
> IOUtils.copy(inR, drlContents);
> kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drlContents.toString())),                             ResourceType.DRL);
Make sure you generate the classes first and put them into a 
classloader. Then specify that ClassLoader as the root classload to the 
kbuilder and kbase configurations.

Mark
> Thomas
>
>> -----Original Message-----
>> From: rules-users-bounces at lists.jboss.org [mailto:rules-users-
>> bounces at lists.jboss.org] On Behalf Of Dave Cracauer
>> Sent: 28 April 2010 19:35
>> To: Rules Users List; rules-users at lists.jboss.org
>> Subject: Re: [rules-users] Challenge! Using javassist and drools presents an
>> issue with drl
>>
>>
>> It sounds like the stated goal is to make things easier for non-developers to
>> write rules. What about a dsl?
>>
>> What about using a templating language?  I have used velocity in the past for
>> dynamically generating rules based on templates, and I think that there is
>> built in support for templates using mvel.
>>
>> -----Original Message-----
>>> From: markricard<markricard at gmail.com>
>>> Sent: Apr 28, 2010 11:53 AM
>>> To: rules-users at lists.jboss.org
>>> Subject: Re: [rules-users] Challenge! Using javassist and drools presents an
>> issue with drl
>>>
>>> Perhaps there is an easier way to ask this question....
>>>
>>> Rather than having to do an 'import' of a class in a drl text file, is there
>>> a way in the Java code that constructs the KnowledgeBase to via java
>>> dynamically import any class file required by any drl file that is added?
>>>
>>> Instead of the drl having:
>>>
>>> import com.foo.Instance;
>>> rule "Walgreens Test"
>>>     ....
>>>
>>> It just has:
>>>
>>> rule "Walgreens Test"
>>>     ....
>>>
>>>
>>> And in the KnowledgeBuilder does something like this:
>>>
>>> KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
>>> kbuilder.addImport("com.foo.Instance");
>>> ...
>>>
>>>
>>>
>>> --
>>> View this message in context: http://drools-java-rules-
>> engine.46999.n3.nabble.com/Challenge-Using-javassist-and-drools-presents-an-
>> issue-with-drl-tp763086p763118.html
>>> Sent from the Drools - User mailing list archive at Nabble.com.
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> **************************************************************************************
> This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.
>
> NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
> **************************************************************************************
>
> This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
> To protect the environment please do not print this e-mail unless necessary.
>
> An NDS Group Limited company. www.nds.com
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>





More information about the rules-users mailing list