Example usage for org.apache.commons.beanutils PropertyUtils setIndexedProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils setIndexedProperty

Introduction

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

Prototype

public static void setIndexedProperty(Object bean, String name, int index, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Sets the value of the specified indexed property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:com.khubla.cbean.serializer.impl.json.JSONArrayFieldSerializer.java

@Override
public void deserialize(Object o, Field field, String value) throws SerializerException {
    try {/* w  w w  .j  a  v  a2s  .  c o  m*/
        final JSONArray jsonArray = new JSONArray(value);
        final Object od = Array.newInstance(field.getType().getComponentType(), jsonArray.length());
        PropertyUtils.setProperty(o, field.getName(), od);
        final Class<?> componentType = field.getType().getComponentType();
        if (componentType.isPrimitive()) {
            for (int i = 0; i < jsonArray.length(); i++) {
                final String v = jsonArray.getString(i);
                PropertyUtils.setIndexedProperty(o, field.getName(), i,
                        ConvertUtils.convert(v, field.getType().getComponentType()));
            }
        } else {
            final CBean<Object> cBean = CBeanServer.getInstance().getCBean(componentType);
            for (int i = 0; i < jsonArray.length(); i++) {
                final Object co = cBean.load(new CBeanKey(jsonArray.getString(i)));
                PropertyUtils.setIndexedProperty(o, field.getName(), i,
                        ConvertUtils.convert(co, field.getType().getComponentType()));
            }
        }
    } catch (final Exception e) {
        throw new SerializerException(e);
    }
}

From source file:org.apache.shiro.config.ReflectionBuilder.java

private void setIndexedProperty(Object object, String propertyPath, int index, Object value) {
    try {//from   ww  w  . j  a  v  a2s .co  m
        PropertyUtils.setIndexedProperty(object, propertyPath, index, value);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to set array property '" + propertyPath + "'", e);
    }
}

From source file:org.oddjob.framework.WrapDynaBean.java

/**
 * Set the value of an indexed property with the specified name.
 *
 * @param name Name of the property whose value is to be set
 * @param index Index of the property to be set
 * @param value Value to which this property is to be set
 *
 * @exception ConversionException if the specified value cannot be
 *  converted to the type required for this property
 * @exception IllegalArgumentException if there is no property
 *  of the specified name//ww  w  .  j  ava  2 s .  c om
 * @exception IllegalArgumentException if the specified property
 *  exists, but is not indexed
 * @exception IndexOutOfBoundsException if the specified index
 *  is outside the range of the underlying property
 */
public void set(String name, int index, Object value) {

    try {
        PropertyUtils.setIndexedProperty(instance, name, index, value);
    } catch (IndexOutOfBoundsException e) {
        throw e;
    } catch (Throwable t) {
        throw new IllegalArgumentException("Property '" + name + "' has no indexed write method");
    }

}