Re: [rules-users] how to specify classpath dependencies in .drl files.
by Mark Proctor
Godmar Back wrote:
> On 9/26/07, Mark Proctor <mproctor(a)codehaus.org> wrote:
>
>> Godmar Back wrote:
>> [off list]
>>
>>
>> Like I said, I doubt that this works.
>>
>> Classloaders don't produce the bytecode a compiler needs. It's not
>> part of their interface.
>>
>> Don't produce what bytecode? If you are dynnamically loading classes are
>> runtime, that .class has the bytecode. This is what people are doing now
>> already with web services. Drools has its own runtime compiler and will
>> compile fine against dynamically loaded classes in a parent classloader.
>>
>>
>
> No, that's not how class loaders work.
> A class loader, fundamentally, implements a method
>
Um I think I know how classloaders work, Drools does some pretty complex
class loader behaviour.
> public Class loadClass(String name) throws ClassNotFoundException
>
> that maps class names to class objects. For instance, the name
> "org.jboss.pkg.SomeClass" may be mapped to an object of type
> java.lang.Class - such as one that would be returned by defineClass().
>
> Although the class loader internally reads the content of .class files
> - either from a URL, from a jar, or from disk, there is no interface
> to obtain the actual bytecode from a class loader.
> There is no method: "byte [] getByteCode(String name)". A class loader
> will internally read the (bytes constituting) a .class file, then
> passes it to "defineClass()", which is where the JVM parses the
> bytecode and creates a java.lang.Class instance.
>
A user can also provide the bytecode to the classloader.
> A compiler that is compiling code that refers to a class needs access
> to that class's bytecode, directly. Access to a class object as
> provided by a ClassLoader is insufficient. (Also, it would be
> dangerous - reflexive examination may trigger a "first active use"
> (See JLS - 12.4.1 in 1st edition) - you don't want the compilation to
> trigger static initializers of referred classes.)
>
No the compiler simply needs to have the dependant class available in
the current or parent classloader, it does not need the bytecode. The
class can be dynamically added to the parent classloader, at runtime,
before you start the compilation.
> Given that, the drools compiler would need to have a way to load the
> actual bytecode, something a classloader cannot provide.
>
> Hence my suggestion to enhance it allow a user-controlled way of
> providing that bytecode.
>
> - Godmar
>
>
17 years, 3 months
Firing single rule
by marimuthu.balasubramanian@wipro.com
Hi ,
I have 10 rules in my .drl file. how can i fire specific rule?
Regards
Marimuthu
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
17 years, 3 months
eval() not working in Spring environment
by Brian Enderle
I am not sure where exactly this problem lies but I can create the following
rule in a Drools project and have it execute as expected but when i use the
exact same rule in my Spring application/environment it does not work.
Within DroolsTest.java:
Boolean performCheck = new Boolean("true");
statefulSession.setGlobal("performCheck", performCheck);
Within the rule file:
global java.lang.Boolean performCheck;
rule "Display if true"
when
eval(performCheck)
then
System.out.println(performCheck);
end
When I run DroolsTest I get the output of 'true', the value of performCheck,
as I would expect. When I use the same rule in my Spring environment the rule
fails to execute. I know the gloabl is getting to the rule with a value
of "true" as I have a second rule which always fires and reports the value of
performCheck.
Has anyone ever experienced this and if so did you find any solution?
Thanks in advance,
Brian Enderle
17 years, 3 months
escaping backslash in matches clauses (documentation bug?)
by Godmar Back
The documentation states that '\' occurring in matches clauses do not
need escaping. However, unescaped '\' cause this error message when
compiling the .drl file:
Exception in thread "main" org.drools.rule.InvalidRulePackage: Unable
to determine the used declarations : [Rule name=Apply XML Descriptor,
agendaGroup=MAIN, salience=0, no-loop=false]
at org.drools.rule.Package.checkValidity(Package.java:419)
at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:292)
Escaping the '\' as is customary in Java makes the code work.
- Godmar
17 years, 3 months
Comparing multiple instances of the same object
by Brian Enderle
I have 3 Rfrnc objects that I would like to compare and return a message if
the firstNm, middleNm and lastNm of two objects match. I set up the Rfrnc
objects with the names "Brian A Enderle", "Brian B Enderle" and "Brian C
Enderle" and created the following rule (with the intent of building up to
checking first, middle and last name).
rule "LevelTwo: Duplicate Reference check"
agenda-group "LevelTwo"
when
$i : Rfrnc($firstNm : firstNm, $middleNm : middleNm, $lastNm :
lastNm)
$j : Rfrnc(this != $i, firstNm == $firstNm)
then
System.out.println("Duplicate refernce found: " +
$i.getMiddleNm() + $i.getLastNm() + ":" + $j.getMiddleNm() + $j.getLastNm());
end
This produces the following output (which is what I would expect):
Duplicate refernce found: CEnderle:BEnderle
Duplicate refernce found: BEnderle:CEnderle
Duplicate refernce found: CEnderle:AEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: AEnderle:BEnderle
Duplicate refernce found: BEnderle:AEnderle
While doing some testing I changed "Brian B Enderle" to "Brian A Enderle" so
that now I have two Rfrnc objects with the name of "Brian A Enderle". When I
rerun the same rule from above I get the following output:
Duplicate refernce found: CEnderle:AEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: CEnderle:AEnderle
What I don't understand is why do I not have any return statements
of "Duplicate reference found AEnderle:AEnderle". I would expect 2 of these
messages, one for when the first "Brian A Enderle" object is compared to the
second and vice versa.
Is the "$i == this" condition checking values within the object itself? Am I
missing something here as to how this rule should work?
Thanks in advance,
Brian Enderle
17 years, 3 months
eval() not working as expected
by Brian Enderle
I am having a problem with eval() which can be found here:
http://rafb.net/p/GnneUd12.html.
Sorry for not posting the question here but I kept getting a top-posting
error. If anyone knows why I would get the top-posting error I would love to
know why.
Thanks in advance,
Brian Enderle
17 years, 3 months
and these...
by Manukyan, Sergey
Does anyone else see those errors? They occur when using "Outline" view
in Eclipse.
**********************
** LEGAL DISCLAIMER **
**********************
This E-mail message and any attachments may contain
legally privileged, confidential or proprietary
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of
this message to the intended recipient(s), you are
hereby notified that any dissemination, distribution
or copying of this E-mail message is strictly
prohibited. If you have received this message in
error, please immediately notify the sender and
delete this E-mail message from your computer.
17 years, 3 months