Example usage for org.apache.commons.beanutils LazyDynaBean LazyDynaBean

List of usage examples for org.apache.commons.beanutils LazyDynaBean LazyDynaBean

Introduction

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

Prototype

public LazyDynaBean() 

Source Link

Document

Construct a new LazyDynaBean with a LazyDynaClass instance.

Usage

From source file:DynaBeansExampleV1.java

private static DynaBean createPersonBean() {
    DynaBean person = new LazyDynaBean();
    return person;
}

From source file:io.coala.experimental.dynabean.DynaBeanTest.java

@Test
public void testDynaBeans() throws Exception {
    // for usage, see
    // http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description

    final DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean
    final MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass(); // get DynaClass

    dynaClass.add("amount", java.lang.Integer.class); // add property
    dynaClass.add("myMap", java.util.TreeMap.class); // add mapped property

    final DynaBean employee = dynaClass.newInstance();

    // TODO experiment with Jackson's AnnotationIntrospector to annotate
    // DynaBean#get(...) method with @JsonAnyGetter and #set(...) method
    // with @JsonAnySetter

    employee.set("address", new HashMap<String, String>());
    employee.set("activeEmployee", Boolean.FALSE);
    employee.set("firstName", "Fred");
    employee.set("lastName", "Flintstone");

    LOG.trace("Employee: " + JsonUtil.toPrettyJSON(employee));

    // set all <activeEmployee> attribute values to <true>
    final BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("activeEmployee",
            Boolean.TRUE);/*ww w.  j av  a2  s.  c  om*/

    final Collection<?> employees = Collections.singleton(employee);
    LOG.trace("Mutated employees: " + JsonUtil.toPrettyJSON(employees));

    // update the Collection
    CollectionUtils.forAllDo(employees, closure);

    // filter for beans with <activeEmployee> set to <false>
    final BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate("lastName",
            "Flintstone");

    // filter the Collection
    CollectionUtils.filter(employees, predicate);
    LOG.trace("Filtered employees: " + JsonUtil.toPrettyJSON(employees));
}

From source file:net.sf.excelutils.ExcelParser.java

/**
 * get the value from context by the expression
 * /*from  w  w  w .  jav a  2 s . c om*/
 * @param expr
 * @param context data object
 * @return Object the value of the expr
 */
public static Object getValue(Object context, String expr) {
    Object value = null;
    try {
        value = PropertyUtils.getProperty(context, expr);
        // ?
        int index = expr.indexOf(INDEXED_DELIM);
        int index2 = expr.indexOf(INDEXED_DELIM2, index);
        if (index >= 0 && index2 > 0 && index2 > index) {
            // ?,?1[]
            if (expr.indexOf(INDEXED_DELIM, index2) >= 0) {
                DynaBean bean = new LazyDynaBean();
                bean.set("list_value", value);
                value = getValue(bean, "list_value" + expr.substring(index2 + 1));
            }
        }
    } catch (Exception e) {
        return null;
    }
    return value;
}

From source file:net.sf.excelutils.ExcelUtils.java

/**
 * get a global context, it's thread safe
 * /*from  ww  w. j  a v  a2  s. c o  m*/
 * @return DynaBean
 */
public static DynaBean getContext() {
    DynaBean ctx = (DynaBean) context.get();
    if (null == ctx) {
        ctx = new LazyDynaBean();
        setContext(ctx);
    }
    return ctx;
}

From source file:com.feilong.core.bean.BeanUtilTest.java

@Test
public void testLazyDynaBean() {
    DynaBean dynaBean = new LazyDynaBean();

    dynaBean.set("first", "1"); //simple
    dynaBean.set("num", "second", "2"); //map
    dynaBean.set("num", "third", "3"); //map
    dynaBean.set("name", 0, "one"); //indexed
    dynaBean.set("name", 1, "two"); //indexed
    LOGGER.debug(JsonUtil.format(dynaBean));
}

