Search in sources :

Example 11 with PropertyDescriptor

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");
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) ComponentBeanInfo(infos.ComponentBeanInfo)

Example 12 with PropertyDescriptor

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();
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ComponentBeanInfo(infos.ComponentBeanInfo) BeanInfo(java.beans.BeanInfo)

Example 13 with PropertyDescriptor

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));
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with PropertyDescriptor

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");
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) MethodDescriptor(java.beans.MethodDescriptor)

Example 15 with PropertyDescriptor

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);
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method) IntrospectionException(java.beans.IntrospectionException)

Aggregations

PropertyDescriptor (java.beans.PropertyDescriptor)841 Method (java.lang.reflect.Method)400 BeanInfo (java.beans.BeanInfo)342 IntrospectionException (java.beans.IntrospectionException)191 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)171 SimpleBeanInfo (java.beans.SimpleBeanInfo)142 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)141 InvocationTargetException (java.lang.reflect.InvocationTargetException)109 ArrayList (java.util.ArrayList)90 HashMap (java.util.HashMap)66 Field (java.lang.reflect.Field)60 Map (java.util.Map)52 Test (org.junit.Test)39 IOException (java.io.IOException)35 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)34 List (java.util.List)33 Type (java.lang.reflect.Type)21 HashSet (java.util.HashSet)21 Set (java.util.Set)20 LinkedHashMap (java.util.LinkedHashMap)19