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

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

Introduction

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

Prototype

public synchronized Method getReadMethod() 

Source Link

Document

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

Usage

From source file:no.sesat.search.datamodel.DataModelFactoryImplTest.java

/**
 *
 * @throws java.lang.Exception//from  w ww. j  a  v  a 2 s  .  co  m
 */
@Test
public void testDataObjectGetters() throws Exception {

    LOG.info("testDataObjectGetters()");
    scan(DataObject.class, DataModel.class, new Command() {
        public void execute(Object... args) {

            try {
                final Class<?> cls = (Class<?>) args[0];
                final Object dataObject = testInstantiate(cls);

                final PropertyDescriptor[] properties = Introspector.getBeanInfo(cls).getPropertyDescriptors();
                for (PropertyDescriptor property : properties) {
                    if (null != property.getReadMethod()) {
                        final Object value = invoke(property.getReadMethod(), dataObject, new Object[0]);
                        LOG.info("        Getter on " + property.getName() + " returned " + value);
                    }
                    if (property instanceof MappedPropertyDescriptor) {
                        final MappedPropertyDescriptor mappedProperty = (MappedPropertyDescriptor) property;
                        if (null != mappedProperty.getReadMethod()) {
                            final Object value = invoke(mappedProperty.getMappedReadMethod(), dataObject, "");
                            LOG.info("        Getter on " + mappedProperty.getName() + " returned " + value);
                        }
                    }
                }
            } catch (IntrospectionException ie) {
                LOG.info(ie.getMessage(), ie);
                throw new RuntimeException(ie.getMessage(), ie);
            }
        }
    });
}