Example usage for org.apache.commons.beanutils MappedPropertyDescriptor setReadMethod

List of usage examples for org.apache.commons.beanutils MappedPropertyDescriptor setReadMethod

Introduction

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

Prototype

public synchronized void setReadMethod(Method readMethod) throws IntrospectionException 

Source Link

Document

Sets the method that should be used to read the property value.

Usage

From source file:no.sesat.search.datamodel.generic.MapDataObjectBeanInfo.java

/** Work around for 4984912.
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4984912
 * TODO remove with java6/* www  .j  av  a 2s  . c  o  m*/
 **/
private static void fixForJavaBug4984912(final Class<?> cls, final MappedPropertyDescriptor mpd)
        throws IntrospectionException {

    try {
        final String name = mpd.getName();
        final String captialised = Character.toUpperCase(name.charAt(0)) + name.substring(1);
        Method m = null;
        try {
            // try plural with "s" first, then fall back onto "es"
            m = cls.getMethod("get" + captialised + 's', new Class[0]);
        } catch (NoSuchMethodException nsme) {
            // who on earth designed the english language!?? :@
            m = cls.getMethod("get" + captialised + "es", new Class[0]);
        }
        mpd.setReadMethod(m);

    } catch (NoSuchMethodException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (SecurityException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}