Java 类org.apache.commons.beanutils.MappedPropertyDescriptor 实例源码

项目:NotifyTools    文件:LocaleBeanUtilsBean.java   
/**
 * Calculate the property type.
 *
 * @param target The bean
 * @param name The property name
 * @param propName The Simple name of target property
 * @return The property's type
 *
 * @throws IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @throws InvocationTargetException if the property accessor method
 *  throws an exception
 */
protected Class<?> definePropertyType(final Object target, final String name, final String propName)
        throws IllegalAccessException, InvocationTargetException {

    Class<?> type = null;               // Java type of target property

    if (target instanceof DynaBean) {
        final DynaClass dynaClass = ((DynaBean) target).getDynaClass();
        final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
        if (dynaProperty == null) {
            return null; // Skip this property setter
        }
        type = dynaProperty.getType();
    }
    else {
        PropertyDescriptor descriptor = null;
        try {
            descriptor =
                    getPropertyUtils().getPropertyDescriptor(target, name);
            if (descriptor == null) {
                return null; // Skip this property setter
            }
        }
        catch (final NoSuchMethodException e) {
            return null; // Skip this property setter
        }
        if (descriptor instanceof MappedPropertyDescriptor) {
            type = ((MappedPropertyDescriptor) descriptor).
                    getMappedPropertyType();
        }
        else if (descriptor instanceof IndexedPropertyDescriptor) {
            type = ((IndexedPropertyDescriptor) descriptor).
                    getIndexedPropertyType();
        }
        else {
            type = descriptor.getPropertyType();
        }
    }
    return type;
}