Example usage for org.springframework.util ConcurrentReferenceHashMap ConcurrentReferenceHashMap

List of usage examples for org.springframework.util ConcurrentReferenceHashMap ConcurrentReferenceHashMap

Introduction

In this page you can find the example usage for org.springframework.util ConcurrentReferenceHashMap ConcurrentReferenceHashMap.

Prototype

public ConcurrentReferenceHashMap() 

Source Link

Document

Create a new ConcurrentReferenceHashMap instance.

Usage

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

/**
 * Create a new CachedIntrospectionResults instance for the given class.
 * //from  w w  w  .  jav  a  2s. 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: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
 *///from w  w  w.  ja v  a 2 s  .  com
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

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

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

        // This call is slow so we do it once.
        PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            if (Class.class == 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);
        }

        // Explicitly check implemented interfaces for setter/getter methods as well,
        // in particular for Java 8 default methods...
        Class<?> clazz = beanClass;
        while (clazz != null && clazz != Object.class) {
            Class<?>[] ifcs = clazz.getInterfaces();
            for (Class<?> ifc : ifcs) {
                if (!ClassUtils.isJavaLanguageInterface(ifc)) {
                    BeanInfo ifcInfo = getBeanInfo(ifc, true);
                    PropertyDescriptor[] ifcPds = ifcInfo.getPropertyDescriptors();
                    for (PropertyDescriptor pd : ifcPds) {
                        if (!this.propertyDescriptorCache.containsKey(pd.getName())) {
                            pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
                            this.propertyDescriptorCache.put(pd.getName(), pd);
                        }
                    }
                }
            }
            clazz = clazz.getSuperclass();
        }

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