1 package test; 2 3 import java.beans.PropertyChangeListener; 4 import java.beans.PropertyChangeSupport; 5 import java.util.EventListener; 6 import java.util.TooManyListenersException; 7 8 public class Accessor { 9 10 public static Class<?> getBeanType() { 11 return Bean.class; 12 } 13 14 public static Class<?> getListenerType() { 15 return TestListener.class; 16 } 17 } 18 19 interface TestEvent { 20 } 21 22 interface TestListener extends EventListener { 23 void process(TestEvent event); 24 } 25 26 class Bean { 27 28 private boolean b; 29 private int[] indexed; 30 private TestListener listener; 31 private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); 32 33 public void addPropertyChangeListener(PropertyChangeListener listener) { 34 this.pcs.addPropertyChangeListener(listener); 35 } 36 37 public void addTestListener(TestListener listener) throws TooManyListenersException { 38 if (listener != null) { 39 if (this.listener != null) { 40 throw new TooManyListenersException(); 41 } 42 this.listener = listener; 43 } 44 } 45 46 public void removeTestListener(TestListener listener) { 47 if (this.listener == listener) { 48 this.listener = null; 49 } 50 } 51 52 public TestListener[] getTestListeners() { 53 return (this.listener != null) 54 ? new TestListener[] { this.listener } 55 : new TestListener[0]; 56 } 57 58 public boolean isBoolean() { 59 return this.b; 60 } 61 62 public void setBoolean(boolean b) { 63 this.b = b; 64 } 65 66 public int[] getIndexed() { 67 return this.indexed; 68 } 69 70 public void setIndexed(int[] values) { 71 this.indexed = values; 72 } 73 74 public int getIndexed(int index) { 75 return this.indexed[index]; 76 } 77 78 public void setIndexed(int index, int value) { 79 this.indexed[index] = value; 80 } 81 }