Bean Internals  «Prev 

Practical Examples of Constrained Properties

A practical example where a constrained property would come in handy is the case of a property that represents a date.
An application might want to validate a change in the date property to make sure it stays within a particular range,
the current year for instance.
If an attempt is made to set the property to a date outside of the current year, the application can reject the change.
Middleware: WSGI Applications that do not do anything alone, but work in between the request and your application.

Veto Constrained Property Value Change

An object with constrained properties allows other objects to veto a constrained property value change. Constrained property listeners can veto a change by throwing a PropertyVetoException. The JellyBean class in demo\sunw\demo\jelly\ has a constrained property called PriceInCents.
public class JellyBean extends Canvas {
 private PropertyChangeSupport changes = new PropertyChangeSupport(this);
 private VetoableChangeSupport vetos =new VetoableChangeSupport(this);
 public void setPriceInCents(int newPriceInCents) throws PropertyVetoException {
  int oldPriceInCents = ourPriceInCents;
  vetos.fireVetoableChange("priceInCents",
  new Integer(oldPriceInCents),
  new Integer(newPriceInCents));
  ourPriceInCents = newPriceInCents;
  changes.firePropertyChange("priceInCents",
  new Integer(oldPriceInCents),
  new Integer(newPriceInCents));
}

 public
  void addVetoableChangeListener(VetoableChangeListener l) {
  vetos.addVetoableChangeListener(l);
 }
 public
  void removeVetoableChangeListener(VetoableChangeListener l) {
  vetos.removeVetoableChangeListener(l);
 }