java.beans.BeanDescriptor Java Examples

The following examples show how to use java.beans.BeanDescriptor. 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: BeanDescriptorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testBeanDescriptorClassClass_CustomizerClassNull() {
    String beanName = "BeanDescriptorTest.bean";
    MockJavaBean bean = new MockJavaBean(beanName);
    Class<? extends MockJavaBean> beanClass = bean.getClass();
    Class<?> cusClass = null;
    BeanDescriptor bd = new BeanDescriptor(beanClass, cusClass);

    assertSame(beanClass, bd.getBeanClass());
    assertNull(bd.getCustomizerClass());

    String displayName = beanClass.getName().substring(
            beanClass.getName().lastIndexOf('.') + 1);
    assertEquals(displayName, bd.getDisplayName());
    assertEquals(displayName, bd.getName());
    assertEquals(displayName, bd.getShortDescription());

    assertNotNull(bd.attributeNames());
    assertFalse(bd.isExpert());
    assertFalse(bd.isHidden());
    assertFalse(bd.isPreferred());
}
 
Example #2
Source File: ModelProperty.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String findDisplayNameFor(Object o) {
    try {
        if (o == null) {
            return null;
        }

        if (o instanceof Node.Property) {
            return ((Node.Property) o).getDisplayName();
        }

        BeanInfo bi = Introspector.getBeanInfo(o.getClass());

        if (bi != null) {
            BeanDescriptor bd = bi.getBeanDescriptor();

            if (bd != null) {
                return bd.getDisplayName();
            }
        }
    } catch (Exception e) {
        //okay, we did our best
    }

    return null;
}
 
Example #3
Source File: BeanDescriptorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testBeanDescriptorClass() {
    String beanName = "BeanDescriptorTest.bean";
    MockJavaBean bean = new MockJavaBean(beanName);
    Class<? extends MockJavaBean> beanClass = bean.getClass();
    BeanDescriptor bd = new BeanDescriptor(beanClass);

    assertSame(beanClass, bd.getBeanClass());
    String displayName = beanClass.getName().substring(
            beanClass.getName().lastIndexOf('.') + 1);
    assertEquals(displayName, bd.getDisplayName());
    assertEquals(displayName, bd.getName());
    assertEquals(displayName, bd.getShortDescription());

    assertNotNull(bd.attributeNames());
    assertFalse(bd.isExpert());
    assertFalse(bd.isHidden());
    assertFalse(bd.isPreferred());
}
 
Example #4
Source File: BeanNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
* Returns name of the bean.
*/
private String getNameForBean() {
    if (nameGetter != null) {
        try {
            String name = (String) nameGetter.invoke(bean);

            return (name != null) ? name : ""; // NOI18N
        } catch (Exception ex) {
            NodeOp.warning(ex);
        }
    }

    BeanDescriptor descriptor = beanInfo.getBeanDescriptor();

    return descriptor.getDisplayName();
}
 
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: BeanUtils.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a bean descriptor for specified class.
 *
 * @param type  the class to introspect
 * @return a bean descriptor
 */
