[rules-users] Globals from functions...

Wolfgang Laun wolfgang.laun at gmail.com
Thu Jul 21 02:20:43 EDT 2011


Global "variables" aren't plain old Java variables; they are kept in a
wrapped map. Functions are passed to a Java compiler "as is", with only the
import list added to the compilation unit.

So you can use a global in a DRL function

   - by passing it as a parameter,
   - by accessing the global via the interface org.drools.runtime.Globals,
   which requires that you have the session object available so you can do
   kSession.getGlobals().

The second option brings us back to square 1: you can't use a global... But
a public static from any application class might be used - imports are
available in functions. Which, after all, could be used for your 'x' in the
first place.

-W





On 21 July 2011 00:13, bob.breitling <bob.breitling at rrd.com> wrote:

> I have a global defined and I am trying to use it from a function.  When my
> rule gets loaded into my knowledge base, I always get an error complaining
> about the global not being resolved.
>
> ---- simplified snippet ----
>
> global int x;
>
> function void foo(int n) {
>    x = n;
> }
>
> ------------------------------
>
> I get this kind of error "Function Compilation error: foo (line:20) x can
> not resolved".
>
> Should this work?
>
> TIA,
>
> Bob
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Globals-from-functions-tp3186882p3186882.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110721/5a4e262c/attachment.html 


More information about the rules-users mailing list