use of java.beans.PropertyChangeSupport in project simplejpa by appoxy.
the class BeansCglib method newInstance.
public static Object newInstance(Class clazz) {
try {
BeansCglib interceptor = new BeansCglib();
Enhancer e = new Enhancer();
e.setSuperclass(clazz);
e.setCallback(interceptor);
Object bean = e.create();
interceptor.propertySupport = new PropertyChangeSupport(bean);
return bean;
} catch (Throwable e) {
e.printStackTrace();
throw new Error(e.getMessage());
}
}
use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.
the class TestPropertyChangeSupport method test.
private static void test(int step, int listeners, int attempts) {
TestPropertyChangeSupport test = new TestPropertyChangeSupport();
PropertyChangeSupport pcs = new PropertyChangeSupport(test);
PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
long time1 = System.currentTimeMillis();
for (int i = 0; i < listeners; i++) {
pcs.addPropertyChangeListener(test);
pcs.addPropertyChangeListener(NAME, test);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < attempts; i++) {
pcs.firePropertyChange(eventNull);
pcs.firePropertyChange(eventName);
}
long time3 = System.currentTimeMillis();
// time of adding the listeners
time1 = time2 - time1;
// time of firing the events
time2 = time3 - time2;
System.out.println("Step: " + step + "; Listeners: " + listeners + "; Attempts: " + attempts + "; Time (ms): " + time1 + "/" + time2);
}
use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.
the class Test4092905 method main.
public static void main(String[] args) {
PropertyChangeSupport pcs = new PropertyChangeSupport(args);
pcs.addPropertyChangeListener(PUBLIC, new PublicListener());
pcs.addPropertyChangeListener(PRIVATE, new PrivateListener());
if (!pcs.hasListeners(PUBLIC)) {
throw new Error("no public listener");
}
if (!pcs.hasListeners(PRIVATE)) {
throw new Error("no private listener");
}
try {
// serialize into byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream output = new ObjectOutputStream(baos);
output.writeObject(pcs);
output.flush();
// deserialize from byte array
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream input = new ObjectInputStream(bais);
pcs = (PropertyChangeSupport) input.readObject();
} catch (Exception exception) {
throw new Error("unexpected exception", exception);
}
if (!pcs.hasListeners(PUBLIC)) {
throw new Error("no public listener");
}
if (pcs.hasListeners(PRIVATE)) {
throw new Error("unexpected private listener");
}
}
use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.
the class Test4985020 method main.
public static void main(String[] args) {
PropertyChangeSupport pcs = new PropertyChangeSupport(args);
VetoableChangeSupport vcs = new VetoableChangeSupport(args);
Test4985020 listener = new Test4985020();
//PropertyChangeSupport.addPropertyChangeListener(null, listener)
System.out.println("PropertyChangeSupport.addPropertyChangeListener(null, listener)");
try {
pcs.addPropertyChangeListener(null, listener);
pcs.firePropertyChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.removePropertyChangeListener(null, listener)
System.out.println("PropertyChangeSupport.removePropertyChangeListener(null, listener)");
try {
pcs.removePropertyChangeListener(null, listener);
pcs.firePropertyChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.getPropertyChangeListeners(null)
System.out.println("PropertyChangeSupport.getPropertyChangeListeners(null)");
try {
PropertyChangeListener[] pcls = pcs.getPropertyChangeListeners(null);
if (pcls == null) {
throw new Error("getPropertyChangeListener() returned null");
}
if (pcls.length != 0) {
throw new Error("getPropertyChangeListener() did not return an empty array");
}
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.hasListeners(null)
System.out.println("PropertyChangeSupport.hasListeners(null)");
try {
pcs.hasListeners(null);
} catch (Throwable error) {
print(error);
}
//PropertyChangeSupport.hasListeners(null): with a generic listener
System.out.println("PropertyChangeSupport.hasListeners(null) with a generic listener");
try {
pcs.addPropertyChangeListener(listener);
if (!pcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned false, but there was a generic listener");
}
} catch (Throwable error) {
print(error);
}
// reset
pcs = new PropertyChangeSupport(args);
//PropertyChangeSupport.hasListeners(null): with a specific listener
System.out.println("PropertyChangeSupport.hasListeners(null) with a specific listener");
try {
pcs.addPropertyChangeListener(NAME, listener);
if (pcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
}
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.addVetoableChangeListener(null, listener)
System.out.println("VetoableChangeSupport.addVetoableChangeListener(null, listener)");
try {
vcs.addVetoableChangeListener(null, listener);
vcs.fireVetoableChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.removeVetoableChangeListener(null, listener)
System.out.println("VetoableChangeSupport.removeVetoableChangeListener(null, listener)");
try {
vcs.removeVetoableChangeListener(null, listener);
vcs.fireVetoableChange(NAME, null, null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.getVetoableChangeListeners(null)
System.out.println("VetoableChangeSupport.getVetoableChangeListeners(null)");
try {
VetoableChangeListener[] pcls = vcs.getVetoableChangeListeners(null);
if (pcls == null) {
throw new Error("getVetoableChangeListener() returned null");
}
if (pcls.length != 0) {
throw new Error("getVetoableChangeListener() did not return an empty array");
}
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.hasListeners(null)
System.out.println("VetoableChangeSupport.hasListeners(null)");
try {
boolean result = vcs.hasListeners(null);
} catch (Throwable error) {
print(error);
}
//VetoableChangeSupport.hasListeners(null): with a generic listener
System.out.println("VetoableChangeSupport.hasListeners(null) with a generic listener");
try {
vcs.addVetoableChangeListener(listener);
if (!vcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned false, but there was a generic listener");
}
} catch (Throwable error) {
print(error);
}
// reset
vcs = new VetoableChangeSupport(args);
//VetoableChangeSupport.hasListeners(null): with a specific listener
System.out.println("VetoableChangeSupport.hasListeners(null) with a specific listener");
try {
vcs.addVetoableChangeListener(NAME, listener);
if (vcs.hasListeners(null)) {
throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
}
} catch (Throwable error) {
print(error);
}
if (failed) {
throw new Error("TEST FAILED");
}
}
use of java.beans.PropertyChangeSupport in project tdi-studio-se by Talend.
the class Element method readObject.
// implemented in order to create listeners field
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
listeners = new PropertyChangeSupport(this);
}
Aggregations