Example usage for org.apache.commons.beanutils WrapDynaBean set

List of usage examples for org.apache.commons.beanutils WrapDynaBean set

Introduction

In this page you can find the example usage for org.apache.commons.beanutils WrapDynaBean set.

Prototype

public void set(String name, Object value) 

Source Link

Document

Set the value of a simple property with the specified name.

Usage

From source file:com.qagen.osfe.core.utils.BeanPopulator.java

public static void populateBean(List<RowValue> rowValues, Object bean) {
    final WrapDynaBean wrapDynaBean = new WrapDynaBean(bean);

    for (RowValue rowValue : rowValues) {
        final String name = rowValue.getDescription().getName();
        final String value = rowValue.getValue();
        final String type = rowValue.getDescription().getType();
        final String format = rowValue.getDescription().getFormat();
        wrapDynaBean.set(name, getValueAsType(name, value, type, format));
    }//  w  w  w  .j av  a  2s .c  om
}

From source file:au.com.jwatmuff.eventmanager.util.CSVBeanReader.java

public T readBean() {
    if (!headerRead)
        readHeader();/*from  w  w  w.j  a  v a 2 s  .  com*/

    T bean;
    try {
        bean = (T) clazz.newInstance();
        WrapDynaBean dynaBean = new EnumConvertingWrapDynaBean(bean);

        String[] line = reader.readNext();
        if (line == null)
            return null;

        for (int i = 0; i < line.length; i++) {
            if (propertyNames[i] != null) {
                dynaBean.set(propertyNames[i], line[i]);
            }
        }
    } catch (InstantiationException e) {
        throw new RuntimeException("Unable to create bean of class " + clazz, e);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException("Unable to create bean of class " + clazz, iae);
    } catch (IOException ioe) {
        log.error("IOException while reading from CSV file", ioe);
        return null;
    }

    return bean;
}

From source file:org.faster.util.Beans.java

/**
 * ??/*from  ww w .j  a v  a  2 s  . c  o  m*/
 *
 * @param dest 
 * @param orig 
 * @param ignoreNullValue ?
 * @param propertyNames ??
 */
public static void slicePopulate(Object dest, Object orig, boolean ignoreNullValue, String... propertyNames) {
    WrapDynaBean destBean = new WrapDynaBean(dest);
    WrapDynaBean origBean = new WrapDynaBean(orig);
    for (String propertyName : propertyNames) {
        Object value = origBean.get(propertyName);
        if (ignoreNullValue && isNullOrEmpty(value)) {
            continue;
        }

        destBean.set(propertyName, value);
    }
}

From source file:org.faster.util.Beans.java

@SuppressWarnings("unchecked")
public static <T> T slice(T orig, boolean ignoreNullValue, String... propertyNames) {
    if (propertyNames == null || propertyNames.length == 0) {
        return orig;
    }/*from w  ww.j  av a  2 s  .c  om*/

    T dest = (T) Beans.newInstance(orig.getClass());
    WrapDynaBean destBean = new WrapDynaBean(dest);
    WrapDynaBean origBean = new WrapDynaBean(orig);
    for (String propertyName : propertyNames) {
        Object value = origBean.get(propertyName);
        if (ignoreNullValue && Beans.isNullOrEmpty(value)) {
            continue;
        }

        destBean.set(propertyName, value);
    }
    return dest;
}

From source file:org.gbif.registry.ws.guice.StringTrimInterceptor.java

private void trimStringsOf(Object target, int level) {
    if (target != null && level <= MAX_RECURSION) {
        LOG.debug("Trimming class: {}", target.getClass());

        WrapDynaBean wrapped = new WrapDynaBean(target);
        DynaClass dynaClass = wrapped.getDynaClass();
        for (DynaProperty dynaProp : dynaClass.getDynaProperties()) {
            if (String.class.isAssignableFrom(dynaProp.getType())) {
                String prop = dynaProp.getName();
                String orig = (String) wrapped.get(prop);
                if (orig != null) {
                    String trimmed = Strings.emptyToNull(orig.trim());
                    if (!Objects.equal(orig, trimmed)) {
                        LOG.debug("Overriding value of [{}] from [{}] to [{}]", prop, orig, trimmed);
                        wrapped.set(prop, trimmed);
                    }//w  w w. j a v  a2s .  c  om
                }
            } else {
                try {
                    // trim everything in the registry model package (assume that Dataset resides in the correct package here)
                    Object property = wrapped.get(dynaProp.getName());
                    if (property != null && Dataset.class.getPackage() == property.getClass().getPackage()) {
                        trimStringsOf(property, level + 1);
                    }

                } catch (IllegalArgumentException e) {
                    // expected for non accessible properties
                }
            }
        }
    }
}

From source file:org.gbif.registry2.ws.guice.StringTrimInterceptor.java

private void trimStringsOf(Object target) {
    WrapDynaBean wrapped = new WrapDynaBean(target);
    DynaClass dynaClass = wrapped.getDynaClass();
    for (DynaProperty dynaProp : dynaClass.getDynaProperties()) {
        // Only operate on strings
        if (String.class.isAssignableFrom(dynaProp.getType())) {
            String prop = dynaProp.getName();
            String orig = (String) wrapped.get(prop);
            if (orig != null) {
                String trimmed = Strings.emptyToNull(orig.trim());
                if (!Objects.equal(orig, trimmed)) {
                    LOG.debug("Overriding value of [{}] from [{}] to [{}]", prop, orig, trimmed);
                    wrapped.set(prop, trimmed);
                }/*from   www .  ja v a  2s .c  o  m*/
            }
        }
    }
}

From source file:org.latticesoft.util.common.BeanUtil.java

public static void setAttribute(Object bean, String attribute, Object value) {
    if (bean == null || attribute == null || value == null)
        return;/*from   ww w.  ja v a 2  s  .  c o m*/
    if (bean instanceof Map) {
        Map map = (Map) bean;
        map.put(attribute, value);
    } else if (bean instanceof WrapDynaBean) {
        WrapDynaBean w = (WrapDynaBean) bean;
        w.set(attribute, value);
    } else {
        WrapDynaBean w = new WrapDynaBean(bean);
        w.set(attribute, value);
    }
}

From source file:org.latticesoft.util.resource.dao.Param.java

/**
 * @see #populate(Object, ResultSet)/*from   w w w. jav a 2 s . co m*/
 * @exception throws SQLException
 */
public void populateEx(Object o, ResultSet rs) throws SQLException {
    Object value = this.readValue(rs);
    if (o instanceof WrapDynaBean) {
        WrapDynaBean bean = (WrapDynaBean) o;
        bean.set(this.getAttribute(), value);
    } else if (o instanceof Map) {
        Map map = (Map) o;
        map.put(this.getAttribute(), value);
    } else {
        WrapDynaBean bean = new WrapDynaBean(o);
        bean.set(this.getAttribute(), value);
    }
}