PropertyChangeEvent
s to them. You can use an instance of this class
as a member field of your bean and delegate these types of work to it.
The VetoableChangeListener
can be registered for all properties
or for a property specified by name.
Here is an example of VetoableChangeSupport
usage that follows
the rules and recommendations laid out in the JavaBeans specification:
public class MyBean {
private final VetoableChangeSupport vcs = new VetoableChangeSupport(this);
public void addVetoableChangeListener(VetoableChangeListener listener) {
this.vcs.addVetoableChangeListener(listener);
}
public void removeVetoableChangeListener(VetoableChangeListener listener) {
this.vcs.removeVetoableChangeListener(listener);
}
private String value;
public String getValue() {
return this.value;
}
public void setValue(String newValue) throws PropertyVetoException {
String oldValue = this.value;
this.vcs.fireVetoableChange("value", oldValue, newValue);
this.value = newValue;
}
[...]
}
A VetoableChangeSupport
instance is thread-safe.
This class is serializable. When it is serialized it will save (and restore) any listeners that are themselves serializable. Any non-serializable listeners will be skipped during serialization.
PropertyChangeSupport
Modifier and Type | Class and Description |
---|---|
private static class | VetoableChangeSupport.
This is a |
Modifier and Type | Field and Description |
---|---|
private VetoableChangeSupport. | |
private static final ObjectStreamField[] | |
private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability. |
private Object | source
The object to be provided as the "source" for any generated events. |
Access | Constructor and Description |
---|---|
public | VetoableChangeSupport(Object
The bean to be given as the source for any events. sourceBean)Constructs a |
Modifier and Type | Method and Description |
---|---|
public void | addVetoableChangeListener(VetoableChangeListener
The VetoableChangeListener to be added listener)Add a VetoableChangeListener to the listener list. |
public void | addVetoableChangeListener(String
The name of the property to listen on. propertyName, VetoableChangeListener The VetoableChangeListener to be added listener)Add a VetoableChangeListener for a specific property. |
public void | fireVetoableChange(String
the programmatic name of the property that is about to change propertyName, Object the old value of the property oldValue, Object the new value of the property newValue)Reports a constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
public void | fireVetoableChange(String
the programmatic name of the property that is about to change propertyName, int the old value of the property oldValue, int the new value of the property newValue)Reports an integer constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
public void | fireVetoableChange(String
the programmatic name of the property that is about to change propertyName, boolean the old value of the property oldValue, boolean the new value of the property newValue)Reports a boolean constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
public void | fireVetoableChange(PropertyChangeEvent
the event)PropertyChangeEvent to be firedFires a property change event to listeners that have been registered to track updates of all properties or a property with the specified name. |
public VetoableChangeListener[] | Returns: all of theVetoableChangeListeners added or an
empty array if no listeners have been addedReturns an array of all the listeners that were added to the VetoableChangeSupport object with addVetoableChangeListener(). |
public VetoableChangeListener[] | Returns: all theVetoableChangeListeners associated with
the named property. If no such listeners have been added,
or if propertyName is null, an empty array is
returned.The name of the property being listened to propertyName)Returns an array of all the listeners which have been associated with the named property. |
public boolean | Returns: true if there are one or more listeners for the given propertythe property name. propertyName)Check if there are any listeners for a specific property, including those registered on all properties. |
private void | |
public void | removeVetoableChangeListener(VetoableChangeListener
The VetoableChangeListener to be removed listener)Remove a VetoableChangeListener from the listener list. |
public void | removeVetoableChangeListener(String
The name of the property that was listened on. propertyName, VetoableChangeListener The VetoableChangeListener to be removed listener)Remove a VetoableChangeListener for a specific property. |
private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites serializable fields to stream. |
map | back to summary |
---|---|
private VetoableChangeSupport. |
serialPersistentFields | back to summary |
---|---|
private static final ObjectStreamField[] serialPersistentFields
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Use serialVersionUID from JDK 1.1 for interoperability. |
source | back to summary |
---|---|
private Object source The object to be provided as the "source" for any generated events. |
VetoableChangeSupport | back to summary |
---|---|
public VetoableChangeSupport(Object sourceBean) Constructs a
|
addVetoableChangeListener | back to summary |
---|---|
public void addVetoableChangeListener(VetoableChangeListener listener) Add a VetoableChangeListener to the listener list.
The listener is registered for all properties.
The same listener object may be added more than once, and will be called
as many times as it is added.
If
|
addVetoableChangeListener | back to summary |
---|---|
public void addVetoableChangeListener(String propertyName, VetoableChangeListener listener) Add a VetoableChangeListener for a specific property. The listener
will be invoked only when a call on fireVetoableChange names that
specific property.
The same listener object may be added more than once. For each
property, the listener will be invoked the number of times it was added
for that property.
If
|
fireVetoableChange | back to summary |
---|---|
public void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException Reports a constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name.
Any listener can throw a No event is fired if old and new values are equal and non-null.
This is merely a convenience wrapper around the more general
|
fireVetoableChange | back to summary |
---|---|
public void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException Reports an integer constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name.
Any listener can throw a No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
|
fireVetoableChange | back to summary |
---|---|
public void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException Reports a boolean constrained property update to listeners that have been registered to track updates of all properties or a property with the specified name.
Any listener can throw a No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
|
fireVetoableChange | back to summary |
---|---|
public void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException Fires a property change event to listeners that have been registered to track updates of all properties or a property with the specified name.
Any listener can throw a No event is fired if the given event's old and new values are equal and non-null.
|
getVetoableChangeListeners | back to summary |
---|---|
public VetoableChangeListener[] getVetoableChangeListeners() Returns an array of all the listeners that were added to the VetoableChangeSupport object with addVetoableChangeListener().
If some listeners have been added with a named property, then
the returned array will be a mixture of VetoableChangeListeners
and
|
getVetoableChangeListeners | back to summary |
---|---|
public VetoableChangeListener[] getVetoableChangeListeners(String propertyName) Returns an array of all the listeners which have been associated with the named property.
|
hasListeners | back to summary |
---|---|
public boolean hasListeners(String propertyName) Check if there are any listeners for a specific property, including
those registered on all properties. If
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException Reads the
|
removeVetoableChangeListener | back to summary |
---|---|
public void removeVetoableChangeListener(VetoableChangeListener listener) Remove a VetoableChangeListener from the listener list.
This removes a VetoableChangeListener that was registered
for all properties.
If
|
removeVetoableChangeListener | back to summary |
---|---|
public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) Remove a VetoableChangeListener for a specific property.
If
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Writes serializable fields to stream.
|
ChangeListenerMap
implementation
that works with VetoableChangeListener
objects.
Modifier and Type | Field and Description |
---|---|
private static final VetoableChangeListener[] |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public VetoableChangeListener | extract(VetoableChangeListener listener)
Implements abstract java. |
protected VetoableChangeListener[] | Returns: an array with specified lengththe array length length)Implements abstract java. VetoableChangeListener objects.
|
protected VetoableChangeListener | Returns: aVetoableChangeListenerProxy objectthe name of the property to listen on name, VetoableChangeListener the listener to process events listener)Implements abstract java. VetoableChangeListenerProxy
object for the specified property.
|
EMPTY | back to summary |
---|---|
private static final VetoableChangeListener[] EMPTY |
VetoableChangeListenerMap | back to summary |
---|---|
private VetoableChangeListenerMap() |
extract | back to summary |
---|---|
public VetoableChangeListener extract(VetoableChangeListener listener) Implements abstract java. Doc from java. Extracts a real listener from the proxy listener. It is necessary because default proxy class is not serializable.
|
newArray | back to summary |
---|---|
protected VetoableChangeListener[] newArray(int length) Implements abstract java. Creates an array of
|
newProxy | back to summary |
---|---|
protected VetoableChangeListener newProxy(String name, VetoableChangeListener listener) Implements abstract java. Creates a
|