java.beans.BeanInfo#getBeanDescriptor ( )源码实例Demo

下面列出了java.beans.BeanInfo#getBeanDescriptor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: IntrospectorTest.java
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());
        }
    }
}
 
源代码2 项目: j2objc   文件: IntrospectorTest.java
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());
        }
    }
}
 
源代码3 项目: j2objc   文件: IntrospectorTest.java
public void testSetBeanInfoSearchPath_SameClassesInDifferentPackage()
        throws IntrospectionException {
    // set the search path in the correct sequence
    Introspector
            .setBeanInfoSearchPath(new String[] {
                    "org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.info",
                    "org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject2.info", });

    BeanInfo beanInfo = Introspector
            .getBeanInfo(org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.MockHomonymySubject.class);
    BeanDescriptor beanDesc = beanInfo.getBeanDescriptor();

    assertEquals(beanDesc.getName(), "mocksubject1");
    assertEquals(
            beanDesc.getBeanClass(),
            org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.MockHomonymySubject.class);

    // set the search path in the reverse sequence
    Introspector
            .setBeanInfoSearchPath(new String[] {
                    "org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject2.info",
                    "org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.info", });

    beanInfo = Introspector
            .getBeanInfo(org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.MockHomonymySubject.class);
    beanDesc = beanInfo.getBeanDescriptor();

    assertEquals(beanDesc.getName(), "mocksubject1");
    assertEquals(
            beanDesc.getBeanClass(),
            org.apache.harmony.beans.tests.support.mock.homonymy.mocksubject1.MockHomonymySubject.class);

}
 
源代码4 项目: j2objc   文件: IntrospectorTest.java
/**
 * 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);
    }
}
 
源代码5 项目: netbeans   文件: BreakpointCustomizeAction.java
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;
}
 
源代码6 项目: openjdk-jdk9   文件: TestSwingContainer.java
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);
}
 
源代码7 项目: j2objc   文件: IntrospectorTest.java
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());
}
 
源代码8 项目: dragonwell8_jdk   文件: BeanInfoFinder.java
@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;
}
 
源代码9 项目: jdk8u-dev-jdk   文件: BeanInfoFinder.java
@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;
}
 
源代码10 项目: jdk8u60   文件: BeanInfoFinder.java
@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;
}
 
源代码11 项目: common-utils   文件: BeanInfoCache.java
public BeanDescriptor getBeanDescriptor(Class<?> beanClass) {
    BeanInfo beanInfo = getBeanInfo(beanClass);

    return beanInfo.getBeanDescriptor();
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: BeanInfoFinder.java
@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;
}
 
源代码13 项目: Bytecoder   文件: BeanInfoFinder.java
@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;
}
 
源代码14 项目: openjdk-jdk9   文件: BeanInfoFinder.java
@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;
}
 
源代码15 项目: openjdk-jdk9   文件: TestBeanInfoPriority.java
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);
            }
        }
    }
 
源代码16 项目: jdk8u-jdk   文件: BeanInfoFinder.java
@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;
}
 
源代码17 项目: hottub   文件: BeanInfoFinder.java
@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;
}
 
源代码18 项目: openjdk-8-source   文件: BeanInfoFinder.java
@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;
}
 
源代码19 项目: jdk8u-jdk   文件: BeanInfoFinder.java
@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;
}
 
源代码20 项目: jdk8u_jdk   文件: BeanInfoFinder.java
@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;
}