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

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

Introduction

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

Prototype

public BasicDynaClass(String name, Class dynaBeanClass, DynaProperty properties[]) 

Source Link

Document

Construct a new BasicDynaClass with the specified parameters.

Usage

From source file:org.agnitas.web.EmmActionAction.java

public List<DynaBean> getActionList(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {
    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));
    List<Integer> charColumns = Arrays.asList(new Integer[] { 0, 1 });
    String[] columns = new String[] { "r.shortname", "r.description", "", "" };

    int sortcolumnindex = 0;
    if (request.getParameter(
            new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT)) != null) {
        sortcolumnindex = Integer.parseInt(request.getParameter(
                new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT)));
    }/*from   ww  w.j a  v a2  s  .co m*/

    String sort = columns[sortcolumnindex];
    if (charColumns.contains(sortcolumnindex)) {
        sort = "upper( " + sort + " )";
    }

    int order = 1;
    if (request.getParameter(
            new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER)) != null) {
        order = new Integer(request.getParameter(
                new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
    }

    String sqlStatement = "SELECT r.action_id, r.shortname, r.description, count(u.form_id) used "
            + " FROM rdir_action_tbl r LEFT JOIN userform_tbl u ON (u.startaction_id = r.action_id or u.endaction_id = r.action_id) "
            + " WHERE r.company_id= " + AgnUtils.getCompanyID(request)
            + " GROUP BY  r.action_id, r.shortname, r.description " + " ORDER BY " + sort + " "
            + (order == 1 ? "ASC" : "DESC");

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);
    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("actionId", Long.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
            new DynaProperty("used", Long.class) };

    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("actionId", BigDecimal.class),
                new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
                new DynaProperty("used", BigDecimal.class) };
    }

    BasicDynaClass dynaClass = new BasicDynaClass("emmaction", null, properties);

    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("actionId", row.get("ACTION_ID"));
        newBean.set("shortname", row.get("SHORTNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        newBean.set("used", row.get("USED"));
        result.add(newBean);
    }
    return result;
}

From source file:org.agnitas.web.MailingStatAction.java

public List<DynaBean> getMailingStats(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {

    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));

    String sqlStatement = "SELECT a.mailing_id, a.shortname, a.description, b.shortname AS listname "
            + "FROM mailing_tbl a, mailinglist_tbl b WHERE a.company_id=" + AgnUtils.getCompanyID(request) + " "
            + "AND a.mailinglist_id=b.mailinglist_id AND a.deleted=0 AND a.is_template=0 ORDER BY mailing_id DESC";

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);
    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("mailingid", Long.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
            new DynaProperty("listname", String.class), };
    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("mailingid", BigDecimal.class),
                new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
                new DynaProperty("listname", String.class), };
    }/*from   w w w  .java  2  s  .co  m*/
    BasicDynaClass dynaClass = new BasicDynaClass("mailingstat", null, properties);
    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("mailingid", row.get("MAILING_ID"));
        newBean.set("shortname", row.get("SHORTNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        newBean.set("listname", row.get("LISTNAME"));
        result.add(newBean);
    }

    return result;
}

From source file:org.agnitas.web.UserFormEditAction.java

public List<DynaBean> getUserFromList(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {
    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));

    String sqlStatement = "SELECT form_id, formname, description FROM userform_tbl WHERE company_id="
            + AgnUtils.getCompanyID(request) + " ORDER BY formname";

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);

    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("formid", Long.class),
            new DynaProperty("formname", String.class), new DynaProperty("description", String.class) };

    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("formid", BigDecimal.class),
                new DynaProperty("formname", String.class), new DynaProperty("description", String.class) };
    }/*  w ww  .j  a  va 2 s . c  om*/

    BasicDynaClass dynaClass = new BasicDynaClass("userform", null, properties);

    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("formid", row.get("FORM_ID"));
        newBean.set("formname", row.get("FORMNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        result.add(newBean);
    }
    return result;
}

From source file:org.apache.ddlutils.platform.ModelBasedResultSetIterator.java

/**
 * Initializes this iterator from the resultset metadata.
 * //from  ww w .ja  va2s .c o m
 * @param model The database model
 */
private void initFromMetaData(Database model) throws SQLException {
    ResultSetMetaData metaData = _resultSet.getMetaData();
    String tableName = null;
    boolean singleKnownTable = true;

    for (int idx = 1; idx <= metaData.getColumnCount(); idx++) {
        String columnName = metaData.getColumnName(idx);
        String tableOfColumn = metaData.getTableName(idx);
        Table table = null;

        if ((tableOfColumn != null) && (tableOfColumn.length() > 0)) {
            // jConnect might return a table name enclosed in quotes
            if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"")
                    && (tableOfColumn.length() > 1)) {
                tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
            }
            // the JDBC driver gave us enough meta data info
            table = model.findTable(tableOfColumn, _caseSensitive);
        }
        if (table == null) {
            // not enough info in the meta data of the result set, lets try the
            // user-supplied query hints
            table = (Table) _preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
            tableOfColumn = (table == null ? null : table.getName());
        }
        if (tableName == null) {
            tableName = tableOfColumn;
        } else if (!tableName.equals(tableOfColumn)) {
            singleKnownTable = false;
        }

        String propName = columnName;

        if (table != null) {
            Column column = table.findColumn(columnName, _caseSensitive);

            if (column != null) {
                propName = column.getName();
            }
        }
        _columnsToProperties.put(columnName, propName);
    }
    if (singleKnownTable && (tableName != null)) {
        _dynaClass = model.getDynaClassFor(tableName);
    } else {
        DynaProperty[] props = new DynaProperty[_columnsToProperties.size()];
        int idx = 0;

        for (Iterator it = _columnsToProperties.values().iterator(); it.hasNext(); idx++) {
            props[idx] = new DynaProperty((String) it.next());
        }
        _dynaClass = new BasicDynaClass("result", BasicDynaBean.class, props);
    }
}

