Example usage for java.beans Introspector IGNORE_ALL_BEANINFO

List of usage examples for java.beans Introspector IGNORE_ALL_BEANINFO

Introduction

In this page you can find the example usage for java.beans Introspector IGNORE_ALL_BEANINFO.

Prototype

int IGNORE_ALL_BEANINFO

To view the source code for java.beans Introspector IGNORE_ALL_BEANINFO.

Click Source Link

Document

Flag to indicate to ignore all beaninfo.

Usage

From source file:com.springframework.beans.CachedIntrospectionResults.java

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 *//* w  w w  .  j  a v a 2 s  . co m*/
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
    try {
        if (logger.isTraceEnabled()) {
            logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
        }

        BeanInfo beanInfo = null;
        for (BeanInfoFactory beanInfoFactory : beanInfoFactories) {
            beanInfo = beanInfoFactory.getBeanInfo(beanClass);
            if (beanInfo != null) {
                break;
            }
        }
        if (beanInfo == null) {
            // If none of the factories supported the class, fall back to the default
            beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses
                    ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO)
                    : Introspector.getBeanInfo(beanClass));
        }
        this.beanInfo = beanInfo;

        if (logger.isTraceEnabled()) {
            logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
        }
        this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            if (Class.class.equals(beanClass)
                    && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
                // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
                continue;
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Found bean property '" + pd.getName() + "'"
                        + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]"
                                : "")
                        + (pd.getPropertyEditorClass() != null
                                ? "; editor [" + pd.getPropertyEditorClass().getName() + "]"
                                : ""));
            }
            pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
            this.propertyDescriptorCache.put(pd.getName(), pd);
        }

        this.typeDescriptorCache = new ConcurrentReferenceHashMap<PropertyDescriptor, TypeDescriptor>();
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
    } finally {

    }
}

From source file:net.yasion.common.core.bean.wrapper.CachedIntrospectionResults.java

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * //from  ww  w.  j ava2  s . c  o  m
 * @param beanClass
 *            the bean class to analyze
 * @throws BeansException
 *             in case of introspection failure
 */
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
    try {
        if (logger.isTraceEnabled()) {
            logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]");
        }

        BeanInfo beanInfo = null;
        for (BeanInfoFactory beanInfoFactory : beanInfoFactories) {
            beanInfo = beanInfoFactory.getBeanInfo(beanClass);
            if (beanInfo != null) {
                break;
            }
        }
        if (beanInfo == null) {
            // If none of the factories supported the class, fall back to the default
            beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses
                    ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO)
                    : Introspector.getBeanInfo(beanClass));
        }
        this.beanInfo = beanInfo;

        if (logger.isTraceEnabled()) {
            logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]");
        }
        this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            if (Class.class.equals(beanClass)
                    && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
                // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
                continue;
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Found bean property '" + pd.getName() + "'"
                        + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]"
                                : "")
                        + (pd.getPropertyEditorClass() != null
                                ? "; editor [" + pd.getPropertyEditorClass().getName() + "]"
                                : ""));
            }
            pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
            this.propertyDescriptorCache.put(pd.getName(), pd);
        }

        this.typeDescriptorCache = new ConcurrentReferenceHashMap<PropertyDescriptor, TypeDescriptor>();
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
    }
}

From source file:no.sesat.search.datamodel.generic.MapDataObjectBeanInfo.java

/**
 *
 * @param name//from  w w  w .  jav a2 s.  com
 * @param cls
 * @return
 */
public static PropertyDescriptor[] addSingleMappedPropertyDescriptor(final String name, final Class<?> cls) {

    try {
        final PropertyDescriptor[] existing = Introspector.getBeanInfo(cls, Introspector.IGNORE_ALL_BEANINFO)
                .getPropertyDescriptors();
        // remove this introspection from the cache to avoid reuse of the IGNORE_ALL_BEANINFO result
        Introspector.flushFromCaches(cls);

        final PropertyDescriptor[] result = new PropertyDescriptor[existing.length + 2];
        System.arraycopy(existing, 0, result, 0, existing.length);
        result[existing.length] = new MappedPropertyDescriptor(name, cls);
        if (!System.getProperty("java.version").startsWith("1.6")) {
            fixForJavaBug4984912(cls, (MappedPropertyDescriptor) result[existing.length]);
        }

        final String captialised = Character.toUpperCase(name.charAt(0)) + name.substring(1);
        try {
            // try plural with "s" first, then fall back onto "es"
            result[existing.length + 1] = new PropertyDescriptor(name + 's', cls, "get" + captialised + 's',
                    null);
        } catch (IntrospectionException ie) {
            // who on earth designed the english language!?? :@
            result[existing.length + 1] = new PropertyDescriptor(name + "es", cls, "get" + captialised + 's',
                    null);
        }
        return result;

    } catch (IntrospectionException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new IllegalStateException('[' + cls.getSimpleName() + ']' + ex.getMessage(), ex);
    }
}

From source file:org.grails.beans.support.CachedIntrospectionResults.java

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * @param beanClass the bean class to analyze
 * @throws BeansException in case of introspection failure
 *///w ww .  ja v a  2  s .co  m
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
    try {
        BeanInfo beanInfo = new ExtendedBeanInfo(Introspector.getBeanInfo(beanClass));
        if (beanInfo == null) {
            // If none of the factories supported the class, fall back to the default
            beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses
                    ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO)
                    : Introspector.getBeanInfo(beanClass));
        }
        this.beanInfo = beanInfo;

        this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>();

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            if (Class.class.equals(beanClass)
                    && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
                // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
                continue;
            }
            pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
            this.propertyDescriptorCache.put(pd.getName(), pd);
        }

        this.typeDescriptorCache = new ConcurrentReferenceHashMap<PropertyDescriptor, TypeDescriptor>();
    } catch (IntrospectionException ex) {
        throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex);
    }
}

From source file:org.springframework.beans.CachedIntrospectionResults.java

/**
 * Retrieve a {@link BeanInfo} descriptor for the given target class.
 * @param beanClass the target class to introspect
 * @param ignoreBeaninfoClasses whether to apply {@link Introspector#IGNORE_ALL_BEANINFO} mode
 * @return the resulting {@code BeanInfo} descriptor (never {@code null})
 * @throws IntrospectionException from the underlying {@link Introspector}
 *///  ww w.j a  v  a2  s  . c  o m
private static BeanInfo getBeanInfo(Class<?> beanClass, boolean ignoreBeaninfoClasses)
        throws IntrospectionException {

    for (BeanInfoFactory beanInfoFactory : beanInfoFactories) {
        BeanInfo beanInfo = beanInfoFactory.getBeanInfo(beanClass);
        if (beanInfo != null) {
            return beanInfo;
        }
    }
    return (ignoreBeaninfoClasses ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO)
            : Introspector.getBeanInfo(beanClass));
}