Please ignore the syntax in this posting. Yes, it is suppose to be like this:<br><br>public abstract class Base {<br><br>}<br><br>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.<br>
<br>Thanks!<br><br><div class="gmail_quote">On Mon, May 4, 2009 at 10:57 AM, Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Well, we can start out with the fact that this is improper java syntax:<br>
<br>
class abstract Base () {}<br>
<br>
The () is not in a class declaration. Does this code compile for you? :)<br>
<br>
--- On Mon, 5/4/09, tellkb <<a href="mailto:tellkb@gmail.com">tellkb@gmail.com</a>> wrote:<br>
<br>
> From: tellkb <<a href="mailto:tellkb@gmail.com">tellkb@gmail.com</a>><br>
> Subject: [rules-users] setGlobal issue in StatefulSession<br>
> To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> Date: Monday, May 4, 2009, 12:35 PM<br>
<div><div></div><div class="h5">> Hi there,<br>
><br>
> I want to set setGlobal in working memory at run time based<br>
> on derived<br>
> class, e.g. DerivedOne or DerivedTwo. But it throws<br>
> following error:<br>
><br>
> Illegal class for global. Expected<br>
> [org.comp.app.bean.Base], found<br>
> [org.comp.app.bean.DerivedOne].<br>
><br>
><br>
> It should automatically resolve the derived class. Please<br>
> let me know if I'm<br>
> doing something wrong. I'd appreciate your help.<br>
><br>
><br>
> Thanks,<br>
> -KB<br>
><br>
> Here are the classed I'm using in my test project:<br>
><br>
><br>
> class abstract Base () {<br>
><br>
> public void init( StatefulSession workingMemory ) {<br>
> this.workingMemory = workingMemory;<br>
> workingMemory.setGlobal("app", this);<br>
> }<br>
> public void logMe() {<br>
> System.out.println("From Derived BASE...");<br>
> }<br>
> }<br>
><br>
> class DerivedOne() extends Base{<br>
> public void runRules( Object obj) {<br>
> ObjOne obj1 = (ObjOne)obj<br>
> workingMemory.insert(obj1);<br>
> workingMemory.fireAllRules();<br>
> workingMemory.dispose();<br>
> }<br>
> public void logMe() {<br>
> System.out.println("From Derived ONE...");<br>
> }<br>
> }<br>
><br>
> class DerivedTwo() extends Base{<br>
> public void runRules( Object obj) {<br>
> ObjTwo obj2 = (ObjTwo)obj<br>
> workingMemory.insert(obj2);<br>
> workingMemory.fireAllRules();<br>
> workingMemory.dispose();<br>
> }<br>
> public void logMe() {<br>
> System.out.println("From Derived ONE...");<br>
> }<br>
> }<br>
><br>
><br>
> class Caller() {<br>
><br>
> RuleBase ruleBase = ruleBaseFactory.open(docRules);<br>
> workingMemory = ruleBase.newStatefulSession();<br>
><br>
> if (sub==1) {<br>
> der1 = new DerivedOne();<br>
> der1.init(workingMemory);<br>
> der1.runRules();<br>
> }<br>
> else if (sub==1) {<br>
> der2 = new DerivedTwo();<br>
> der2.init(workingMemory);<br>
> der2.runRules();<br>
> }<br>
> }<br>
><br>
> //********DRL FILE*****<br>
> package com.sample<br>
><br>
> import com.sample.app.RuleCaller.Message;<br>
><br>
> global com.sample.app.Base app;<br>
><br>
> rule "using a static function"<br>
> when<br>
> eval( true )<br>
> then<br>
> System.out.println( "Message from Rule." );<br>
> app.logMe();<br>
> end<br>
> //********DRL FILE*****<br>
> --<br>
> View this message in context:<br>
> <a href="http://www.nabble.com/setGlobal-issue-in-StatefulSession-tp23373008p23373008.html" target="_blank">http://www.nabble.com/setGlobal-issue-in-StatefulSession-tp23373008p23373008.html</a><br>
> Sent from the drools - user mailing list archive at<br>
> Nabble.com.<br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>