Hi Francesco,

On Wed, Jul 2, 2008 at 10:28 AM, fmarchioni <[EMAIL PROTECTED]> wrote:
>
> Hi all drools users!
> I'm just learning Drools from the manual, I have a question about Dynamic
> Beans. I have added PropertyChangeSupport and listeners to my Beans: I can
> see that inside my rule, if I change
> one property the bean.....
>
> rule "Check Age"
>
> salience 20
>
>  when
>     b : Buyer (age <18)
>  then
>      bankApp.addMessage(Messages.AGE_UNDER_18);
>      b.setCash(40000); // CHANGE OF PROPERTY
> end
>
> ..then all rules are fired back again. Is it the correct behaviour ? is
> there a way to re-evaluate only some of the Rules back again ?
> thanks a lot
> Francesco
> --

that's strange. From my experience, only those rules that depend on
the cash property should be fired if the new value triggers an
activation that wouldn't have been triggered for the old value. Could
you post the code of your PropertyChangeSupport implementation?

Here's some sample code from one of my projects:

public abstract class BindObject { /* simple proxy */
        private PropertyChangeSupport propertyChangeSupport = new
PropertyChangeSupport(this);

    public void addPropertyChangeListener(PropertyChangeListener _listener) {
            propertyChangeSupport.addPropertyChangeListener(_listener);
    }

    public void addPropertyChangeListener(String _propertyName,
PropertyChangeListener _listener) {
            propertyChangeSupport.addPropertyChangeListener(_propertyName,
_listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener _listener) {
            propertyChangeSupport.removePropertyChangeListener(_listener);
    }

    public void removePropertyChangeListener(String _propertyName,
PropertyChangeListener _listener) {
            propertyChangeSupport.removePropertyChangeListener(_propertyName,
_listener);
    }

    protected void firePropertyChange(String _propertyName, Object
_oldValue, Object _newValue) {
            propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
    }

    protected void firePropertyChange(String _propertyName, int
_oldValue, int _newValue) {
            propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
    }

    protected void firePropertyChange(String _propertyName, boolean
_oldValue, boolean _newValue) {
            propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
    }
}

Now I simply inherit my classes from BindObject and write my setters like this:

public final static String PROPERTY_ARTICLE_NUMBER = "articleNumber";
public void setArticleNumber(String _articleNumber) {
        String oldValue = _articleNumber;
        articleNumber = _articleNumber;
        firePropertyChange(PROPERTY_ARTICLE_NUMBER, oldValue, articleNumber);
}

This has been working great for me so far.

HTH
Marcus
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to