Example usage for org.apache.commons.chain.web WebContext getRequestScope

List of usage examples for org.apache.commons.chain.web WebContext getRequestScope

Introduction

In this page you can find the example usage for org.apache.commons.chain.web WebContext getRequestScope.

Prototype

public abstract Map getRequestScope();

Source Link

Document

Return a mutable Map that maps request scope attribute names to their values.

Usage

From source file:org.apache.struts.chain.AbstractPopulateActionForm.java

protected void handleCancel(Context context, ActionConfig actionConfig, ActionForm actionForm)
        throws Exception {
    WebContext wcontext = (WebContext) context;
    Map paramValues = wcontext.getParamValues();

    // Set the cancellation attribute if appropriate
    if ((paramValues.get(org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY) != null)
            || (paramValues.get(org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY_X) != null)) {
        context.put(getCancelKey(), Boolean.TRUE);
        wcontext.getRequestScope().put(Globals.CANCEL_KEY, Boolean.TRUE);
    } else {//from ww  w .  j  a  v  a2 s . com
        context.put(getCancelKey(), Boolean.FALSE);
    }
}

From source file:org.apache.struts.chain.AbstractSelectAction.java

/**
 * <p>Cache the <code>ActionConfig</code> instance for the
 * action to be used for processing this request.</p>
 *
 * @param context The <code>Context</code> for the current request
 *
 * @exception IllegalArgumentException if no valid
 *  action can be identified for this request
 *
 * @return <code>false</code> so that processing continues
 *///from w  w  w.j  av  a2  s . co m
public boolean execute(Context context) throws Exception {

    // Identify the matching path for this request
    String path = getPath(context);

    // Cache the corresponding ActonConfig instance
    WebContext wcontext = (WebContext) context;
    ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey());
    ActionConfig actionConfig = moduleConfig.findActionConfig(path);

    if (actionConfig == null) {
        // Locate the mapping for unknown paths (if any)
        ActionConfig configs[] = moduleConfig.findActionConfigs();
        for (int i = 0; i < configs.length; i++) {
            if (configs[i].getUnknown()) {
                actionConfig = configs[i];
                break;
            }
        }

    }

    if (actionConfig == null) {
        throw new IllegalArgumentException("No action config for '" + path + "'");
    }
    wcontext.put(getActionConfigKey(), actionConfig);
    wcontext.getRequestScope().put(Globals.MAPPING_KEY, actionConfig);
    return (false);

}

From source file:org.apache.struts.chain.AbstractSelectModule.java

/**
 * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
 * instances for the sub-application module to be used for processing
 * this request.</p>/*from   w w  w  .  j a  va 2s  .c o m*/
 *
 * @param context The <code>Context</code> for the current request
 *
 * @exception IllegalArgumentException if no valid
 *  ModuleConfig or MessageResources can be identified for this request
 *
 * @return <code>false</code> so that processing continues
 */
public boolean execute(Context context) throws Exception {

    // Identify the module prefix for the current module
    String prefix = getPrefix(context);

    // Cache the corresponding ModuleConfig and MessageResources instances
    WebContext wcontext = (WebContext) context;
    ModuleConfig moduleConfig = (ModuleConfig) wcontext.getApplicationScope().get(Globals.MODULE_KEY + prefix);
    if (moduleConfig == null) {
        throw new IllegalArgumentException("No module config for prefix '" + prefix + "'");
    }
    wcontext.put(getModuleConfigKey(), moduleConfig);
    wcontext.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
    MessageResources messageResources = (MessageResources) wcontext.getApplicationScope()
            .get(Globals.MESSAGES_KEY + prefix);
    if (messageResources != null) {
        wcontext.put(getMessageResourcesKey(), messageResources);
        wcontext.getRequestScope().put(Globals.MESSAGES_KEY, messageResources);
    }

    return (false);

}

From source file:org.apache.struts.chain.CreateActionForm.java

/**
 * <p>Create (if necessary) and cache a form bean for this request.</p>
 *
 * @param context The <code>Context</code> for the current request
 *
 * @return <code>false</code> so that processing continues
 *///from   w  w w  . java 2 s  .c  o  m
public boolean execute(Context context) throws Exception {

    // Is there a form bean associated with this ActionConfig?
    ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey());
    String name = actionConfig.getName();
    if (name == null) {
        context.remove(getActionFormKey());
        return (false);
    }

    log.trace("Look up form-bean " + name);

    // Look up the corresponding FormBeanConfig (if any)
    FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name);
    if (formBeanConfig == null) {
        log.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix()
                + " under name " + name);
        context.remove(getActionFormKey());
        return (false);
    }

    // Look up the session scope ActionForm instance (if any)
    WebContext wcontext = (WebContext) context;
    ActionForm instance = null;
    if ("session".equals(actionConfig.getScope())) {
        instance = (ActionForm) wcontext.getSessionScope().get(actionConfig.getAttribute());
    }

    // Can we recycle the existing instance (if any)?
    if (instance != null) {
        log.trace("Found an instance in the session; test for reusability");
        if (formBeanConfig.getDynamic()) {
            String className = ((DynaBean) instance).getDynaClass().getName();
            if (className.equals(formBeanConfig.getName())) {
                wcontext.put(getActionFormKey(), instance);
                /* It should already be in session scope
                if ("session".equals(actionConfig.getScope())) {
                wcontext.getSessionScope().put
                    (actionConfig.getAttribute(), instance);
                }
                */
                log.debug("Using existing instance (dynamic)");
                return (false);
            }
        } else {
            try {
                Class configClass = ClassUtils.getApplicationClass(formBeanConfig.getType());
                if (configClass.isAssignableFrom(instance.getClass())) {
                    wcontext.put(getActionFormKey(), instance);
                    /* It should already be in session scope
                       if ("session".equals(actionConfig.getScope())) {
                       wcontext.getSessionScope().put
                       (actionConfig.getAttribute(), instance);
                       }
                    */
                    log.debug("Using existing instance (non-dynamic)");
                    return (false);
                }
            } catch (Exception e) {
                log.debug("Error testing existing instance for reusability; just create a new instance", e);
            }
        }
    }

    log.trace("Make a new instance of: " + formBeanConfig);
    // Create a new form bean instance
    if (formBeanConfig.getDynamic()) {
        ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey());
        DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(formBeanConfig);
        instance = (ActionForm) dynaClass.newInstance();
        ((DynaActionForm) instance).initialize((ActionMapping) actionConfig);
    } else {
        instance = (ActionForm) ClassUtils.getApplicationInstance(formBeanConfig.getType());
    }

    // Configure and cache the new instance
    ActionServlet servlet = (ActionServlet) wcontext.get(getActionServletKey());
    instance.setServlet(servlet);
    wcontext.put(getActionFormKey(), instance);
    if ("session".equals(actionConfig.getScope())) {
        wcontext.getSessionScope().put(actionConfig.getAttribute(), instance);
    } else if ("request".equals(actionConfig.getScope())) {
        wcontext.getRequestScope().put(actionConfig.getAttribute(), instance);
    }

    return (false);

}