From source file:com.emergya.persistenceGeo.dao.impl.PostgisDBManagementDaoHibernateImpl.java

@Override
public boolean createLayerTable(String tableName, int srsCode, GeometryType geometryType) {
    List<DynaBean> columns = new ArrayList<DynaBean>();
    DynaBean fieldId = new LazyDynaBean();
    fieldId.set("name", "id");
    fieldId.set("type", "serial");
    fieldId.set("primaryKey", true);

    columns.add(fieldId);/*ww  w.ja  v a 2 s  . co m*/

    DynaBean fieldDesc = new LazyDynaBean();
    fieldDesc.set("name", "descripcion");
    fieldDesc.set("type", "character varying(512)");
    fieldDesc.set("primaryKey", false);
    columns.add(fieldDesc);

    return createLayerTable(tableName, columns, srsCode, geometryType);
}

From source file:com.feilong.core.bean.BeanUtil.java

/**
 * New dyna bean.//from  w w  w . j  av  a 2 s. c om
 * 
 * <p>
 * {@link LazyDynaBean}????DynaClass?LazyDynaBean??<br>
 * {@link LazyDynaBean}???mapkey-value pairLazyDynaBeanmapmetadatametadata<br>
 * 
 * ?, {@link org.apache.commons.beanutils.LazyDynaClass}
 * </p>
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * DynaBean newDynaBean = BeanUtil.newDynaBean(toMap(//
 *                 Pair.of("address", (Object) new HashMap()),
 *                 Pair.of("firstName", (Object) "Fred"),
 *                 Pair.of("lastName", (Object) "Flintstone")));
 * LOGGER.debug(JsonUtil.format(newDynaBean));
 * 
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * {
"address": {},
"firstName": "Fred",
"lastName": "Flintstone"
}
 * </pre>
 * 
 * </blockquote>
 *
 * @param valueMap
 *            the value map
 * @return the dyna bean
 * @see org.apache.commons.beanutils.LazyDynaBean
 * @throws NullPointerException
 *              <code>valueMap</code> null, mapkeynull
 * @since 1.8.1
 */
public static DynaBean newDynaBean(Map<String, ?> valueMap) {
    Validate.notNull(valueMap, "valueMap can't be null!");

    LazyDynaBean lazyDynaBean = new LazyDynaBean();
    for (Map.Entry<String, ?> entry : valueMap.entrySet()) {
        Validate.notBlank(entry.getKey(), "entry.getKey() can't be blank!");
        lazyDynaBean.set(entry.getKey(), entry.getValue());
    }
    return lazyDynaBean;
}

From source file:org.apache.struts.validator.LazyValidatorForm.java

/**
 * Default Constructor which creates a <code>LazyDynaBean</code> to
 * <i>back</i> this form.//w ww . j a  v  a 2s  .c o m
 */
public LazyValidatorForm() {
    super(new LazyDynaBean());
}

From source file:org.apache.struts.validator.LazyValidatorForm.java

/**
 * <p>Creates new <code>DynaBean</code> instances to populate an 'indexed'
 * property of beans - defaults to <code>LazyDynaBean</code> type.</p>
 *
 * <p>Override this method if you require a different type of
 * <code>DynaBean</code>.</p>
 */// w w w. j  av  a  2  s.  c  om
protected DynaBean newIndexedBean(String name) {
    return new LazyDynaBean();
}

From source file:org.opoo.oqs.core.mapper.DynaBeanPropertyMapper.java

/**
 *
 * @param resultSet ResultSet//from  w ww.  j  ava2  s.  c  o m
 * @param _int int
 * @return Object
 * @throws SQLException
 */
public Object map(ResultSet resultSet, int _int) throws SQLException {
    DynaBean bean = new LazyDynaBean();
    for (int i = 0; i < mappers.length; i++) {
        bean.set(mappers[i].getName(), mappers[i].map(resultSet, _int));
    }
    return bean;
}