use of java.beans.VetoableChangeListener in project commons-lang by apache.
the class EventListenerSupportTest method testRemoveListenerDuringEvent.
@Test
public void testRemoveListenerDuringEvent() throws PropertyVetoException {
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
for (int i = 0; i < 10; ++i) {
addDeregisterListener(listenerSupport);
}
assertEquals(listenerSupport.getListenerCount(), 10);
listenerSupport.fire().vetoableChange(new PropertyChangeEvent(new Date(), "Day", 4, 5));
assertEquals(listenerSupport.getListenerCount(), 0);
}
use of java.beans.VetoableChangeListener in project jdk8u_jdk by JetBrains.
the class Test7148143 method main.
public static void main(String[] args) {
VetoableChangeListener listener = new CustomProxy();
VetoableChangeSupport support = new VetoableChangeSupport(listener);
support.addVetoableChangeListener(listener);
// cast class exception
support.addVetoableChangeListener("foo", listener);
}
use of java.beans.VetoableChangeListener in project jdk8u_jdk by JetBrains.
the class BeanContextSupport method initialize.
/**
* protected method called from constructor and readObject to initialize
* transient state of BeanContextSupport instance.
*
* This class uses this method to instantiate inner class listeners used
* to monitor PropertyChange and VetoableChange events on children.
*
* subclasses may envelope this method to add their own initialization
* behavior
*/
protected synchronized void initialize() {
children = new HashMap(serializable + 1);
bcmListeners = new ArrayList(1);
childPCL = new PropertyChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
* property changes from a child to the BeanContext, avoiding
* accidential serialization of the BeanContext by a badly
* behaved Serializable child.
*/
public void propertyChange(PropertyChangeEvent pce) {
BeanContextSupport.this.propertyChange(pce);
}
};
childVCL = new VetoableChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
* vetoable changes from a child to the BeanContext, avoiding
* accidential serialization of the BeanContext by a badly
* behaved Serializable child.
*/
public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
BeanContextSupport.this.vetoableChange(pce);
}
};
}
use of java.beans.VetoableChangeListener in project commons-lang by apache.
the class EventUtilsTest method testAddEventListenerWithPrivateAddMethod.
@Test
public void testAddEventListenerWithPrivateAddMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".");
EventUtils.addEventListener(src, VetoableChangeListener.class, listener);
}
use of java.beans.VetoableChangeListener in project commons-lang by apache.
the class EventListenerSupportTest method testSubclassInvocationHandling.
@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {
final EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(VetoableChangeListener.class) {
private static final long serialVersionUID = 1L;
@Override
protected java.lang.reflect.InvocationHandler createInvocationHandler() {
return new ProxyInvocationHandler() {
/**
* {@inheritDoc}
*/
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return "vetoableChange".equals(method.getName()) && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null : super.invoke(proxy, method, args);
}
};
}
};
final VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
eventListenerSupport.addListener(listener);
final Object source = new Date();
final PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
final PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
listener.vetoableChange(respond);
EasyMock.replay(listener);
eventListenerSupport.fire().vetoableChange(ignore);
eventListenerSupport.fire().vetoableChange(respond);
EasyMock.verify(listener);
}
Aggregations