Setting a global that is a subclass of the global reference works fine. See attached
code.
--- On Mon, 5/4/09, Mere Huzoor <tellkb(a)gmail.com> wrote:
From: Mere Huzoor <tellkb(a)gmail.com>
Subject: Re: [rules-users] setGlobal issue in StatefulSession
To: greg_barton(a)yahoo.com, "Rules Users List"
<rules-users(a)lists.jboss.org>
Date: Monday, May 4, 2009, 1:39 PM
Please ignore the syntax in this posting. Yes, it is suppose
to be like
this:
public abstract class Base {
}
I would appreciate if you can explain how I can achieve the
polymorphism
behavior in drools (explained in my example). FYI I'm
using version 4.0.7.
Thanks!
On Mon, May 4, 2009 at 10:57 AM, Greg Barton
<greg_barton(a)yahoo.com> wrote:
>
> Well, we can start out with the fact that this is
improper java syntax:
>
> class abstract Base () {}
>
> The () is not in a class declaration. Does this code
compile for you? :)
>
> --- On Mon, 5/4/09, tellkb <tellkb(a)gmail.com>
wrote:
>
> > From: tellkb <tellkb(a)gmail.com>
> > Subject: [rules-users] setGlobal issue in
StatefulSession
> > To: rules-users(a)lists.jboss.org
> > Date: Monday, May 4, 2009, 12:35 PM
> > Hi there,
> >
> > I want to set setGlobal in working memory at run
time based
> > on derived
> > class, e.g. DerivedOne or DerivedTwo. But it
throws
> > following error:
> >
> > Illegal class for global. Expected
> > [org.comp.app.bean.Base], found
> > [org.comp.app.bean.DerivedOne].
> >
> >
> > It should automatically resolve the derived
class. Please
> > let me know if I'm
> > doing something wrong. I'd appreciate your
help.
> >
> >
> > Thanks,
> > -KB
> >
> > Here are the classed I'm using in my test
project:
> >
> >
> > class abstract Base () {
> >
> > public void init( StatefulSession
workingMemory ) {
> > this.workingMemory = workingMemory;
> >
workingMemory.setGlobal("app", this);
> > }
> > public void logMe() {
> > System.out.println("From
Derived BASE...");
> > }
> > }
> >
> > class DerivedOne() extends Base{
> > public void runRules( Object obj) {
> > ObjOne obj1 = (ObjOne)obj
> > workingMemory.insert(obj1);
> > workingMemory.fireAllRules();
> > workingMemory.dispose();
> > }
> > public void logMe() {
> > System.out.println("From
Derived ONE...");
> > }
> > }
> >
> > class DerivedTwo() extends Base{
> > public void runRules( Object obj) {
> > ObjTwo obj2 = (ObjTwo)obj
> > workingMemory.insert(obj2);
> > workingMemory.fireAllRules();
> > workingMemory.dispose();
> > }
> > public void logMe() {
> > System.out.println("From
Derived ONE...");
> > }
> > }
> >
> >
> > class Caller() {
> >
> > RuleBase ruleBase =
ruleBaseFactory.open(docRules);
> > workingMemory =
ruleBase.newStatefulSession();
> >
> > if (sub==1) {
> > der1 = new DerivedOne();
> > der1.init(workingMemory);
> > der1.runRules();
> > }
> > else if (sub==1) {
> > der2 = new DerivedTwo();
> > der2.init(workingMemory);
> > der2.runRules();
> > }
> > }
> >
> > //********DRL FILE*****
> > package com.sample
> >
> > import com.sample.app.RuleCaller.Message;
> >
> > global com.sample.app.Base app;
> >
> > rule "using a static function"
> > when
> > eval( true )
> > then
> > System.out.println( "Message from
Rule." );
> > app.logMe();
> > end
> > //********DRL FILE*****
> > --
> > View this message in context:
> >
>
http://www.nabble.com/setGlobal-issue-in-StatefulSession-tp23373008p23373...
> > Sent from the drools - user mailing list archive
at
> >
Nabble.com.
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>