After (naively) playing around with Jess/Bean
interactions, I'd thought I'd pass on a short list of
'things to be careful about'. Violating any of these
can lead to exceptions being raised that can be difficult
to trace back to the problem source.
1. Make sure your Bean is a public class.
2. Make sure the Bean's property methods are public.
3. For a property expressed as getFooBar, the firePropertyChange
property name is "fooBar".
4. Ensure you respect typing in your Jess rules. e.g.
Using Jess5.0a3, WinNT, Microsoft 3.1 SDK for Java,
In the pumps example, if you add the following 2 properties
to the Pump class in jess/examples/pumps/Pump.java
//////////////////////////////////
// Begin addition of 2 properties
private Object m_some_object;
public void setSomeObject(Object an_obj) {
System.out.println("Pump.setSomeObject(" + an_obj.getClass().getName() + " " +
an_obj + ") called");
Object old_object = m_some_object;
m_some_object = an_obj;
pcs.firePropertyChange("someObject", old_object,m_some_object);
}
private String m_some_string;
public void setSomeString(String a_string) {
System.out.println("Pump.setSomeString(" + a_string.getClass().getName() + " "
+ a_string + ") called");
String old_string = m_some_string;
m_some_string = a_string;
pcs.firePropertyChange("someString", old_string, m_some_string);
}
// end addition of 2 properties
////////////////////////////////
And augment the rule raise-rate-if-low in
jess/examples/pumps/pumps-fromjava.clp to be
(defrule raise-rate-if-low
?warning <- (warning low ?name)
(pump (name ?name) (flow ?flow-rate) (OBJECT ?pump))
(test (< ?flow-rate 25))
=>
(retract ?warning)
(set ?pump flow (+ ?flow-rate 5))
;; next line works fine
(set ?pump someString ?name)
;; next line raises exception
(set ?pump someObject ?name)
(printout t "Raised pumping rate of pump " ?name " to "
(get ?pump flow) crlf))
You will get the exception:
C:\Java\Jess50a3>jview jess.examples.pumps.MainInJava
WARNING: TANK MAIN IS LOW!
Pump.setSomeString(java.lang.String MAIN) called
Rete Exception in routine call while executing defrule raise-rate-if-low.
Message: No method 'setSomeObject' found or invalid argument types at line 0: ( run
1 ) .
at jess/reflect/Call.call (ReflectFunctions.java)
at jess/reflect/Set.call (ReflectFunctions.java)
at jess/Funcall.simpleExecute (Funcall.java)
at jess/Funcall.execute (Funcall.java)
at jess/Funcall.execute (Funcall.java)
at jess/Defrule.fire (Defrule.java)
at jess/Activation.fire (Activation.java)
at jess/Rete.run (Rete.java)
at jess/HaltEtc.call (Funcall.java)
at jess/Funcall.simpleExecute (Funcall.java)
at jess/Funcall.execute (Funcall.java)
at jess/Funcall.execute (Funcall.java)
at jess/Jesp.parseAndExecuteFuncall (Jesp.java)
at jess/Jesp.parseSexp (Jesp.java)
at jess/Jesp.parse (Jesp.java)
at jess/Rete.executeCommand (Rete.java)
at jess/examples/pumps/MainInJava.main (MainInJava.java)
^C
C:\Java\Jess50a3>
because ?name is a Jess string, not a java object.
-- Dan
Dan Larner, [EMAIL PROTECTED]
Xerox Parc, 3333 Coyote Hill Rd, Palo Alto CA 94304
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------