1 /* 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package test; 25 26 import java.beans.PropertyChangeListener; 27 import java.beans.PropertyChangeSupport; 28 import java.util.EventListener; 29 import java.util.TooManyListenersException; 30 31 public class Accessor { 32 33 public static Class<?> getBeanType() { 34 return Bean.class; 35 } 36 37 public static Class<?> getListenerType() { 38 return TestListener.class; 39 } 40 } 41 42 interface TestEvent { 43 } 44 45 interface TestListener extends EventListener { 46 void process(TestEvent event); 47 } 48 49 class Bean { 50 51 private boolean b; 52 private int[] indexed; 53 private TestListener listener; 54 private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); 55 56 public void addPropertyChangeListener(PropertyChangeListener listener) { 57 this.pcs.addPropertyChangeListener(listener); 58 } 59 60 public void addTestListener(TestListener listener) throws TooManyListenersException { 61 if (listener != null) { 62 if (this.listener != null) { 63 throw new TooManyListenersException(); 64 } 65 this.listener = listener; 66 } 67 } 68 69 public void removeTestListener(TestListener listener) { 70 if (this.listener == listener) { 71 this.listener = null; 72 } 73 } 74 75 public TestListener[] getTestListeners() { 76 return (this.listener != null) 77 ? new TestListener[] { this.listener } 78 : new TestListener[0]; 79 } 80 81 public boolean isBoolean() { 82 return this.b; 83 } 84 85 public void setBoolean(boolean b) { 86 this.b = b; 87 } 88 89 public int[] getIndexed() { 90 return this.indexed; 91 } 92 93 public void setIndexed(int[] values) { 94 this.indexed = values; 95 } 96 97 public int getIndexed(int index) { 98 return this.indexed[index]; 99 } 100 101 public void setIndexed(int index, int value) { 102 this.indexed[index] = value; 103 } 104 }