has Explicit Bean Info - Java Reflection

Java examples for Reflection:Java Bean

Description

has Explicit Bean Info

Demo Code


//package com.java2s;
import java.beans.Introspector;

public class Main {
    public static void main(String[] argv) throws Exception {
        Class clazz = String.class;
        System.out.println(hasExplicitBeanInfo(clazz));
    }/*from   w  w  w  .  j  a  v a 2  s.  com*/

    public static boolean hasExplicitBeanInfo(Class clazz) {
        String className = clazz.getName();
        int indx = className.lastIndexOf('.');
        className = className.substring(indx + 1);

        String[] paths = Introspector.getBeanInfoSearchPath();
        for (String path : paths) {
            String s = path + '.' + className + "BeanInfo"; // NOI18N
            try {
                // test if such class exists
                Class.forName(s);
                return true;
            } catch (ClassNotFoundException ex) {
                // OK, this is normal.
            }
        }
        return false;
    }
}

Related Tutorials