private void handleIndexedPropertyDescriptors()

in src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java [89:147]


    private void handleIndexedPropertyDescriptors(final Class<?> beanClass,
            final PropertyDescriptor[] descriptors) {
        for (final PropertyDescriptor pd : descriptors) {
            if (pd instanceof IndexedPropertyDescriptor) {
                final IndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor) pd;
                final String propName = descriptor.getName().substring(0, 1)
                        .toUpperCase()
                        + descriptor.getName().substring(1);

                if (descriptor.getReadMethod() == null) {
                    final String methodName = descriptor.getIndexedReadMethod() != null ? descriptor
                            .getIndexedReadMethod().getName() : "get"
                            + propName;
                    final Method readMethod = MethodUtils
                            .getMatchingAccessibleMethod(beanClass, methodName,
                                    BeanUtils.EMPTY_CLASS_ARRAY);
                    if (readMethod != null) {
                        try {
                            descriptor.setReadMethod(readMethod);
                        } catch (final Exception e) {
                            log.error(
                                    "Error setting indexed property read method",
                                    e);
                        }
                    }
                }
                if (descriptor.getWriteMethod() == null) {
                    final String methodName = descriptor.getIndexedWriteMethod() != null ? descriptor
                            .getIndexedWriteMethod().getName() : "set"
                            + propName;
                    Method writeMethod = MethodUtils
                            .getMatchingAccessibleMethod(beanClass, methodName,
                                    LIST_CLASS_PARAMETER);
                    if (writeMethod == null) {
                        for (final Method m : beanClass.getMethods()) {
                            if (m.getName().equals(methodName)) {
                                final Class<?>[] parameterTypes = m.getParameterTypes();
                                if (parameterTypes.length == 1
                                        && List.class
                                                .isAssignableFrom(parameterTypes[0])) {
                                    writeMethod = m;
                                    break;
                                }
                            }
                        }
                    }
                    if (writeMethod != null) {
                        try {
                            descriptor.setWriteMethod(writeMethod);
                        } catch (final Exception e) {
                            log.error(
                                    "Error setting indexed property write method",
                                    e);
                        }
                    }
                }
            }
        }
    }