Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.beans

Class VetoableChangeSupport

java.lang.Object
|
+--java.beans.VetoableChangeSupport

All Implemented Interfaces:

Serializable


public class VetoableChangeSupport

extends Object

implements Serializable

VetoableChangeSupport makes it easy to fire vetoable change events and handle listeners. It allows chaining of listeners, as well as filtering by property name. In addition, it will serialize only those listeners which are serializable, ignoring the others without problem. This class is thread-safe.

Since:Authors:

Constructor Summary

VetoableChangeSupport(java.lang.Object source)

Create a VetoableChangeSupport to work with a specific source bean.

Method Summary

synchronized voidaddVetoableChangeListener(java.beans.VetoableChangeListener l)

Adds a VetoableChangeListener to the list of global listeners.
synchronized voidaddVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener l)

Adds a VetoableChangeListener listening on the specified property.
voidfireVetoableChange(java.lang.String propertyName, java.lang.Object oldVal, java.lang.Object newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name.
voidfireVetoableChange(java.lang.String propertyName, int oldVal, int newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name.
voidfireVetoableChange(java.lang.String propertyName, boolean oldVal, boolean newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name.
voidfireVetoableChange(java.beans.PropertyChangeEvent event)

Fire a PropertyChangeEvent to all the global listeners, and to all the listeners for the specified property name.
synchronized java.beans.VetoableChangeListener[]getVetoableChangeListeners()

Returns an array of all registered vetoable change listeners.
synchronized java.beans.VetoableChangeListener[]getVetoableChangeListeners(java.lang.String propertyName)

Returns an array of all vetoable change listeners registered under the given property name.
synchronized booleanhasListeners(java.lang.String propertyName)

Tell whether the specified property is being listened on or not.
synchronized voidremoveVetoableChangeListener(java.beans.VetoableChangeListener l)

Removes a VetoableChangeListener from the list of global listeners.
synchronized voidremoveVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener l)

Removes a VetoableChangeListener from listening to a specific property.

Constructor Details

VetoableChangeSupport

public VetoableChangeSupport(java.lang.Object source)

Create a VetoableChangeSupport to work with a specific source bean.

Parameters:

Throws:


Method Details

addVetoableChangeListener

public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener l)

Adds a VetoableChangeListener to the list of global listeners. All vetoable change events will be sent to this listener. The listener add is not unique: that is, n adds with the same listener will result in n events being sent to that listener for every vetoable change. Adding a null listener may cause a NullPointerException down the road. This method will unwrap a VetoableChangeListenerProxy, registering the underlying delegate to the named property list.

Parameters:


addVetoableChangeListener

public synchronized void addVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener l)

Adds a VetoableChangeListener listening on the specified property. Events will be sent to the listener only if the property name matches. The listener add is not unique; that is, n adds on a particular property for a particular listener will result in n events being sent to that listener when that property is changed. The effect is cumulative, too; if you are registered to listen to receive events on all vetoable changes, and then you register on a particular property, you will receive change events for that property twice. Adding a null listener may cause a NullPointerException down the road. This method will unwrap a VetoableChangeListenerProxy, registering the underlying delegate to the named property list if the names match, and discarding it otherwise.

Parameters:

Throws:


fireVetoableChange

public void fireVetoableChange(java.beans.PropertyChangeEvent event)

Fire a PropertyChangeEvent to all the global listeners, and to all the listeners for the specified property name. This does nothing if old and new values of the event are equal. If the change is vetoed, a new event is fired to notify listeners about the rollback before the exception is thrown.

Parameters:

Throws:


fireVetoableChange

public void fireVetoableChange(java.lang.String propertyName, boolean oldVal, boolean newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name. This does nothing if old and new are equal. If the change is vetoed, a new event is fired to notify listeners about the rollback before the exception is thrown.

Parameters:

Throws:


fireVetoableChange

public void fireVetoableChange(java.lang.String propertyName, int oldVal, int newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name. This does nothing if old and new are equal. If the change is vetoed, a new event is fired to notify listeners about the rollback before the exception is thrown.

Parameters:

Throws:


fireVetoableChange

public void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldVal, java.lang.Object newVal)

Fire a PropertyChangeEvent containing the old and new values of the property to all the global listeners, and to all the listeners for the specified property name. This does nothing if old and new are non-null and equal. If the change is vetoed, a new event is fired to notify listeners about the rollback before the exception is thrown.

Parameters:

Throws:


getVetoableChangeListeners

public synchronized VetoableChangeListener[] getVetoableChangeListeners()

Returns an array of all registered vetoable change listeners. Those that were registered under a name will be wrapped in a VetoableChangeListenerProxy, so you must check whether the listener is an instance of the proxy class in order to see what name the real listener is registered under. If there are no registered listeners, this returns an empty array.

Since:Returns:

See Also:


getVetoableChangeListeners

public synchronized VetoableChangeListener[] getVetoableChangeListeners(java.lang.String propertyName)

Returns an array of all vetoable change listeners registered under the given property name. If there are no registered listeners, this returns an empty array.

Since:Parameters:

Returns:

Throws:


hasListeners

public synchronized boolean hasListeners(java.lang.String propertyName)

Tell whether the specified property is being listened on or not. This will only return true if there are listeners on all properties or if there is a listener specifically on this property.

Parameters:

Returns:

Throws:


removeVetoableChangeListener

public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener l)

Removes a VetoableChangeListener from the list of global listeners. If any specific properties are being listened on, they must be deregistered by themselves; this will only remove the general listener to all properties. If add() has been called multiple times for a particular listener, remove() will have to be called the same number of times to deregister it. This method will unwrap a VetoableChangeListenerProxy, removing the underlying delegate from the named property list.

Parameters:


removeVetoableChangeListener

public synchronized void removeVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener l)

Removes a VetoableChangeListener from listening to a specific property. If add() has been called multiple times for a particular listener on a property, remove() will have to be called the same number of times to deregister it. This method will unwrap a VetoableChangeListenerProxy, removing the underlying delegate from the named property list if the names match.

Parameters:

Throws: