Example usage for java.lang NoSuchMethodException NoSuchMethodException

List of usage examples for java.lang NoSuchMethodException NoSuchMethodException

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException NoSuchMethodException.

Prototype

public NoSuchMethodException(String s) 

Source Link

Document

Constructs a NoSuchMethodException with a detail message.

Usage

From source file:org.quartz.impl.StdSchedulerFactory.java

private void setBeanProps(Object obj, Properties props) throws NoSuchMethodException, IllegalAccessException,
        java.lang.reflect.InvocationTargetException, IntrospectionException, SchedulerConfigException {
    props.remove("class");

    BeanInfo bi = Introspector.getBeanInfo(obj.getClass());
    PropertyDescriptor[] propDescs = bi.getPropertyDescriptors();
    PropertiesParser pp = new PropertiesParser(props);

    java.util.Enumeration keys = props.keys();
    while (keys.hasMoreElements()) {
        String name = (String) keys.nextElement();
        String c = name.substring(0, 1).toUpperCase(Locale.US);
        String methName = "set" + c + name.substring(1);

        java.lang.reflect.Method setMeth = getSetMethod(methName, propDescs);

        try {// ww  w.j av  a2s. com
            if (setMeth == null) {
                throw new NoSuchMethodException("No setter for property '" + name + "'");
            }

            Class[] params = setMeth.getParameterTypes();
            if (params.length != 1) {
                throw new NoSuchMethodException("No 1-argument setter for property '" + name + "'");
            }
            if (params[0].equals(int.class)) {
                setMeth.invoke(obj, new Object[] { new Integer(pp.getIntProperty(name)) });
            } else if (params[0].equals(long.class)) {
                setMeth.invoke(obj, new Object[] { new Long(pp.getLongProperty(name)) });
            } else if (params[0].equals(float.class)) {
                setMeth.invoke(obj, new Object[] { new Float(pp.getFloatProperty(name)) });
            } else if (params[0].equals(double.class)) {
                setMeth.invoke(obj, new Object[] { new Double(pp.getDoubleProperty(name)) });
            } else if (params[0].equals(boolean.class)) {
                setMeth.invoke(obj, new Object[] { new Boolean(pp.getBooleanProperty(name)) });
            } else if (params[0].equals(String.class)) {
                setMeth.invoke(obj, new Object[] { pp.getStringProperty(name) });
            } else {
                throw new NoSuchMethodException("No primitive-type setter for property '" + name + "'");
            }
        } catch (NumberFormatException nfe) {
            throw new SchedulerConfigException(
                    "Could not parse property '" + name + "' into correct data type: " + nfe.toString());
        }
    }
}

From source file:org.enerj.apache.commons.beanutils.PropertyUtilsBean.java

/**
 * Set the value of the specified indexed property of the specified
 * bean, with no type conversions.  In addition to supporting the JavaBeans
 * specification, this method has been extended to support
 * <code>List</code> objects as well.
 *
 * @param bean Bean whose property is to be set
 * @param name Simple property name of the property value to be set
 * @param index Index of the property value to be set
 * @param value Value to which the indexed property element is to be set
 *
 * @exception ArrayIndexOutOfBoundsException if the specified index
 *  is outside the valid range for the underlying array
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception/*from   w w w . j  av  a  2 s .  c om*/
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public void setIndexedProperty(Object bean, String name, int index, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException("Unknown property '" + name + "'");
        }
        ((DynaBean) bean).set(name, index, value);
        return;
    }

    // Retrieve the property descriptor for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException("Unknown property '" + name + "'");
    }

    // Call the indexed setter method if there is one
    if (descriptor instanceof IndexedPropertyDescriptor) {
        Method writeMethod = ((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod();
        if (writeMethod != null) {
            Object subscript[] = new Object[2];
            subscript[0] = new Integer(index);
            subscript[1] = value;
            try {
                if (log.isTraceEnabled()) {
                    String valueClassName = value == null ? "<null>" : value.getClass().getName();
                    log.trace("setSimpleProperty: Invoking method " + writeMethod + " with index=" + index
                            + ", value=" + value + " (class " + valueClassName + ")");
                }
                invokeMethod(writeMethod, bean, subscript);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof ArrayIndexOutOfBoundsException) {
                    throw (ArrayIndexOutOfBoundsException) e.getTargetException();
                } else {
                    throw e;
                }
            }
            return;
        }
    }

    // Otherwise, the underlying property must be an array or a list
    Method readMethod = descriptor.getReadMethod();
    if (readMethod == null) {
        throw new NoSuchMethodException("Property '" + name + "' has no getter method");
    }

    // Call the property getter to get the array or list
    Object array = invokeMethod(readMethod, bean, new Object[0]);
    if (!array.getClass().isArray()) {
        if (array instanceof List) {
            // Modify the specified value in the List
            ((List) array).set(index, value);
        } else {
            throw new IllegalArgumentException("Property '" + name + "' is not indexed");
        }
    } else {
        // Modify the specified value in the array
        Array.set(array, index, value);
    }

}

