The Source for Java Technology Collaboration
User: Password:



Evan Summers

Evan Summers's Blog

Bound Gooey Beans

Posted by evanx on February 05, 2007 at 03:07 AM | Comments (0)

Bound Gooey Beans

In the Gooey Beans Info prequel, we explicitly declare properties. Now we allow a bean info instance to be bound to a specific bean, in order to support bound properties ie. firing PropertyChangeEvent's.


Code Snippet

In our bean, we instantiate a bound bean info class with PropertyChangeSupport as follows.

public class BakedBean {
    public final BakedBeanInfo info = new BakedBeanInfo(this);
    
    private BigInteger barcode;
    private String label;
    private Integer bakingTemparature;
    private BigDecimal medianLength;
    ...   
    public BakedBean() {
    }
    ...
    public void setBarcode(BigInteger barcode) {
        this.barcode = barcode;
        info.barcode.firePropertyChanged(barcode);
    }
}

where we use property "literals" from our bean info to firePropertyChanged().

We can add PropertyChangeListener's as follows.

public class BakedBeanDemo implements PropertyChangeListener, Runnable {
    BakedBean bean = new BakedBean();
    ...
    public BakedBeanDemo() {
        ...
        bean.info.getPropertyChangeSupport().addPropertyChangeListener(this);
    }
    ...    
}   

bakedBeansDemo



Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds