Your Bean basically "lies" about its support for
PropertyChangeEvents. In the definstance call, you tell Jess that the
bean supports them, and when Jess looks for the
addPropertyChangeListener() method, it's there. So Jess assumes that
when it calls setCustomerName() on your bean, a PropertyChangeEvent
will be generated, and Jess will receive that event and act on it by
changing the contents of the shadow fact.

But actually, your bean sends no PropertyChangeEvents whatsoever, so
Jess's assumptions are wrong. If you have an
addPropertyChangeListener() method, that means that when your bean's
properties change, you promise to send an event notifying the
listeners about it; but you're not keeping your promise!

I think Xuelian Bian wrote:
> Hi,
> 
> I got a problem with JavaBean slot updating from Jess script.  I wrote the 
> Jess script and Java code as following. I defined a customer shadow fact in 
> Jess and add a customer instance to working memory then I found the rule 
> 'bronze-customer' is fired, but the corresponding attribute 'customerType' in 
> customer bean hadn't been changed at all. 
> Could you find the problem for me? Thank you in advance.
> 
> Jess script fragment
> (defclass customer ecommerce.Customer)
> (defrule bronze-customer
>     ?c <- (customer (shopAccount ?r&:(not (eq ?r nil))) )
>     =>
>    (modify ?c (customerType 1)))
> 
>   
> The Customer bean is:
> public class Customer {
>       
>       private String customername;
>       private ShopAccount account;
>       private int customerType;
>       
>       // The constructor
>       public Customer(String aCustomerName) {
>               customername = aCustomerName;
>       }
> 
>       // Get the customer name
>       public String getCustomerName() {
>               return customername;
>       }
> 
>       // Set the customer name
>       public void setCustomerName(String string) {
>               customername = string;
>       }
>       
>       public void setShopAccount(ShopAccount a){
>               account = a;
>       }
>       
>       public ShopAccount getShopAccount(){
>               return account;
>       }
>       
>       //set the customer type
>       public void setCustomerType(int type){
>               customerType = type;
>       }
>       
>       public int getCustomerType(){
>               return customerType;
>       }
>       
>       public boolean hasShopAccount(){
>               if(this.account != null)
>                       return true;
>               return false;
>       }
>       
>       private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
>       public void addPropertyChangeListener(PropertyChangeListener p)
>       {
>               pcs.addPropertyChangeListener(p);
>       }
>       public void removePropertyChangeListener(PropertyChangeListener p)
>       {
>               pcs.removePropertyChangeListener(p);
>       }
> }
> 
> And the adding of customer instance to Jess working memory from Java:
>               Customer customerjan = new Customer("Jan");
>               
>               Rete engine = new Rete();
>               engine.watchAll();
>               String rulesFile = "/shopAP.clp";               
>               try
>               {
>             engine.executeCommand("(batch \"" + rulesFile + "\")");
>                       engine.reset();
>                       engine.definstance("customer",customerjan,true);
>                                       
>               }catch(JessException je)
>               {
>                       System.out.println(je.getLineNumber());
>                       System.out.println(je.getProgramText());
>                       System.out.println(je.getMessage());
>               }
> 
> 
> 
> 
> Best regards, 
>   
> Xuelian
> [EMAIL PROTECTED]
> 
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to