public static BeanDescriptor getBeanDescriptor(Class type) {
    try {
        return Introspector.getBeanInfo(type).getBeanDescriptor();
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
Example #7
Source File: BeanDescriptorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests java.beans.BeanDescriptor#BeanDescriptor( java.lang.Class,
 *        java.lang.Class)
 */
public void test_Ctor2_NullPointerException() {
    try {
        // Regression for HARMONY-225
        new BeanDescriptor(null, String.class);
        fail("No expected NullPointerException");
    } catch (NullPointerException e) {
    }
}
 
Example #8
Source File: BeanUtils.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a bean descriptor for specified class.
 *
 * @param type  the class to introspect
 * @return a bean descriptor
 */
public static BeanDescriptor getBeanDescriptor(Class type) {
    try {
        return Introspector.getBeanInfo(type).getBeanDescriptor();
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
Example #9
Source File: TestBeanInfoPriority.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {

    BeanDescriptor bd = new BeanDescriptor(TestClass.class, null);
    bd.setShortDescription("user-defined-description");
    bd.setValue("isContainer", true);
    bd.setValue("containerDelegate", "user-defined-delegate");

    return bd;
}
 
Example #10
Source File: BeanUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a bean descriptor for specified class.
 *
 * @param type  the class to introspect
 * @return a bean descriptor
 */
public static BeanDescriptor getBeanDescriptor(Class type) {
    try {
        return Introspector.getBeanInfo(type).getBeanDescriptor();
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
Example #11
Source File: BeanUtils.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a bean descriptor for specified class.
 *
 * @param type  the class to introspect
 * @return a bean descriptor
 */
public static BeanDescriptor getBeanDescriptor(Class type) {
    try {
        return Introspector.getBeanInfo(type).getBeanDescriptor();
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
Example #12
Source File: JiveBeanInfo.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor descriptor = new BeanDescriptor(getBeanClass());
    try {
        // Attempt to load the displayName and shortDescription explicitly.
        String displayName = bundle.getString("displayName");
        if (displayName != null) {
            descriptor.setDisplayName(displayName);
        }
        String shortDescription = bundle.getString("shortDescription");
        if (shortDescription != null) {
            descriptor.setShortDescription(shortDescription);
        }
        // Add any other properties that are specified.
        Enumeration enumeration = bundle.getKeys();
        while (enumeration.hasMoreElements()) {
            String key = (String)enumeration.nextElement();
            String value = bundle.getString(key);
            if (value != null) {
                descriptor.setValue(key, value);
            }
        }
    }
    catch (Exception e) {
        // Ignore any exceptions. We may get some if we try to load a
        // a property that doesn't appear in the resource bundle.
    }
    return descriptor;
}
 
Example #13
Source File: SerialDataNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Sheet.Set createPropertiesSet(BeanNode.Descriptor descr, BeanDescriptor bd) {
    Sheet.Set props;
    props = Sheet.createPropertiesSet();
    if (descr.property != null) {
        convertProps (props, descr.property, this);
    }
    if (bd != null) {
        // #29550: help from the beaninfo on property tabs
        Object helpID = bd.getValue("propertiesHelpID"); // NOI18N
        if (helpID != null && helpID instanceof String) {
            props.setValue("helpID", helpID); // NOI18N
        }
    }
    return props;
}
 
Example #14
Source File: MicrosoftEdgeBrowserBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
   public BeanDescriptor getBeanDescriptor() {
       BeanDescriptor descr = new BeanDescriptor(MicrosoftEdgeBrowser.class);
       descr.setDisplayName(NbBundle.getMessage(MicrosoftEdgeBrowserBeanInfo.class, "CTL_MicrosoftEdgeBrowserName")); // NOI18N
       descr.setShortDescription(NbBundle.getMessage(MicrosoftEdgeBrowserBeanInfo.class, "HINT_MicrosoftEdgeBrowserName")); // NOI18N
       descr.setValue ("helpID", "org.netbeans.modules.extbrowser.ExtWebBrowser");  // NOI18N
return descr;
   }
 
Example #15
Source File: BeanDescriptorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testBeanDescriptorClass_Null() {
    try {
        new BeanDescriptor(null);
        fail("Should throw NullPointerException.");
    } catch (NullPointerException e) {
    }
}
 
Example #16
Source File: Test6447751.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(Manual.class, AutomaticCustomizer.class);
}
 
Example #17
Source File: Test7193977.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    return this.info.getBeanDescriptor();
}
 
Example #18
Source File: Test6447751.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(Manual.class, AutomaticCustomizer.class);
}
 
Example #19
Source File: DerbyOptionsBeanInfo.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor descriptor = new BeanDescriptor(DerbyOptions.class);
    descriptor.setName(NbBundle.getMessage(DerbyOptionsBeanInfo.class, "LBL_DerbyOptions"));
    return descriptor;
}
 
Example #20
Source File: SecondBeanBeanInfo.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(SecondBean.class);
}
 
Example #21
Source File: ComponentBeanInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor bd = new BeanDescriptor(Component.class);
    // set a value to ensure that it's unique
    bd.setValue("test", Boolean.TRUE);
    return bd;
}
 
Example #22
Source File: ThirdBeanBeanInfo.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(ThirdBeanBeanInfo.class);
}
 
Example #23
Source File: FirstBeanBeanInfo.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(FirstBean.class);
}
 