From source file:javadz.beanutils.PropertyUtilsBean.java

/**
 * Return the value of the specified simple property of the specified
 * bean, with no type conversions.// w  w  w .j a  v a  2  s. com
 *
 * @param bean Bean whose property is to be extracted
 * @param name Name of the property to be extracted
 * @return The property value
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception IllegalArgumentException if the property name
 *  is nested or indexed
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public Object getSimpleProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Validate the syntax of the property name
    if (resolver.hasNested(name)) {
        throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isIndexed(name)) {
        throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isMapped(name)) {
        throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on dynaclass '" + ((DynaBean) bean).getDynaClass() + "'");
        }
        return (((DynaBean) bean).get(name));
    }

    // Retrieve the property getter method for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException("Unknown property '" + name + "' on class '" + bean.getClass() + "'");
    }
    Method readMethod = getReadMethod(bean.getClass(), descriptor);
    if (readMethod == null) {
        throw new NoSuchMethodException(
                "Property '" + name + "' has no getter method in class '" + bean.getClass() + "'");
    }

    // Call the property getter and return the value
    Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
    return (value);

}

From source file:org.evergreen.web.utils.beanutils.PropertyUtilsBean.java

/**
 * Return the value of the specified simple property of the specified
 * bean, with no type conversions./*w  w  w  . j a v a  2 s  . co  m*/
 *
 * @param bean Bean whose property is to be extracted
 * @param name Name of the property to be extracted
 * @return The property value
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception IllegalArgumentException if the property name
 *  is nested or indexed
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public Object getSimpleProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Validate the syntax of the property name
    if (resolver.hasNested(name)) {
        throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isIndexed(name)) {
        throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isMapped(name)) {
        throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on dynaclass '" + ((DynaBean) bean).getDynaClass() + "'");
        }
        return (((DynaBean) bean).get(name));
    }

    // Retrieve the property getter method for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException("Unknown property '" + name + "' on class '" + bean.getClass() + "'");
    }
    Method readMethod = getReadMethod(bean.getClass(), descriptor);
    if (readMethod == null) {
        throw new NoSuchMethodException(
                "Property '" + name + "' has no getter method in class '" + bean.getClass() + "'");
    }

    // Call the property getter and return the value
    Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
    //??,?,?
    if (value == null) {
        try {
            //getternullsetter
            Object instance = readMethod.getReturnType().newInstance();
            Method writeMethod = getWriteMethod(bean.getClass(), descriptor);
            if (writeMethod == null) {
                throw new NoSuchMethodException(
                        "Property '" + name + "' has no setter method in class '" + bean.getClass() + "'");
            }
            invokeMethod(writeMethod, bean, new Object[] { instance });
            value = instance;
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
    return (value);

}

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

public Object _getSimpleProperty(final Object bean, final String name) throws Exception {

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

    // Validate the syntax of the property name
    if (resolver.hasNested(name)) {
        throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isIndexed(name)) {
        throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isMapped(name)) {
        throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    }

    if (name.startsWith("@")) {
        final String fieldName = trimAnnotations(name);
        final Field f = FieldUtils.findField(bean.getClass(), fieldName);
        if (null == f) {
            throw new NoSuchFieldException("field `" + fieldName + "` not found");
        }
        f.setAccessible(true);
        return f.get(bean);
    } else {
        // Retrieve the property getter method for the specified property
        final PropertyDescriptor descriptor = getPropertyDescriptor(bean, trimAnnotations(name));
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on class '" + bean.getClass() + "'");
        }
        final Method readMethod = getReadMethod(bean.getClass(), descriptor);
        if (readMethod == null) {
            throw new NoSuchMethodException(
                    "Property '" + name + "' has no getter method in class '" + bean.getClass() + "'");
        }

        // Call the property getter and return the value
        final Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
        return value;
    }

}

From source file:org.enerj.apache.commons.beanutils.PropertyUtilsBean.java

/**
 * Set the value of the specified mapped property of the specified
 * bean, with no type conversions.// ww w .j a  v a 2  s.  c  om
 *
 * @param bean Bean whose property is to be set
 * @param name Mapped property name of the property value to be set
 * @param key Key of the property value to be set
 * @param value The property value to be set
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public void setMappedProperty(Object bean, String name, String key, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified");
    }
    if (key == null) {
        throw new IllegalArgumentException("No key specified");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException("Unknown property '" + name + "'");
        }
        ((DynaBean) bean).set(name, key, value);
        return;
    }

    // Retrieve the property descriptor for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException("Unknown property '" + name + "'");
    }

    if (descriptor instanceof MappedPropertyDescriptor) {
        // Call the keyed setter method if there is one
        Method mappedWriteMethod = ((MappedPropertyDescriptor) descriptor).getMappedWriteMethod();
        if (mappedWriteMethod != null) {
            Object params[] = new Object[2];
            params[0] = key;
            params[1] = value;
            if (log.isTraceEnabled()) {
                String valueClassName = value == null ? "<null>" : value.getClass().getName();
                log.trace("setSimpleProperty: Invoking method " + mappedWriteMethod + " with key=" + key
                        + ", value=" + value + " (class " + valueClassName + ")");
            }
            invokeMethod(mappedWriteMethod, bean, params);
        } else {
            throw new NoSuchMethodException("Property '" + name + "' has no mapped setter method");
        }
    } else {
        /* means that the result has to be retrieved from a map */
        Method readMethod = descriptor.getReadMethod();
        if (readMethod != null) {
            Object invokeResult = invokeMethod(readMethod, bean, new Object[0]);
            /* test and fetch from the map */
            if (invokeResult instanceof java.util.Map) {
                ((java.util.Map) invokeResult).put(key, value);
            }
        } else {
            throw new NoSuchMethodException("Property '" + name + "' has no mapped getter method");
        }
    }

}

From source file:adalid.commons.velocity.Writer.java

private Object invoke(Object object, Set<String> getters, String message) {
    Method[] methods = object.getClass().getMethods();
    for (String getter : getters) {
        for (Method method : methods) {
            if (getter.equals(method.getName())) {
                if (method.getParameterTypes().length == 0) {
                    if (void.class.equals(method.getReturnType())) {
                        break;
                    } else {
                        return invoke(object, method);
                    }//w w  w  .j  a v a 2s  . c  o  m
                }
            }
        }
    }
    throw new RuntimeException(message, new NoSuchMethodException(hintless(message)));
}

From source file:org.enerj.apache.commons.beanutils.PropertyUtilsBean.java

