I can't seem to install more than one bean into a running RETE engine
using definstance. Can anyone help?
I'm writing a rule-based system to provide "policy guidance" for a
large Enterprise Java information system. I plan to use Java beans
for communications between the RETE engine and the rest of the
system. Other components will install beans to provide factual
information about specific situations, Jess will apply the system's
rules, then the modules requesting guidance will use a
PropertyChangeListener to receive information back from "their" bean.
This means I must install more than one bean in a running engine, but
I can't seem to do that. Im am using the Java funcall interface. (I
can't see any way to do it.)
The beans come from several related classes. They all have different
data (Each one has a unique sequence number just to guarantee this.),
but I can't install more than one bean in the engine. This is true if
the no matter whether the second bean belongs to a different class or
is merely is a different instance of the same class as the first. The
order in which I install the classes doesn't seem to matter, the first
bean gets installed and the second doesn't.
This is a big problem on a project already running late.
I have included the code and the output. I've added some explanatory
notes and reformatted the output slightly to make it easier to read.
I'd appreciate any help.
Peter Olsen
********************************************************
This is the overall driver program.
IMSOperator and IMSOperand are subclasses of IMSOpera.
IMSOpera and IMSAccessBean are subclasses of IMSPolicyBean.
********************************************************
public static void accessPermissionTest() throws Exception{
try{
LogEntry.setLogStream
(new ObjectOutputStream(new FileOutputStream("/tmp/logger")));
staticDebug("\n\n****> accessPermissionTest: \n");
IMSSecurityEngine e = new IMSSecurityEngine();
IMSOperator a = new IMSOperator(new IMSOpera("frank", "T"));
IMSOperand b = new IMSOperand(new IMSOpera("Pizza", "C"));
IMSAccessBean c = new IMSAccessBean(a,b);
IMSOperator d = new IMSOperator(new IMSOpera("lou", "S"));
IMSOperand f = new IMSOperand(new IMSOpera("Nachos", "T"));
e.reset();
System.out.println(a.toString());
System.out.println(b.toString());
System.out.println(c.toString());
System.out.println(d.toString());
System.out.println(f.toString());
e.insertBean(a);
e.insertBean(c);
e.insertBean(b);
e.insertBean(d);
e.insertBean(f);
staticDebug("\nFacts just before reset.");
e.reset();
staticDebug("\nAbout to execute defrule.");
String rule = ("(defrule testRule"
+ "(policy.IMSOperator (uid ?u))"
+ "=>"
+ "(printout t \"Rule Executed\"))");
staticDebug("\nRule to execute:\n"+rule);
e.executeCommand(rule);
e.run();
staticDebug("\nFacts just after running.");
e.executeCommand("(facts)");
}catch(JessException je){
System.out.println("constructorTest: JessException");
System.out.println(je.toString());
}catch(PolicyException pe){
System.out.println("constructorTest: PolicyException");
System.out.println(pe.toString());
}
}
}
}
*****************************************************************
This is the method (from another class) that performs the actual
definstance. The class in which this runs is a subclass of
jess.rete.
*****************************************************************
public FactIDValue defInstanceBean(IMSPolicyBean b, String t)
throws JessException{
jess.FactIDValue result = null;
// Execution context for Funcall
Context c = getGlobalContext();
// Get the name of the bean's class. This will be the "tag" for
// the template.
String cl = b.getClass().getName();
// Start the funcall for definstance.
Funcall fDI = new Funcall("definstance", this);
// The bean's class name is the tag
fDI.add(new Value(cl, RU.STRING) );
// The bean's external address
fDI.add(new Value(b));
// Type, "static" or "dynamic"
fDI.add(new Value(t, RU.STRING));
// Function execution returns a jess.Value, a superclass of
// jess.FactIDValue
Value tmpresult = fDI.execute(c);
if(tmpresult instanceof jess.FactIDValue){
result = (jess.FactIDValue) tmpresult;
debug("\nBean was installed: " + b.getSequenceNumber());
executeCommand("(facts)");
debug("\n");
}else{
result = null;
}
return result;
}
******************************************************
Here is the output. This test was run as part of Unit Testing using
Bruce Eckel's UnitTest class.
******************************************************
cd /home/pcolsen/D.Projects/D.IMS/policy/
java com.bruceeckel.test.RunUnitTests policy.IMSSecurityEngine
static:
****> accessPermissionTest:
IMSOpera: entering constructor.
IMSOpera: entering constructor.
IMSOpera: entering constructor.
IMSOpera: entering constructor.
policy.IMSOperator:
globallyUniqueID: 2
class: class policy.IMSOperator
newState: false
comment:
basicClassName: IMSOperator
empty: true
uid: frank
securityAccessLevel:
notes:
compartments:
type: IMSOperator
sequenceNumber: 2
clearance: T
policy.IMSOperand:
globallyUniqueID: 6
class: class policy.IMSOperand
newState: false
classification: C
comment:
basicClassName: IMSOperand
empty: true
securityAccessLevel:
notes:
caveats:
type: IMSOperand
sequenceNumber: 6
title: Pizza
policy.IMSAccessBean:
globallyUniqueID: 9
class: class policy.IMSAccessBean
newState: false
comment:
basicClassName: IMSAccessBean
empty: true
uid: frank
notes:
type: IMSAccessBean
sequenceNumber: 9
title: Pizza
policy.IMSOperator:
globallyUniqueID: 4
class: class policy.IMSOperator
newState: false
comment:
basicClassName: IMSOperator
empty: true
uid: lou
securityAccessLevel:
notes:
compartments:
type: IMSOperator
sequenceNumber: 4
clearance: S
policy.IMSOperand:
globallyUniqueID: 8
class: class policy.IMSOperand
newState: false
classification: T
comment:
basicClassName: IMSOperand
empty: true
securityAccessLevel:
notes:
caveats:
type: IMSOperand
sequenceNumber: 8
title: Nachos
IMSSecurityEngine:
Bean was installed: 6
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID nil) (globallyUniqueID "6")
(groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
IMSSecurityEngine:
IMSSecurityEngine:
Bean was installed: 8
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID nil) (globallyUniqueID "6")
(groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
IMSSecurityEngine:
IMSSecurityEngine:
Bean was installed: 2
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID nil) (globallyUniqueID "6")
(groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
IMSSecurityEngine:
IMSSecurityEngine:
Bean was installed: 4
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID nil) (globallyUniqueID "6")
(groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
IMSSecurityEngine:
IMSSecurityEngine:
Bean was installed: 9
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID nil) (globallyUniqueID "6")
(groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
IMSSecurityEngine:
static: About to execute defrule.
f-0 (initial-fact)
f-1 (policy.IMSOperand (basicClassName "IMSOperand") (caveats
<External-Address:policy.StringVector>) (class <External-Address:java.lang.Class>)
(classification "C") (comment "") (empty TRUE) (factID <Fact-1>) (globallyUniqueID
"6") (groups nil) (needToKnow nil) (newState FALSE) (notes
<External-Address:policy.StringVector>) (organizations nil) (role nil)
(securityAccessLevel "") (sequenceNumber 6) (specialAccesses nil) (title "Pizza")
(type "IMSOperand") (OBJECT <External-Address:policy.IMSOperand>))
For a total of 2 facts.
Process com.bruceeckel.test.RunUnitTests finished
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------