Example #24
Source File: Test4498236.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    PropertyChangeEvent event = new PropertyChangeEvent("source", null, null, null);
    event.setPropagationId("id");
    test("[propertyName=null; oldValue=null; newValue=null; propagationId=id; source=source]", event);
    test("[propertyName=name; oldValue=old; newValue=new; propagationId=null; source=source]",
         new PropertyChangeEvent("source", "name", "old", "new")
    );
    test("[propertyName=array; index=5; oldValue=old; newValue=new; propagationId=null; source=source]",
         new IndexedPropertyChangeEvent("source", "array", "old", "new", 5)
    );
    FeatureDescriptor fd = new FeatureDescriptor();
    fd.setName("n");
    fd.setDisplayName("dn");
    fd.setShortDescription("sd");
    fd.setPreferred(true);
    fd.setHidden(true);
    fd.setExpert(true);
    fd.setValue("first", "value");
    test("[name=n; displayName=dn; shortDescription=sd; preferred; hidden; expert; values={first=value}]", fd);
    test("[name=String; beanClass=class java.lang.String]",
         new BeanDescriptor(String.class)
    );
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",
         new BeanDescriptor(Object.class, String.class)
    );
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",
         new BeanDescriptor(Object.class, String.class)
    );
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object)]",
         new MethodDescriptor(Object.class.getMethod("equals", Object.class))
    );
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object); parameterDescriptors={java.beans.ParameterDescriptor[name=null]}]",
         new MethodDescriptor(Object.class.getMethod("equals", Object.class), new ParameterDescriptor[] {
                 new ParameterDescriptor()
         })
    );
    Class type = KeyListener.class;
    String[] names = { "keyTyped", "keyPressed", "keyReleased" };
    Method[] methods = new Method[names.length];
    for (int i = 0; i < names.length; i++) {
        methods[i] = type.getMethod(names[i], KeyEvent.class);
    }
    test("[name=key; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.getKeyListeners(); addListenerMethod=public void Test4498236.addKeyListener(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.removeKeyListener(java.awt.event.KeyListener)]",
         new EventSetDescriptor(Test4498236.class, "key", type, names[0])
    );
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
         new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove")
    );
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
         new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove", "get")
    );
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
         new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type))
    );
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",
         new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type), Test4498236.class.getMethod("get"))
    );
    test("[name=value; propertyType=boolean; readMethod=public boolean Test4498236.isValue(); writeMethod=public void Test4498236.setValue(boolean)]",
         new PropertyDescriptor("value", Test4498236.class)
    );
    test("[name=$$$]",
         new PropertyDescriptor("$$$", Test4498236.class, null, null)
    );
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",
         new PropertyDescriptor("$$$", Test4498236.class, "getValue", null)
    );
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",
         new PropertyDescriptor("$$$", Test4498236.class, "getValue", "setValue")
    );
    test("[name=$$$]",
         new PropertyDescriptor("$$$", null, null)
    );
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",
         new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), null)
    );
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",
         new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), Test4498236.class.getMethod("setValue", boolean.class))
    );
    test("[name=index; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
         new IndexedPropertyDescriptor("index", Test4498236.class)
    );
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
         new IndexedPropertyDescriptor("$$$", Test4498236.class, "getIndex", "setIndex", "getIndex", "setIndex")
    );
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",
         new IndexedPropertyDescriptor("$$$", Test4498236.class.getMethod("getIndex"), Test4498236.class.getMethod("setIndex", new int[0].getClass()), Test4498236.class.getMethod("getIndex", int.class), Test4498236.class.getMethod("setIndex", int.class, int.class) )
    );
}
 
Example #25
Source File: ExtendedBeanInfo.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
	return this.delegate.getBeanDescriptor();
}
 
Example #26
Source File: ThirdBeanBeanInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(ThirdBeanBeanInfo.class);
}
 
Example #27
Source File: Test6447751.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(Manual.class, AutomaticCustomizer.class);
}
 
Example #28
Source File: FooBarBeanInfo.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor bd = new BeanDescriptor(FooBar.class);
    // set a value to ensure that it's unique
    bd.setValue("test", Boolean.TRUE);
    return bd;
}
 
Example #29
Source File: SecondBeanBeanInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanDescriptor getBeanDescriptor() {
    return new BeanDescriptor(SecondBean.class);
}
 
Example #30
Source File: Foo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor bd = new BeanDescriptor(Foo.class);
    // set a value to ensure that it's unique
    bd.setValue("test", Boolean.TRUE);
    return bd;
}