/**
 * Set the value of the specified simple property of the specified bean,
 * with no type conversions.//from  w ww  .  j  ava  2  s .c  om
 *
 * @param bean Bean whose property is to be modified
 * @param name Name of the property to be modified
 * @param value Value to which the property should be set
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception IllegalArgumentException if the property name is
 *  nested or indexed
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public void setSimpleProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified");
    }

    // Validate the syntax of the property name
    if (name.indexOf(PropertyUtils.NESTED_DELIM) >= 0) {
        throw new IllegalArgumentException("Nested property names are not allowed");
    } else if (name.indexOf(PropertyUtils.INDEXED_DELIM) >= 0) {
        throw new IllegalArgumentException("Indexed property names are not allowed");
    } else if (name.indexOf(PropertyUtils.MAPPED_DELIM) >= 0) {
        throw new IllegalArgumentException("Mapped property names are not allowed");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException("Unknown property '" + name + "'");
        }
        ((DynaBean) bean).set(name, value);
        return;
    }

    // Retrieve the property setter method for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException("Unknown property '" + name + "'");
    }
    Method writeMethod = getWriteMethod(descriptor);
    if (writeMethod == null) {
        throw new NoSuchMethodException("Property '" + name + "' has no setter method");
    }

    // Call the property setter method
    Object values[] = new Object[1];
    values[0] = value;
    if (log.isTraceEnabled()) {
        String valueClassName = value == null ? "<null>" : value.getClass().getName();
        log.trace("setSimpleProperty: Invoking method " + writeMethod + " with value " + value + " (class "
                + valueClassName + ")");
    }
    invokeMethod(writeMethod, bean, values);

}

From source file:javadz.beanutils.PropertyUtilsBean.java

/**
 * Set the value of the specified indexed property of the specified
 * bean, with no type conversions.  In addition to supporting the JavaBeans
 * specification, this method has been extended to support
 * <code>List</code> objects as well.
 *
 * @param bean Bean whose property is to be set
 * @param name Simple property name of the property value to be set
 * @param index Index of the property value to be set
 * @param value Value to which the indexed property element is to be set
 *
 * @exception IndexOutOfBoundsException if the specified index
 *  is outside the valid range for the underlying property
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception//from   ww w . ja va 2 s .c om
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public void setIndexedProperty(Object bean, String name, int index, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null || name.length() == 0) {
        if (bean.getClass().isArray()) {
            Array.set(bean, index, value);
            return;
        } else if (bean instanceof List) {
            ((List) bean).set(index, value);
            return;
        }
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on bean class '" + bean.getClass() + "'");
        }
        ((DynaBean) bean).set(name, index, value);
        return;
    }

    // Retrieve the property descriptor for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException(
                "Unknown property '" + name + "' on bean class '" + bean.getClass() + "'");
    }

    // Call the indexed setter method if there is one
    if (descriptor instanceof IndexedPropertyDescriptor) {
        Method writeMethod = ((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod();
        writeMethod = MethodUtils.getAccessibleMethod(bean.getClass(), writeMethod);
        if (writeMethod != null) {
            Object[] subscript = new Object[2];
            subscript[0] = new Integer(index);
            subscript[1] = value;
            try {
                if (log.isTraceEnabled()) {
                    String valueClassName = value == null ? "<null>" : value.getClass().getName();
                    log.trace("setSimpleProperty: Invoking method " + writeMethod + " with index=" + index
                            + ", value=" + value + " (class " + valueClassName + ")");
                }
                invokeMethod(writeMethod, bean, subscript);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof IndexOutOfBoundsException) {
                    throw (IndexOutOfBoundsException) e.getTargetException();
                } else {
                    throw e;
                }
            }
            return;
        }
    }

    // Otherwise, the underlying property must be an array or a list
    Method readMethod = getReadMethod(bean.getClass(), descriptor);
    if (readMethod == null) {
        throw new NoSuchMethodException(
                "Property '" + name + "' has no getter method on bean class '" + bean.getClass() + "'");
    }

    // Call the property getter to get the array or list
    Object array = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
    if (!array.getClass().isArray()) {
        if (array instanceof List) {
            // Modify the specified value in the List
            ((List) array).set(index, value);
        } else {
            throw new IllegalArgumentException(
                    "Property '" + name + "' is not indexed on bean class '" + bean.getClass() + "'");
        }
    } else {
        // Modify the specified value in the array
        Array.set(array, index, value);
    }

}

From source file:org.evergreen.web.utils.beanutils.PropertyUtilsBean.java

/**
 * Set the value of the specified indexed property of the specified
 * bean, with no type conversions.  In addition to supporting the JavaBeans
 * specification, this method has been extended to support
 * <code>List</code> objects as well.
 *
 * @param bean Bean whose property is to be set
 * @param name Simple property name of the property value to be set
 * @param index Index of the property value to be set
 * @param value Value to which the indexed property element is to be set
 *
 * @exception IndexOutOfBoundsException if the specified index
 *  is outside the valid range for the underlying property
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or
 *  <code>name</code> is null
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception//from   w  w w  . j  av  a  2  s. c o m
 * @exception NoSuchMethodException if an accessor method for this
 *  propety cannot be found
 */