From source file:org.apache.ojb.broker.metadata.PersistentFieldTest.java

protected DynaClass createDynaClass() {
    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null,
            new DynaProperty[] { new DynaProperty("name", String.class), });
    return (dynaClass);
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>./*from ww  w  . j a  v a2s  .  com*/
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

From source file:org.catechis.Transformer.java

public static DynaBean getWordTestBean(int number_of_words_to_test) {
    DynaProperty[] properties = new DynaProperty[number_of_words_to_test];
    {//from  w w  w  .  ja va2  s  . c o m
        int count = 0;
        while (count < number_of_words_to_test) {
            properties[count] = new DynaProperty("feild" + count, String.class);
            count++;
        }
    }
    ;
    BasicDynaClass word_test_class = new BasicDynaClass("word_test", BasicDynaBean.class, properties);
    DynaBean word_test = new BasicDynaBean(word_test_class);
    try {
        word_test = word_test_class.newInstance();
        int count = 0;
        while (count < number_of_words_to_test) {
            word_test.set("feild" + count, "");
            count++;
        }
    } catch (java.lang.IllegalAccessException iae) {
        word_test = null;
    } catch (java.lang.InstantiationException ie) {
        word_test = null;
    }
    return word_test;
}

From source file:org.catechis.Transformer.java

/**
*<p>Create a Vector of dynamically created beans.
*<p>It only works for flat beans, with one layer of properties.
<p>BasicDynaClass is created like this:
BasicDynaClass(java.lang.String name, java.lang.Class dynaBeanClass, DynaProperty[] properties) 
getComponentType() /*  ww w  . j a  va2s. c  o  m*/
*/
public static Vector loadElements(List list, String object_name, Class class_name) {
    Vector vector = new Vector();
    //BasicDynaClass bd_class = new BasicDynaClass();
    int size = list.size();
    int i = 0;
    // first construct the class
    Element e = (Element) list.get(i);
    List children = e.getChildren();
    int kids = children.size();
    DynaProperty[] dps = new DynaProperty[kids];
    int j = 0;
    while (i < kids) {
        Element kid = (Element) children.get(i);
        String name = kid.getName();
        try {
            dps[j] = new DynaProperty(name);
        } catch (java.lang.ArrayIndexOutOfBoundsException aioob) {
            break;
        }
        j++;
    }
    BasicDynaClass bd_class = new BasicDynaClass(object_name, class_name, dps);
    // then create the instances and populate them
    while (i < size) {
        BasicDynaBean bd_bean = new BasicDynaBean(bd_class);
        Element ee = (Element) list.get(i);
        List childrens = ee.getChildren();
        int kiddies = childrens.size();
        int jj = 0;
        while (jj < kids) {
            Element kidd = (Element) childrens.get(jj);
            //Element child = kidds.getChild();
            String name = kidd.getName();
            String value = (String) kidd.getChildText(name);
            bd_bean.set(name, value);
            jj++;
        }
        vector.add(bd_bean);
        i++;
    }
    return vector;
}

From source file:org.examproject.task.core.ArgumentBeanFactory.java

@Override
public Object create() {
    LOG.debug("called.");
    try {/*from w  w w. ja  v a 2  s  .co m*/
        // create a dynaproperty array.
        DynaProperty[] props = new DynaProperty[3];

        // create a dynaproperty object.
        props[0] = new DynaProperty("count", Integer.class);
        props[1] = new DynaProperty("job", Closure.class);
        props[2] = new DynaProperty("state", DynaBean.class);

        // create a dynaclass object.
        DynaClass clazz = new BasicDynaClass("argument", BasicDynaBean.class, props);

        // create a dynabean object.
        DynaBean bean = clazz.newInstance();

        // return the dynabean object.
        return bean;

    } catch (Exception e) {
        LOG.error(e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:org.examproject.task.core.ParamBeanFactory.java

@Override
public Object create() {
    LOG.debug("called.");
    try {/*from  w w w.ja  v a2s  . c o m*/
        // create a dynaproperty array.
        DynaProperty[] props = new DynaProperty[1];

        // create a dynaproperty object.
        props[0] = new DynaProperty("values", Map.class);

        // create a dynaclass object.
        DynaClass clazz = new BasicDynaClass("param", BasicDynaBean.class, props);

        // create a dynabean object.
        DynaBean bean = clazz.newInstance();

        // create the values map.
        bean.set("values", new ConcurrentHashMap<String, Object>());

        // return the dynabean object.
        return bean;

    } catch (Exception e) {
        LOG.error(e.getMessage());
        throw new RuntimeException(e);
    }
}