use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test4168475 method main.
public static void main(String[] args) throws IntrospectionException {
Introspector.setBeanInfoSearchPath(PATH);
BeanInfo info = Introspector.getBeanInfo(Component.class);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
if (pds.length != 1) {
throw new Error("wrong number of properties");
}
if (!pds[0].getName().equals("name")) {
throw new Error("unexpected property name");
}
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test4520754 method test4168475.
/**
* This is a regression test to ensure that 4168475 does not regress.
*/
private static void test4168475(Class type) {
String[] newPath = { "infos" };
String[] oldPath = Introspector.getBeanInfoSearchPath();
Introspector.setBeanInfoSearchPath(newPath);
BeanInfo info = getBeanInfo(Boolean.TRUE, type);
Introspector.setBeanInfoSearchPath(oldPath);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
if (pds.length != 1) {
throw new Error("could not find custom BeanInfo for " + type);
}
Introspector.flushCaches();
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test4683761 method main.
public static void main(String[] args) throws Exception {
System.setSecurityManager(new SecurityManager());
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
Map.Entry<String, String> entry = map.entrySet().iterator().next();
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(entry.getClass())) {
System.out.println(pd.getName() + " = " + pd.getReadMethod().invoke(entry));
}
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test7172865 method main.
public static void main(String[] args) throws Exception {
int errors = 0;
MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));
errors += test(PropertyDescriptor.class, "good", true);
PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");
PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()));
errors += test(PropertyDescriptor.class, "bad", false);
PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);
PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()));
errors += test(IndexedPropertyDescriptor.class, "good", true);
IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");
IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()), Test7172865.class.getMethod("getGood", Integer.TYPE), Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));
errors += test(IndexedPropertyDescriptor.class, "bad", false);
IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);
IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()), Test7172865.class.getMethod("getBad", Integer.TYPE), Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));
for (int i = 1; i <= 2; i++) {
System.out.println("STEP: " + i);
errors += test("md", null != md.getMethod());
errors += test("pdGoodString", pdGoodString, true, true);
errors += test("pdGoodMethod", pdGoodMethod, true, true);
errors += test("pdBadString", pdBadString, true, false);
errors += test("pdBadMethod", pdBadMethod, true, true);
errors += test("ipdGoodString", ipdGoodString, true, true, true, true);
errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);
errors += test("ipdBadString", ipdBadString, true, false, true, false);
errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
} catch (OutOfMemoryError error) {
System.gc();
}
}
if (errors > 0) {
throw new Error("found " + errors + " errors");
}
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test4508780 method run.
public void run() {
for (String name : this.names) {
Object bean;
try {
bean = this.loader.loadClass(name).newInstance();
} catch (Exception exception) {
throw new Error("could not instantiate bean: " + name, exception);
}
if (this.loader != bean.getClass().getClassLoader()) {
throw new Error("bean class loader is not equal to default one");
}
PropertyDescriptor[] pds = getPropertyDescriptors(bean);
for (PropertyDescriptor pd : pds) {
Class type = pd.getPropertyType();
Method setter = pd.getWriteMethod();
Method getter = pd.getReadMethod();
if (type.equals(String.class)) {
executeMethod(setter, bean, "Foo");
} else if (type.equals(int.class)) {
executeMethod(setter, bean, Integer.valueOf(1));
}
executeMethod(getter, bean);
}
}
}
Aggregations