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

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

Introduction

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

Prototype

public Class getMappedPropertyType() 

Source Link

Document

Gets the Class object for the property values.

Usage

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

private void handleMappedProperty(final Collection<Method> propertyMethods,
        final MappedPropertyDescriptor property) throws IntrospectionException {

    if (null != property.getMappedReadMethod()) {
        propertyMethods.add(property.getMappedReadMethod());
        // recurse down the datamodel heirarchy
        if (null != property.getMappedPropertyType().getAnnotation(DataObject.class)) {
            ensureJavaBeanAPI(property.getMappedPropertyType());
        }//  w  w  w .ja va 2s . c o  m
    }
    if (null != property.getMappedWriteMethod()) {
        propertyMethods.add(property.getMappedWriteMethod());
    }
}

From source file:org.apache.torque.dsfactory.AbstractDataSourceFactory.java

/**
 * Encapsulates setting configuration properties on
 * <code>DataSource</code> objects.
 *
 * @param property the property to read from the configuration
 * @param c the configuration to read the property from
 * @param ds the <code>DataSource</code> instance to write the property to
 * @throws Exception if anything goes wrong
 *//*from  w w w  .  j av a 2  s. co  m*/
protected void setProperty(String property, Configuration c, Object ds) throws Exception {
    if (c == null || c.isEmpty()) {
        return;
    }

    String key = property;
    Class<?> dsClass = ds.getClass();
    int dot = property.indexOf('.');
    try {
        if (dot > 0) {
            property = property.substring(0, dot);

            MappedPropertyDescriptor mappedPD = new MappedPropertyDescriptor(property, dsClass);
            Class<?> propertyType = mappedPD.getMappedPropertyType();
            Configuration subProps = c.subset(property);
            // use reflection to set properties
            Iterator<?> j = subProps.getKeys();
            while (j.hasNext()) {
                String subProp = (String) j.next();
                String propVal = subProps.getString(subProp);
                Object value = ConvertUtils.convert(propVal, propertyType);
                PropertyUtils.setMappedProperty(ds, property, subProp, value);

                if (log.isDebugEnabled()) {
                    log.debug(
                            "setMappedProperty(" + ds + ", " + property + ", " + subProp + ", " + value + ")");
                }
            }
        } else {
            if ("password".equals(key)) {
                // do not log value of password
                // for this, ConvertUtils.convert cannot be used
                // as it also logs the value of the converted property
                // so it is assumed here that the password is a String
                String value = c.getString(property);
                PropertyUtils.setSimpleProperty(ds, property, value);
                if (log.isDebugEnabled()) {
                    log.debug("setSimpleProperty(" + ds + ", " + property + ", " + " (value not logged)" + ")");
                }
            } else {
                Class<?> propertyType = PropertyUtils.getPropertyType(ds, property);
                Object value = ConvertUtils.convert(c.getString(property), propertyType);
                PropertyUtils.setSimpleProperty(ds, property, value);

                if (log.isDebugEnabled()) {
                    log.debug("setSimpleProperty(" + ds + ", " + property + ", " + value + ")");
                }
            }
        }
    } catch (RuntimeException e) {
        throw new TorqueRuntimeException("Runtime error setting property " + property, e);
    } catch (Exception e) {
        log.error("Property: " + property + " value: " + c.getString(key) + " is not supported by DataSource: "
                + ds.getClass().getName());
    }
}