Package org.apache.commons.chain.web

Examples of org.apache.commons.chain.web.WebContext


    public boolean execute(Context context) throws Exception {

        count++;
        log.info("Executing: " + attribute + "=" + count);

        WebContext webContext = (WebContext)context;
        webContext.getSessionScope().put(attribute, new Integer(count));

        return false;

    }
View Full Code Here


     * @return <code>true</code> so that processing completes
     */
    public boolean execute(Context context) throws Exception {

        // Retrieve module config instance
        WebContext wcontext = (WebContext) context;
        ModuleConfig moduleConfig = (ModuleConfig)
            wcontext.get(getModuleConfigKey());
       
        // Is there an include to be performed?
        String include = (String)
            context.get(getIncludeKey());
        if (include == null) {
View Full Code Here

            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);

View Full Code Here

     *  application module
     */
    protected synchronized Map getActions(Context context,
                                          ModuleConfig moduleConfig) {

        WebContext wcontext = (WebContext) context;
        String actionsKey = Constants.ACTIONS_KEY + moduleConfig.getPrefix();
        Map actions = (Map) wcontext.getApplicationScope().get(actionsKey);
        if (actions == null) {
            actions = new HashMap();
            wcontext.getApplicationScope().put(actionKey, actions);
        }
        return (actions);

    }
View Full Code Here

     * @return <code>false</code> so that processing continues
     */
    public boolean execute(Context context) throws Exception {

        // Retrieve the ModuleConfig instance
        WebContext wcontext = (WebContext) context;
        ModuleConfig moduleConfig = (ModuleConfig)
            wcontext.get(getModuleConfigKey());
           
        // If the module is configured for no caching, request no caching   
        if (moduleConfig.getControllerConfig().getNocache()) {
            requestNoCache(context);
        }
View Full Code Here

     */
    protected void populate(Context context,
                            ActionConfig actionConfig,
                            ActionForm actionForm) throws Exception
    {
        WebContext wcontext = (WebContext) context;
        Map paramValues = wcontext.getParamValues();
        Map parameters = new HashMap();

        String prefix = actionConfig.getPrefix();
        String suffix = actionConfig.getSuffix();

View Full Code Here

    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 {
            context.put(getCancelKey(), Boolean.FALSE);
        }
    }
View Full Code Here

        // 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);
View Full Code Here

     * @return <code>false</code> so that processing continues
     */
    public boolean execute(Context context) throws Exception {

        // Retrieve the ModuleConfig instance
        WebContext wcontext = (WebContext) context;
        ModuleConfig moduleConfig = (ModuleConfig)
            wcontext.get(getModuleConfigKey());
           
        // If the content type is configured, set it for the response
        String contentType =
            moduleConfig.getControllerConfig().getContentType();
        if (contentType != null) {
View Full Code Here

        // 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);

    }
View Full Code Here

TOP

Related Classes of org.apache.commons.chain.web.WebContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.