1/* 2 * Copyright (c) 2007, 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/* 25 * @test 26 * @bug 6194788 27 * @summary Tests bound property in PropertyDescriptor/PropertyEditorSupport 28 * @author Sergey Malenkov 29 */ 30 31import java.beans.IndexedPropertyDescriptor; 32import java.beans.IntrospectionException; 33import java.beans.PropertyChangeListener; 34import java.beans.PropertyDescriptor; 35 36public class Test6194788 { 37 public static void main(String[] args) throws IntrospectionException { 38 test(Grand.class, new PropertyDescriptor("index", Grand.class)); 39 test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName")); 40 41 test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class)); 42 test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class)); 43 44 test(Child.class, new PropertyDescriptor("childIndex", Child.class)); 45 test(Child.class, new IndexedPropertyDescriptor("childName", Child.class)); 46 } 47 48 private static void test(Class type, PropertyDescriptor property) { 49 for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) { 50 boolean forward = pd.equals(property); 51 boolean backward = property.equals(pd); 52 if (forward || backward) { 53 if (forward && backward) 54 return; 55 56 throw new Error("illegal comparison of properties"); 57 } 58 } 59 throw new Error("could not find property: " + property.getName()); 60 } 61 62 public static class Grand { 63 public int getIndex() { 64 return 0; 65 } 66 67 public void setIndex(int index) { 68 } 69 70 public String getName(int index) { 71 return null; 72 } 73 74 public void setName(int index, String name) { 75 } 76 } 77 78 public static class Parent { 79 public void addPropertyChangeListener(PropertyChangeListener listener) { 80 } 81 82 public void removePropertyChangeListener(PropertyChangeListener listener) { 83 } 84 85 public int getParentIndex() { 86 return 0; 87 } 88 89 public void setParentIndex(int index) { 90 } 91 92 public String[] getParentName() { 93 return null; 94 } 95 96 public String getParentName(int index) { 97 return null; 98 } 99 100 public void setParentName(String[] names) { 101 } 102 103 public void setParentName(int index, String name) { 104 } 105 } 106 107 public static class Child { 108 public int getChildIndex() { 109 return 0; 110 } 111 112 public void setChildIndex(int index) { 113 } 114 115 public String[] getChildName() { 116 return null; 117 } 118 119 public String getChildName(int index) { 120 return null; 121 } 122 123 public void setChildName(String[] names) { 124 } 125 126 public void setChildName(int index, String name) { 127 } 128 } 129} 130