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

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

Introduction

In this page you can find the example usage for org.apache.commons.beanutils DynaBean 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:org.catechis.Transformer.java

public static DynaBean getWordTestBean(int number_of_words_to_test) {
    DynaProperty[] properties = new DynaProperty[number_of_words_to_test];
    {//from   ww w .  j  a  v  a  2  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.examproject.task.core.Facade.java

@Override
public void run() {
    LOG.debug("called.");

    try {/*from   ww  w.jav a 2s.c  o m*/
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> facade begin.");
        LOG.info("processing at " + new Date());

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        // initialize the content object for this run.
        init();

        // set the param for the worker object of the list.
        List<Runnable> workerList = new CopyOnWriteArrayList<Runnable>();
        for (int i = 0; i < contentList.size(); i++) {

            // create the beans of result for the worker. 
            DynaBean result = (DynaBean) resultBeanFactory.create();

            // create the beans of state for the worker.
            DynaBean state = (DynaBean) stateBeanFactory.create();

            // create the beans of argument for the worker.
            DynaBean argument = (DynaBean) argumentBeanFactory.create();

            // build the parameter for the worker.
            state.set("result", result);
            state.set("param", getParam());
            argument.set("job", jobClosure);
            argument.set("state", state);
            argument.set("count", counter.incrementAndGet());

            // set the argument object for the worker.
            Runnable worker = (Runnable) context.getBean(workerBeanId, argument);

            // add the worker to the list.
            workerList.add(worker);
        }

        // run the all of the worker object.
        for (int i = 0; i < workerList.size(); i++) {
            executor.execute(workerList.get(i));
        }

        stopWatch.stop();

        LOG.info("execute time: " + stopWatch.getTime() + " msec");
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade end.");

    } catch (Exception e) {
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade error.");
        LOG.error("exception occurred. " + e.getMessage());

        // TODO: final strategy of the error!
        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.j av a2 s  . c  om*/
        // 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);
    }
}

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

@Override
public Object create() {
    LOG.debug("called.");
    try {//  w  ww  . j a  v  a2  s  .  c om
        // 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("result", 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);
    }
}

From source file:org.jwebsocket.dynamicsql.DynaDB.java

/**
 * Convert the item map to DynaBean object of a table.
 *
 * @param aTableName The table name.//from   w w w.  j  a  v  a 2 s  . c o m
 * @param aItem The values of a tuple in map form.
 * @return The DynaBean object.
 */
private DynaBean createDynaBean(String aTableName, Map<String, Object> aItem) {
    DynaBean lDynaBean = mDB.createDynaBeanFor(aTableName, true);

    for (Map.Entry<String, Object> entry : aItem.entrySet()) {
        lDynaBean.set(entry.getKey(), entry.getValue());
    }
    return lDynaBean;
}

From source file:org.kohsuke.stapler.jelly.groovy.JellyBuilder.java

private void configureTag(Tag tag, Map attributes) throws JellyException {
    if (tag instanceof DynaTag) {
        DynaTag dynaTag = (DynaTag) tag;

        for (Object o : attributes.entrySet()) {
            Entry entry = (Entry) o;/*  ww  w  .  j a  v  a  2  s  .com*/
            String name = (String) entry.getKey();
            if (name.equals("xmlns"))
                continue; // we'll process this by ourselves

            Object value = getValue(entry, dynaTag.getAttributeType(name));
            dynaTag.setAttribute(name, value);
        }
    } else {
        // treat the tag as a bean
        DynaBean dynaBean = new ConvertingWrapDynaBean(tag);
        for (Object o : attributes.entrySet()) {
            Entry entry = (Entry) o;
            String name = (String) entry.getKey();
            if (name.equals("xmlns"))
                continue; // we'll process this by ourselves

            DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name);
            if (property == null) {
                throw new JellyException("This tag does not understand the '" + name + "' attribute");
            }

            dynaBean.set(name, getValue(entry, property.getType()));
        }
    }
}

From source file:org.openbravo.erpCommon.modules.ImportModule.java

/**
 * Inserts in database the Vector<DynaBean> with its dependencies
 * /*from   w  ww  . j  a  v a 2s.co  m*/
 * @param dModulesToInstall
 * @param dependencies1
 * @param newModule
 * @throws Exception
 */
private void insertDynaModulesInDB(Vector<DynaBean> dModulesToInstall, Vector<DynaBean> dependencies1,
        Vector<DynaBean> dbPrefix, boolean newModule) throws Exception {
    final Properties obProperties = new Properties();
    obProperties.load(new FileInputStream(obDir + "/config/Openbravo.properties"));

    final String url = obProperties.getProperty("bbdd.url")
            + (obProperties.getProperty("bbdd.rdbms").equals("POSTGRE")
                    ? "/" + obProperties.getProperty("bbdd.sid")
                    : "");

    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(obProperties.getProperty("bbdd.driver"));
    ds.setUrl(url);
    ds.setUsername(obProperties.getProperty("bbdd.user"));
    ds.setPassword(obProperties.getProperty("bbdd.password"));

    final Connection conn = ds.getConnection();

    Integer seqNo = new Integer(ImportModuleData.selectSeqNo(pool));

    for (final DynaBean module : dModulesToInstall) {
        seqNo += 10;
        module.set("ISDEFAULT", "N");
        module.set("STATUS", "I");
        module.set("SEQNO", seqNo);
        module.set("UPDATE_AVAILABLE", null);
        module.set("UPGRADE_AVAILABLE", null);
        log4j.info("Inserting in DB info for module: " + module.get("NAME"));

        String moduleId = (String) module.get("AD_MODULE_ID");

        // Clean temporary tables
        ImportModuleData.cleanModuleInstall(pool, moduleId);
        ImportModuleData.cleanModuleDBPrefixInstall(pool, moduleId);
        ImportModuleData.cleanModuleDependencyInstall(pool, moduleId);

        String type = (String) module.get("TYPE");
        String applyConfigScript = "Y";
        if ("T".equals(type)) {
            if (newModule && V3_TEMPLATE_ID.equals(moduleId)) {
                // When installing V3 template do not apply its config script
                applyConfigScript = "N";
            } else {
                org.openbravo.model.ad.module.Module template = OBDal.getInstance()
                        .get(org.openbravo.model.ad.module.Module.class, moduleId);
                applyConfigScript = template == null ? "Y" : template.isApplyConfigurationScript() ? "Y" : "N";
            }
        }

        // Insert data in temporary tables
        ImportModuleData.insertModuleInstall(pool, moduleId, (String) module.get("NAME"),
                (String) module.get("VERSION"), (String) module.get("DESCRIPTION"), (String) module.get("HELP"),
                (String) module.get("URL"), type, (String) module.get("LICENSE"),
                (String) module.get("ISINDEVELOPMENT"), (String) module.get("ISDEFAULT"), seqNo.toString(),
                (String) module.get("JAVAPACKAGE"), (String) module.get("LICENSETYPE"),
                (String) module.get("AUTHOR"), (String) module.get("STATUS"),
                (String) module.get("UPDATE_AVAILABLE"), (String) module.get("ISTRANSLATIONREQUIRED"),
                (String) module.get("AD_LANGUAGE"), (String) module.get("HASCHARTOFACCOUNTS"),
                (String) module.get("ISTRANSLATIONMODULE"), (String) module.get("HASREFERENCEDATA"),
                (String) module.get("ISREGISTERED"), (String) module.get("UPDATEINFO"),
                (String) module.get("UPDATE_VER_ID"), (String) module.get("REFERENCEDATAINFO"),
                applyConfigScript);

        // Set installed for modules being updated
        ImportModuleData.setModuleUpdated(pool, (String) module.get("AD_MODULE_ID"));

        addLog("@ModuleInstalled@ " + module.get("NAME") + " - " + module.get("VERSION"), MSG_SUCCESS);
    }
    for (final DynaBean module : dependencies1) {
        ImportModuleData.insertModuleDependencyInstall(pool, (String) module.get("AD_MODULE_DEPENDENCY_ID"),
                (String) module.get("AD_MODULE_ID"), (String) module.get("AD_DEPENDENT_MODULE_ID"),
                (String) module.get("STARTVERSION"), (String) module.get("ENDVERSION"),
                (String) module.get("ISINCLUDED"), (String) module.get("DEPENDANT_MODULE_NAME"));
    }
    for (final DynaBean module : dbPrefix) {
        ImportModuleData.insertModuleDBPrefixInstall(pool, (String) module.get("AD_MODULE_DBPREFIX_ID"),
                (String) module.get("AD_MODULE_ID"), (String) module.get("NAME"));
    }

    conn.close();
}

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

/**
 *
 * @param resultSet ResultSet/*from  w ww.j av a 2s .  c om*/
 * @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;
}

From source file:org.oscarehr.common.web.BillingreferralEditAction.java

public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from  w ww . ja v a  2s. com
    DynaBean lazyForm = (DynaBean) form;

    List<Billingreferral> referrals = bDao.getBillingreferral(request.getParameter("referralNo"));
    Billingreferral referral = referrals.get(0);

    lazyForm.set("referral", referral);

    return mapping.findForward("detail");
}

From source file:org.oscarehr.common.web.BillingreferralEditAction.java

public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from ww  w. j av a  2s  .c o  m
    DynaBean lazyForm = (DynaBean) form;

    Billingreferral referral = new Billingreferral();

    lazyForm.set("referral", referral);

    return mapping.findForward("detail");
}