public void setIndexedProperty(Object bean, String name, int index, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null || name.length() == 0) {
        if (bean.getClass().isArray()) {
            Array.set(bean, index, value);
            return;
        } else if (bean instanceof List) {
            ((List) bean).set(index, value);
            return;
        }
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Handle DynaBean instances specially
    if (bean instanceof DynaBean) {
        DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name);
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on bean class '" + bean.getClass() + "'");
        }
        ((DynaBean) bean).set(name, index, value);
        return;
    }

    // Retrieve the property descriptor for the specified property
    PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException(
                "Unknown property '" + name + "' on bean class '" + bean.getClass() + "'");
    }

    // Call the indexed setter method if there is one
    if (descriptor instanceof IndexedPropertyDescriptor) {
        Method writeMethod = ((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod();
        writeMethod = MethodUtils.getAccessibleMethod(bean.getClass(), writeMethod);
        if (writeMethod != null) {
            Object[] subscript = new Object[2];
            subscript[0] = new Integer(index);
            subscript[1] = value;
            try {
                if (log.isTraceEnabled()) {
                    String valueClassName = value == null ? "<null>" : value.getClass().getName();
                    log.trace("setSimpleProperty: Invoking method " + writeMethod + " with index=" + index
                            + ", value=" + value + " (class " + valueClassName + ")");
                }
                invokeMethod(writeMethod, bean, subscript);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof IndexOutOfBoundsException) {
                    throw (IndexOutOfBoundsException) e.getTargetException();
                } else {
                    throw e;
                }
            }
            return;
        }
    }

    // Otherwise, the underlying property must be an array or a list
    Method readMethod = getReadMethod(bean.getClass(), descriptor);
    if (readMethod == null) {
        throw new NoSuchMethodException(
                "Property '" + name + "' has no getter method on bean class '" + bean.getClass() + "'");
    }

    // Call the property getter to get the array or list
    Object array = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
    if (!array.getClass().isArray()) {
        if (array instanceof List) {
            // Modify the specified value in the List

            //((List) array).set(index, value);
            //?
            //((List) array).add(value);     
            List list = (List) array;
            Type returnType = readMethod.getGenericReturnType();
            Type acturalType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
            list.add(ConvertUtils.convert(value, (Class) acturalType));
        } else if (array instanceof Set) {
            //?set??
            //((Set) array).add(value);
            Set set = (Set) array;
            Type returnType = readMethod.getGenericReturnType();
            Type acturalType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
            set.add(ConvertUtils.convert(value, (Class) acturalType));
        } else {
            throw new IllegalArgumentException(
                    "Property '" + name + "' is not indexed on bean class '" + bean.getClass() + "'");
        }
    } else {
        // Modify the specified value in the array
        Array.set(array, index, value);
    }

}