In special circumstances, it may be useful to know when attributes are being changed, what the old and new values are, or the order in which attributes are changed. Circumstances where this might be useful include rule coverage utilities, step-through debuggers, or similar runtime rule analysis tools. For these situations, an AttributeChangeListener can be written to observe attributes being changed during inferencing.
Attribute change events are similar to inferencing events. A class must be created that implements the AttributeChangeListener interface. The interface declares two methods, inferredAttribute() and userChangedAttribute(). The inferredAttribute() method receives an AttributeChangeEvent object whenever the Oracle Determinations Engine infers a value different from the current value. The userChangedAttribute() method receives an AttributeChangeEvent object whenever the user sets a new value.
The AttributeChangeEvent object includes various properties such as the EntityInstance in which the change occurred, the Attribute to be changed, and the new value of the Attribute. The old value can be access using the provided Attribute and EntityInstance objects directly.
The following is a simple example of an attribute change listener. It outputs the name of the Attribute being changed, and the new value of the Attribute.