1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7193977
* @summary Tests that generified property descriptors do not loose additional info
* @author Sergey Malenkov
*/
import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.util.Arrays;
import java.util.List;
public class Test7193977 {
private static final List<String> names = Arrays.asList("listType", "list", "value");
public static void main(String args[]) {
for (String name : names) {
test(Abstract.class, name);
test(Concrete.class, name);
}
}
private static void test(Class<?> type, String name) {
if (!Boolean.TRUE.equals(BeanUtils.getPropertyDescriptor(type, name).getValue("transient"))) {
throw new Error("property '" + name + "' is not transient");
}
}
public static final class Concrete extends Abstract<String> {
}
public static abstract class Abstract<T> {
private List<T> list;
public List<T> getList() {
return this.list;
}
public void setList(List<T> list) {
this.list = list;
}
public T getValue(int index) {
return (0 <= index) && (this.list != null) && (index < this.list.size())
? this.list.get(index)
: null;
}
public void setValue(int index, T value) {
if ((0 <= index) && (this.list != null)) {
if (index == this.list.size()) {
this.list.add(value);
}
else if (index < this.list.size()) {
this.list.set(index, value);
}
}
}
public String getListType() {
return (this.list != null)
? this.list.getClass().getName()
: null;
}
public void setListType(String type) throws Exception {
this.list = (type != null)
? (List<T>) Class.forName(type).newInstance()
: null;
}
}
public static final class ConcreteBeanInfo extends Wrapper {
public ConcreteBeanInfo() throws IntrospectionException {
super(Concrete.class);
}
}
public static final class AbstractBeanInfo extends Wrapper {
public AbstractBeanInfo() throws IntrospectionException {
super(Abstract.class);
for (PropertyDescriptor pd : getPropertyDescriptors()) {
if (names.contains(pd.getName())) {
pd.setValue("transient", Boolean.TRUE);
}
}
}
}
private static class Wrapper implements BeanInfo {
private final BeanInfo info;
Wrapper(Class<?> type) throws IntrospectionException {
this.info = Introspector.getBeanInfo(type, Introspector.IGNORE_IMMEDIATE_BEANINFO);
}
public BeanDescriptor getBeanDescriptor() {
return this.info.getBeanDescriptor();
}
public EventSetDescriptor[] getEventSetDescriptors() {
return this.info.getEventSetDescriptors();
}
public int getDefaultEventIndex() {
return this.info.getDefaultEventIndex();
}
public PropertyDescriptor[] getPropertyDescriptors() {
return this.info.getPropertyDescriptors();
}
public int getDefaultPropertyIndex() {
return this.info.getDefaultPropertyIndex();
}
public MethodDescriptor[] getMethodDescriptors() {
return this.info.getMethodDescriptors();
}
public BeanInfo[] getAdditionalBeanInfo() {
return this.info.getAdditionalBeanInfo();
}
public Image getIcon(int kind) {
return this.info.getIcon(kind);
}
}
}
|