[rules-users] setGlobal issue in StatefulSession

tellkb tellkb at gmail.com
Mon May 4 13:35:39 EDT 2009


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-tp23373008p23373008.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list