|
Spec-Zone .ru
спецификации, руководства, описания, API
|
public class VetoableChangeSupport extends Object implements Serializable
PropertyChangeEvents им. Можно использовать экземпляр этого class как задействованное поле Вашего боба и делегировать эти типы работы к этому. VetoableChangeListener может быть зарегистрирован для всех свойств или для свойства, определенного по имени. Вот пример VetoableChangeSupport использование, которое следует за правилами и рекомендациями, размеченными в спецификации JavaBeans™:
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 экземпляр ориентирован на многопотоковое исполнение.
Этот class сериализуем. Когда это будет сериализировано, это спасет (и восстановление) любых слушателей, которые самостоятельно сериализуемы. Любые несериализуемые слушатели будут пропущены во время сериализации.
PropertyChangeSupport, Сериализированная Форма| Конструктор и Описание |
|---|
VetoableChangeSupport(Object sourceBean)
Конструкции a
VetoableChangeSupport объект. |
| Модификатор и Тип | Метод и Описание |
|---|---|
void |
addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
Добавьте VetoableChangeListener для определенного свойства.
|
void |
addVetoableChangeListener(VetoableChangeListener listener)
Добавьте VetoableChangeListener к списку слушателя.
|
void |
fireVetoableChange(PropertyChangeEvent event)
Запускает событие изменения свойства в слушателей, которые были зарегистрированы, чтобы отследить обновления всех свойств или свойства с указанным именем.
|
void |
fireVetoableChange(String propertyName, boolean oldValue, boolean newValue)
Сообщает булево ограниченное обновление свойства слушателям, которые были зарегистрированы, чтобы отследить обновления всех свойств или свойства с указанным именем.
|
void |
fireVetoableChange(String propertyName, int oldValue, int newValue)
Сообщает целое число об ограниченном обновлении свойства слушателям, которые были зарегистрированы, чтобы отследить обновления всех свойств или свойства с указанным именем.
|
void |
fireVetoableChange(String propertyName, Object oldValue, Object newValue)
Сообщает ограниченное обновление свойства слушателям, которые были зарегистрированы, чтобы отследить обновления всех свойств или свойства с указанным именем.
|
VetoableChangeListener[] |
getVetoableChangeListeners()
Возвращает массив всех слушателей, которые были добавлены к объекту VetoableChangeSupport с addVetoableChangeListener ().
|
VetoableChangeListener[] |
getVetoableChangeListeners(String propertyName)
Возвращает массив всех слушателей, которые были связаны с именованным свойством.
|
boolean |
hasListeners(String propertyName)
Проверьте, есть ли какие-либо слушатели для определенного свойства, включая зарегистрированных на всех свойствах.
|
void |
removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
Удалите VetoableChangeListener для определенного свойства.
|
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Удалите VetoableChangeListener из списка слушателя.
|
public VetoableChangeSupport(Object sourceBean)
VetoableChangeSupport объект.sourceBean - Боб, который будет дан как источник для любых событий.public void addVetoableChangeListener(VetoableChangeListener listener)
listener нуль, никакое исключение не выдается, и никакие меры не предпринимаются.listener - VetoableChangeListener, который будет добавленpublic void removeVetoableChangeListener(VetoableChangeListener listener)
listener был добавлен не раз к тому же самому источнику события, он будет уведомлен один меньше времени, будучи удаленным. Если listener нуль, или никогда не добавлялся, никакое исключение не выдается, и никакие меры не предпринимаются.listener - VetoableChangeListener, который будет удаленpublic VetoableChangeListener[] getVetoableChangeListeners()
Если некоторые слушатели были добавлены с именованным свойством, то возвращенный массив будет смесью VetoableChangeListeners и VetoableChangeListenerProxys. Если метод вызова интересуется различением слушателей тогда, это должно протестировать каждый элемент, чтобы видеть, является ли это a VetoableChangeListenerProxy, выполните бросок, и исследуйте параметр.
VetoableChangeListener[] listeners = bean.getVetoableChangeListeners();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof VetoableChangeListenerProxy) {
VetoableChangeListenerProxy proxy =
(VetoableChangeListenerProxy)listeners[i];
if (proxy.getPropertyName().equals("foo")) {
// proxy is a VetoableChangeListener which was associated
// with the property named "foo"
}
}
}
VetoableChangeListeners added or an
empty array if no listeners have been addedVetoableChangeListenerProxypublic void addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
propertyName or listener is null, no
exception is thrown and no action is taken.propertyName - The name of the property to listen on.listener - The VetoableChangeListener to be addedpublic void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
listener was added more than once to the same event
source for the specified property, it will be notified one less time
after being removed.
If propertyName is null, no exception is thrown and no
action is taken.
If listener is null, or was never added for the specified
property, no exception is thrown and no action is taken.propertyName - The name of the property that was listened on.listener - The VetoableChangeListener to be removedpublic VetoableChangeListener[] getVetoableChangeListeners(String propertyName)
propertyName - The name of the property being listened toVetoableChangeListeners associated with
the named property. If no such listeners have been added,
or if propertyName is null, an empty array is
returned.public void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException
Any listener can throw a PropertyVetoException to veto the update.
If one of the listeners vetoes the update, this method passes
a new "undo" PropertyChangeEvent that reverts to the old value
to all listeners that already confirmed this update
and throws the PropertyVetoException again.
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(PropertyChangeEvent) method.
propertyName - the programmatic name of the property that is about to changeoldValue - the old value of the propertynewValue - the new value of the propertyPropertyVetoException - if one of listeners vetoes the property updatepublic void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException
Any listener can throw a PropertyVetoException to veto the update.
If one of the listeners vetoes the update, this method passes
a new "undo" PropertyChangeEvent that reverts to the old value
to all listeners that already confirmed this update
and throws the PropertyVetoException again.
No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
fireVetoableChange(String, Object, Object) method.
propertyName - the programmatic name of the property that is about to changeoldValue - the old value of the propertynewValue - the new value of the propertyPropertyVetoException - if one of listeners vetoes the property updatepublic void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException
Any listener can throw a PropertyVetoException to veto the update.
If one of the listeners vetoes the update, this method passes
a new "undo" PropertyChangeEvent that reverts to the old value
to all listeners that already confirmed this update
and throws the PropertyVetoException again.
No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
fireVetoableChange(String, Object, Object) method.
propertyName - the programmatic name of the property that is about to changeoldValue - the old value of the propertynewValue - the new value of the propertyPropertyVetoException - if one of listeners vetoes the property updatepublic void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException
Any listener can throw a PropertyVetoException to veto the update.
If one of the listeners vetoes the update, this method passes
a new "undo" PropertyChangeEvent that reverts to the old value
to all listeners that already confirmed this update
and throws the PropertyVetoException again.
No event is fired if the given event's old and new values are equal and non-null.
event - the PropertyChangeEvent to be firedPropertyVetoException - if one of listeners vetoes the property updatepublic boolean hasListeners(String propertyName)
propertyName
is null, only check for listeners registered on all properties.propertyName - the property name.
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.
DRAFT ea-b92