Hi,
My goal is to capture fact modification events for shadow facts.
I have a Java class which I use to create a def template:
(import FactChanged)
(deftemplate FactChanged
(declared (from-class FactChanged)
(include-variables TRUE)))
I define the following to capture fact modification events:
(deffunction display-fact-modified-from-event (?evt)
(bind ?ets (?evt toString))
(bind ?et (?evt getType))
(bind ?et1 (get ?evt type))
(if (eq ((bit-or (JessEvent.FACT) (JessEvent.MODIFIED)) (get ?evt
type)) then
(printout t "modified fact:" (call (call ?evt getObject) getName)
crlf))))
; install the above function using a JessEventAdapter
(call (engine) addJessListener
(new JessEventAdapter display-fact-modified-from-event (engine)))
; add FACT|MODIFIED to the event mask
(set (engine) eventMask
(bit-or (get (engine) eventMask) (JessEvent.MODIFIED) (JessEvent.FACT)))
I add a new Java object
; create a new instance of FactChanged
(bind ?data (new FactChanged))
(add ?data)
I then get the shadow fact and modify it
(bind ?datafact (call (engine) getShadowFactForObject ?data))
(modify ?datafact (data "Once Upon A Time"))
I expected to receive an event for fact modified but did not receive.
Using JessDE to look at the event type I saw 16, which is
JessEvent.Fact.
I can capture fact assertions but not fact modifications.
This seems to be related to the fact being a shadow fact instead of a
regular fact.
The java class is simple:
public class FactChanged implements Serializable {
private PropertyChangeSupport pcs = new
PropertyChangeSupport(this);
public String data;
public FactChanged () {
data = "original";
}
public String getData() {
return data;
}
public void setData(String data) {
String oldData = this.data;
this.data = data;
pcs.firePropertyChange("FactChanged ", oldData, data);
System.out.println("DataChanged occurred");
}
public void addPropertyChangeListener(PropertyChangeListener
pcl) {
pcs.addPropertyChangeListener(pcl);
}
public void removePropertyChangeListener(PropertyChangeListener
pcl) {
pcs.removePropertyChangeListener(pcl);
}
}
Any help will be appreciated.
Son Nguyen.