When I call firePropertyChange from my Java object after setting an
attribute the working memory of my engine is not updated.  I know this
because I loop through the facts before and after the setting of the
attribute, and "round" is set to "0" both times.

My Java and Jess code is below (if you're wondering why I have a class just
to wrap an int and string, it's to tie into some 3rd party code I don't have
control over).  Any idea what I'm doing wrong?

######## JAVA CLASS ########
package game.server;

import java.beans.*;
import java.io.*;
import java.nio.*;
import java.util.*;
import jess.*;

public class Round implements Serializable
{
    private static final long serialVersionUID = 1L;
    private int round;
    private String gameName;
    private PropertyChangeSupport propertyChange;

    protected Round(int round, String game)
    {
        this.round = round;
        gameName = game;
        propertyChange = new PropertyChangeSupport(this);
    }

    public int getRound()
    {
        return round;
    }

    public void setRound(int round)
    {
        if (this.round != round)
        {
            int oldValue = this.round;
            this.round = round;

            // Fire property change event so Jess working memory is updated
            propertyChange.firePropertyChange("round", new
Integer(oldValue), new Integer(this.round));
        }
    }

    public String getGameName()
    {
        return gameName;
    }

    public void setGameName(String game)
    {
        gameName = game;
    }


    public void addPropertyChangeListener(PropertyChangeListener listener)
    {
        propertyChange.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener
listener)
    {
        propertyChange.removePropertyChangeListener(listener);
    }

    public boolean equals(Object obj)
    {
        boolean equal = false;

        if (obj instanceof Round)
        {
            Round objRound = (Round)obj;
            equal = ((objRound.getRound() == round) &&
(objRound.getGameName() == gameName));
        }

        return equal;
    }

    public int hashCode()
    {
        // Game name never changes so hashCode is mutable
        return gameName.hashCode();
    }
}


######## JESS RULES ########
(import game.server.*)

(deftemplate Round (declare (from-class Round)))

(defrule process-round
    (Round {round >= 0} (round ?round))
    =>
    (printout t "Round " ?round crlf)
)

Reply via email to