Search in sources :

Example 1 with MutableDynaClass

use of org.apache.commons.beanutils.MutableDynaClass in project sonarqube by SonarSource.

the class FormBeanConfig method createActionForm.

// --------------------------------------------------------- Public Methods
/**
     * <p>Create and return an <code>ActionForm</code> instance appropriate to
     * the information in this <code>FormBeanConfig</code>.</p>
     *
     * <p>Although this method is not formally deprecated yet, where possible,
     * the form which accepts an <code>ActionContext</code> as an argument is
     * preferred, to help sever direct dependencies on the Servlet API.  As
     * the ActionContext becomes more familiar in Struts, this method will
     * almost certainly be deprecated.</p>
     *
     * @param servlet The action servlet
     * @return ActionForm instance
     * @throws IllegalAccessException if the Class or the appropriate
     *                                constructor is not accessible
     * @throws InstantiationException if this Class represents an abstract
     *                                class, an array class, a primitive type,
     *                                or void; or if instantiation fails for
     *                                some other reason
     */
public ActionForm createActionForm(ActionServlet servlet) throws IllegalAccessException, InstantiationException {
    Object obj = null;
    // Create a new form bean instance
    if (getDynamic()) {
        obj = getDynaActionFormClass().newInstance();
    } else {
        obj = formBeanClass().newInstance();
    }
    ActionForm form = null;
    if (obj instanceof ActionForm) {
        form = (ActionForm) obj;
    } else {
        form = new BeanValidatorForm(obj);
    }
    form.setServlet(servlet);
    if (form instanceof DynaBean && ((DynaBean) form).getDynaClass() instanceof MutableDynaClass) {
        DynaBean dynaBean = (DynaBean) form;
        MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass();
        // Add properties
        dynaClass.setRestricted(false);
        FormPropertyConfig[] props = findFormPropertyConfigs();
        for (int i = 0; i < props.length; i++) {
            dynaClass.add(props[i].getName(), props[i].getTypeClass());
            dynaBean.set(props[i].getName(), props[i].initial());
        }
        dynaClass.setRestricted(isRestricted());
    }
    if (form instanceof BeanValidatorForm) {
        ((BeanValidatorForm) form).initialize(this);
    }
    return form;
}
Also used : DynaBean(org.apache.commons.beanutils.DynaBean) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) BeanValidatorForm(org.apache.struts.validator.BeanValidatorForm) MutableDynaClass(org.apache.commons.beanutils.MutableDynaClass)

Aggregations

DynaBean (org.apache.commons.beanutils.DynaBean)1 MutableDynaClass (org.apache.commons.beanutils.MutableDynaClass)1 ActionForm (org.apache.struts.action.ActionForm)1 DynaActionForm (org.apache.struts.action.DynaActionForm)1 BeanValidatorForm (org.apache.struts.validator.BeanValidatorForm)1