Java Code Examples for java.beans.BeanInfo#getBeanDescriptor()

The following examples show how to use java.beans.BeanInfo#getBeanDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testBeanInfo_1() throws IntrospectionException {
    Class<FakeFox011> beanClass = FakeFox011.class;
    BeanInfo info = Introspector.getBeanInfo(beanClass);
    assertNull(info.getAdditionalBeanInfo());
    BeanDescriptor beanDesc = info.getBeanDescriptor();
    assertEquals("FakeFox011", beanDesc.getName());
    assertEquals(0, info.getEventSetDescriptors().length);
    assertEquals(-1, info.getDefaultEventIndex());
    assertEquals(0, info.getDefaultPropertyIndex());

    MethodDescriptor[] methodDesc = info.getMethodDescriptors();

    assertEquals(4, methodDesc.length);

    PropertyDescriptor[] propertyDesc = info.getPropertyDescriptors();
    assertEquals(2, propertyDesc.length);
    for (PropertyDescriptor element : propertyDesc) {
        if (element.getName().equals("class")) {
            assertNull(element.getWriteMethod());
            assertNotNull(element.getReadMethod());
        }
    }
}
 
Example 2
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testBeanInfo_2() throws IntrospectionException {
    Class<FakeFox02> beanClass = FakeFox02.class;
    BeanInfo info = Introspector.getBeanInfo(beanClass);
    assertNull(info.getAdditionalBeanInfo());
    BeanDescriptor beanDesc = info.getBeanDescriptor();
    assertEquals("FakeFox02", beanDesc.getName());
    assertEquals(0, info.getEventSetDescriptors().length);
    assertEquals(-1, info.getDefaultEventIndex());
    assertEquals(-1, info.getDefaultPropertyIndex());

    PropertyDescriptor[] propertyDesc = info.getPropertyDescriptors();
    for (PropertyDescriptor element : propertyDesc) {
        if (element.getName().equals("fox02")) {
            assertEquals("fox02.beaninfo", element.getDisplayName());
        }
    }
}
 
Example 3
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * The test checks the getBeanDescriptor method
 */
public void testBeanDescriptor() throws Exception {
    String[] oldBeanInfoSearchPath = Introspector.getBeanInfoSearchPath();
    try {
        Introspector
                .setBeanInfoSearchPath(new String[] { "java.beans.infos" });
        BeanInfo info = Introspector.getBeanInfo(SampleBean.class);
        assertNotNull(info);
        BeanDescriptor descriptor = info.getBeanDescriptor();
        assertNotNull(descriptor);
        assertEquals(SampleBean.class, descriptor.getBeanClass());
    } finally {
        Introspector.setBeanInfoSearchPath(oldBeanInfoSearchPath);
    }
}
 
Example 4
Source File: BreakpointCustomizeAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Class getCustomizerClass(Breakpoint b) {
    BeanInfo bi = findBeanInfo(b.getClass());
    if (bi == null) {
        try {
            bi = Introspector.getBeanInfo(b.getClass());
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
            return null;
        }
    }
    BeanDescriptor bd = bi.getBeanDescriptor();
    if (bd == null) return null;
    Class cc = bd.getCustomizerClass();
    return cc;
}
 
Example 5
Source File: IntrospectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testGetBeanInfoSearchPath_Default()
        throws IntrospectionException, ClassNotFoundException {
    BeanInfo info = Introspector.getBeanInfo(MockFooButton.class);
    PropertyDescriptor[] pds = info.getPropertyDescriptors();
    BeanDescriptor beanDesc;

    assertEquals(2, pds.length);
    assertEquals("class", pds[0].getName());

    beanDesc = info.getBeanDescriptor();
    assertEquals("MockFooButton", beanDesc.getName());
}
 
Example 6
Source File: TestSwingContainer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Class<?> type, Object iC, Object cD) throws Exception {
    System.out.println(type);
    BeanInfo info = Introspector.getBeanInfo(type);
    BeanDescriptor bd = info.getBeanDescriptor();
    test(bd, "isContainer", iC);
    test(bd, "containerDelegate", cD);
}
 
Example 7
Source File: BeanInfoFinder.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 8
Source File: BeanInfoFinder.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 9
Source File: BeanInfoFinder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 10
Source File: BeanInfoFinder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 11
Source File: BeanInfoFinder.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 12
Source File: BeanInfoFinder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 13
Source File: TestBeanInfoPriority.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        BeanInfo i = Introspector.getBeanInfo(TestClass.class, Object.class);
        BeanDescriptor bd = i.getBeanDescriptor();

        checkEq("description", bd.getShortDescription(), "user-defined-description");
        checkEq("default property index", i.getDefaultPropertyIndex(), 1);
        checkEq("default event index", i.getDefaultEventIndex(), 0);

        checkEq("isContainer", i.getBeanDescriptor().getValue("isContainer"), true);
        checkEq("containerDelegate",
            i.getBeanDescriptor().getValue("containerDelegate"), "user-defined-delegate");
        System.out.println("");

        PropertyDescriptor[] pds = i.getPropertyDescriptors();
        for (PropertyDescriptor pd: pds) {
            String name = pd.getName();
            switch (name) {
                case "value":
                    checkEq("\"value\" isBound",       pd.isBound(),       true);
                    checkEq("\"value\" isConstrained", pd.isConstrained(), true);
                    checkEq("\"value\" isExpert",      pd.isExpert(),      true);
                    checkEq("\"value\" isHidden",      pd.isHidden(),      true);
                    checkEq("\"value\" isPreferred",   pd.isPreferred(),   true);
                    checkEq("\"value\" required",      pd.getValue("required"),     true);
                    checkEq("\"value\" visualUpdate",  pd.getValue("visualUpdate"), true);

                    checkEq("\"value\" description",   pd.getShortDescription(), "user-defined-value");

                    checkEnumEq(pd.getName(), pd.getValue("enumerationValues"),
                        new Object[]{
                        "EAST", 3, "javax.swing.SwingConstants.EAST",
                        "WEST", 7, "javax.swing.SwingConstants.WEST"});
                    System.out.println("");
                    break;
                case "other":
                    checkEq("\"other\" isBound",       pd.isBound(),       false);
                    checkEq("\"other\" isConstrained", pd.isConstrained(), false);
                    checkEq("\"other\" isExpert",      pd.isExpert(),      false);
                    checkEq("\"other\" isHidden",      pd.isHidden(),      false);
                    checkEq("\"other\" isPreferred",   pd.isPreferred(),   false);
                    checkEq("\"other\" required",      pd.getValue("required"),     false);
                    checkEq("\"other\" visualUpdate",  pd.getValue("visualUpdate"), false);

                    checkEq("\"other\" description",   pd.getShortDescription(), "user-defined-other");

                    checkEnumEq(pd.getName(), pd.getValue("enumerationValues"),
                        new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
                    System.out.println("");
                    break;
                default:
                    throw new Exception("invalid property descriptor: " + name);
            }
        }
    }
 
Example 14
Source File: BeanInfoFinder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 15
Source File: BeanInfoFinder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 16
Source File: BeanInfoFinder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 17
Source File: BeanInfoCache.java    From common-utils with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor(Class<?> beanClass) {
    BeanInfo beanInfo = getBeanInfo(beanClass);

    return beanInfo.getBeanDescriptor();
}
 
Example 18
Source File: BeanInfoFinder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 19
Source File: BeanInfoFinder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}