Example usage for org.apache.commons.beanutils PropertyUtilsBean setNestedProperty

List of usage examples for org.apache.commons.beanutils PropertyUtilsBean setNestedProperty

Introduction

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

Prototype

public void setNestedProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

Usage

From source file:org.opencms.workplace.CmsWidgetDialogParameter.java

/**
 * "Commits" (writes) the value of this widget back to the underlying base object.<p> 
 * /*from   w  w w .  j a  va2s . c o  m*/
 * @param dialog the widget dialog where the parameter is used on
 * 
 * @throws CmsException in case the String value of the widget is invalid for the base Object
 */
@SuppressWarnings("unchecked")
public void commitValue(CmsWidgetDialog dialog) throws CmsException {

    if (m_baseCollection == null) {
        PropertyUtilsBean bean = new PropertyUtilsBean();
        ConvertUtilsBean converter = new ConvertUtilsBean();
        Object value = null;
        try {
            Class<?> type = bean.getPropertyType(m_baseObject, m_baseObjectProperty);
            value = converter.convert(m_value, type);
            bean.setNestedProperty(m_baseObject, m_baseObjectProperty, value);
            setError(null);
        } catch (InvocationTargetException e) {
            setError(e.getTargetException());
            throw new CmsWidgetException(Messages.get().container(Messages.ERR_PROPERTY_WRITE_3, value,
                    dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()),
                    m_baseObject.getClass().getName()), e.getTargetException(), this);
        } catch (Exception e) {
            setError(e);
            throw new CmsWidgetException(Messages.get().container(Messages.ERR_PROPERTY_WRITE_3, value,
                    dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()),
                    m_baseObject.getClass().getName()), e, this);
        }
    } else if (m_baseCollection instanceof SortedMap) {
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) {
            int pos = m_value.indexOf('=');
            if ((pos > 0) && (pos < (m_value.length() - 1))) {
                String key = m_value.substring(0, pos);
                String value = m_value.substring(pos + 1);
                @SuppressWarnings("rawtypes")
                SortedMap map = (SortedMap) m_baseCollection;
                if (map.containsKey(key)) {
                    Object val = map.get(key);
                    CmsWidgetException error = new CmsWidgetException(
                            Messages.get().container(Messages.ERR_MAP_DUPLICATE_KEY_3,
                                    dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()), key, val),
                            this);
                    setError(error);
                    throw error;
                }
                map.put(key, value);
            } else {
                CmsWidgetException error = new CmsWidgetException(
                        Messages.get().container(Messages.ERR_MAP_PARAMETER_FORM_1,
                                dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey())),
                        this);
                setError(error);
                throw error;
            }
        }
    } else if (m_baseCollection instanceof List) {
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) {
            @SuppressWarnings("rawtypes")
            List list = (List) m_baseCollection;
            list.add(m_value);
        }
    }
}