Example usage for org.apache.commons.beanutils NestedNullException NestedNullException

List of usage examples for org.apache.commons.beanutils NestedNullException NestedNullException

Introduction

In this page you can find the example usage for org.apache.commons.beanutils NestedNullException NestedNullException.

Prototype

public NestedNullException(String message) 

Source Link

Document

Constructs a NestedNullException without a detail message.

Usage

From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoPropertyUtilsBean.java

public Class getPropertyType(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }//from w w w . j a v a  2  s.  c  o m
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Resolve nested references
    while (getResolver().hasNested(name)) {
        String next = getResolver().next(name);
        Object nestedBean = getProperty(bean, next);
        if (nestedBean == null) {
            Class<?>[] paramTypes = {};
            Method method = null;
            try {
                method = bean.getClass().getMethod(
                        "get" + next.substring(0, 1).toUpperCase() + next.substring(1), (Class[]) null);
            } catch (NoSuchMethodException e) {
                method = bean.getClass().getMethod(
                        "is" + next.substring(0, 1).toUpperCase() + next.substring(1), (Class[]) null);
            }
            try {
                nestedBean = ObjectUtils.createNewObjectFromClass(method.getReturnType());
            } catch (RuntimeException e) {
                NestedNullException nne = new NestedNullException(
                        "Null property value for '" + next + "' on bean class '" + bean.getClass() + "'");
                nne.initCause(e);
                throw nne;
            }
        }
        bean = nestedBean;
        name = getResolver().remove(name);
    }

    // Remove any subscript from the final name value
    name = getResolver().getProperty(name);

    // Special handling for DynaBeans
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            return (null);
        }
        Class type = descriptor.getType();
        if (type == null) {
            return (null);
        } else if (type.isArray()) {
            return (type.getComponentType());
        } else {
            return (type);
        }
    }

    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        return (null);
    } else if (descriptor instanceof IndexedPropertyDescriptor) {
        return (((IndexedPropertyDescriptor) descriptor).getIndexedPropertyType());
    } else if (descriptor instanceof MappedPropertyDescriptor) {
        return (((MappedPropertyDescriptor) descriptor).getMappedPropertyType());
    } else {
        return (descriptor.getPropertyType());
    }

}

From source file:org.mypsycho.beans.PropertyUtilsBean.java

public Object[] resolveNested(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    validateArgs(bean, name);/*from  www .  j  av  a2  s  .  c  om*/
    if (!resolver.hasNested(name)) {
        return null;
    }

    // Resolve nested references
    while (resolver.hasNested(name)) {
        String next = resolver.next(name);
        Object nestedBean = getProperty(bean, next);
        if (nestedBean == null) {
            throw new NestedNullException(
                    "Null property value for '" + next + "' on bean class '" + bean.getClass() + "'");
        }
        bean = nestedBean;
        name = resolver.remove(name);
    }
    return new Object[] { bean, name };
}