protected Map getBeanProperties()

in core/src/main/java/flex/messaging/io/BeanProxy.java [364:451]


    protected Map<String, BeanProperty> getBeanProperties(Object instance) {
        Class c = instance.getClass();
        Map<String, BeanProperty> props;

        // look up instance class in cache if we don't have a custom descriptor.
        if (descriptor == null) {
            if (getIncludeReadOnly()) {
                synchronized (roBeanPropertyCache) {
                    props = roBeanPropertyCache.get(c);
                }
            } else {
                synchronized (rwBeanPropertyCache) {
                    props = rwBeanPropertyCache.get(c);
                }
            }
            if (props != null)
                return props;
        }

        props = new HashMap<String, BeanProperty>();
        PropertyDescriptor[] pds = getPropertyDescriptors(c);
        if (pds == null)
            return null;

        List excludes = null;
        if (descriptor != null) {
            excludes = descriptor.getExcludesForInstance(instance);
            if (excludes == null) // For compatibility with older implementations
                excludes = descriptor.getExcludes();
        }

        // Add standard bean properties first
        for (PropertyDescriptor pd : pds) {
            String propertyName = pd.getName();
            Method readMethod = pd.getReadMethod();
            Method writeMethod = pd.getWriteMethod();

            // If there's a public read method but no writeMethod and includeReadOnly
            // flag is off, then skip the property.
            if (readMethod != null && isPublicAccessor(readMethod.getModifiers()) && !getIncludeReadOnly() && writeMethod == null)
                continue;

            // Skip excluded and ignored properties as well.
            if ((excludes != null && excludes.contains(propertyName)) || isPropertyIgnored(c, propertyName))
                continue;

            // Ensure we don't include Object getClass() property, possibly returned (incorrectly) by custom BeanInfos
            if (getIncludeReadOnly() && writeMethod == null && "class".equals(propertyName))
                continue;

            // Skip any classloader properties
            final Class<?> type = pd.getPropertyType();
            if (type != null && ClassLoader.class.isAssignableFrom(type))
                continue;

            props.put(propertyName, new BeanProperty(propertyName, pd.getPropertyType(),
                    readMethod, writeMethod, null));
        }

        // Then add public fields to list if property does not already exist
        Field[] fields = instance.getClass().getFields();
        for (Field field : fields) {
            String propertyName = field.getName();
            int modifiers = field.getModifiers();
            if (isPublicField(modifiers) && !props.containsKey(propertyName)) {
                // Skip excluded and ignored properties.
                if ((excludes != null && excludes.contains(propertyName)) || isPropertyIgnored(c, propertyName))
                    continue;

                props.put(propertyName, new BeanProperty(propertyName, field.getType(), null, null, field));
            }
        }

        // Update the cache if we don't have a custom serialization descriptor and we are caching.
        if (descriptor == null && cacheProperties) {
            if (getIncludeReadOnly()) {
                synchronized (roBeanPropertyCache) {
                    roBeanPropertyCache.put(c, props);
                }
            } else {
                synchronized (rwBeanPropertyCache) {
                    rwBeanPropertyCache.put(c, props);
                }
            }
        }

        return props;
    }