Obtain the bean info for a bean class. - Java Reflection

Java examples for Reflection:Java Bean

Description

Obtain the bean info for a bean class.

Demo Code


import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;

public class Main{
    public static void main(String[] argv) throws Exception{
        Object bean = "java2s.com";
        System.out.println(getBeanInfo(bean));
    }//from w  w w  . j  a v  a 2 s  . c  om
    /**
     * Obtain the bean info for a bean class.
     * 
     * @param beanClass
     *            A java bean <code>Class</code>.
     * @return A <code>BeanInfo</code>.
     */
    private static BeanInfo getBeanInfo(final Object bean) {
        try {
            return Introspector.getBeanInfo(bean.getClass());
        } catch (final IntrospectionException ix) {
            throw new BeanException(ix);
        }
    }
}

Related Tutorials