Package com.opensymphony.xwork

Source Code of com.opensymphony.xwork.ActionContext$ActionContextThreadLocal

package com.opensymphony.xwork;

import com.opensymphony.xwork.util.OgnlValueStack;

import java.io.Serializable;
import java.util.*;

///////////////Fix for JetSpeed/Tomcat////////////////
///////////////Add Serializable interface ////////////

/**
* We should get ActionContext object in all running scope.
* ActionContext must add Serializable interface, because
* processAction & doView in JetSpeed/Tomcat ware belong to two
* difference threads. We should use PortletSession as bridge to
* transfer PortletContext between these two threads.
* @author Revised by Henry Hu  -- hu_pengfei@yahoo.com.cn
* @since 2005-7-6
*/
public class ActionContext implements Serializable{

    static ThreadLocal actionContext = new ActionContextThreadLocal();

    public static final String ACTION_NAME = "com.opensymphony.xwork.ActionContext.name";

    public static final String VALUE_STACK = "com.opensymphony.xwork.util.OgnlValueStack.ValueStack";

    public static final String SESSION = "com.opensymphony.xwork.ActionContext.session";

    public static final String APPLICATION = "com.opensymphony.xwork.ActionContext.application";

    public static final String PARAMETERS = "com.opensymphony.xwork.ActionContext.parameters";

    public static final String LOCALE = "com.opensymphony.xwork.ActionContext.locale";

    public static final String TYPE_CONVERTER = "com.opensymphony.xwork.ActionContext.typeConverter";

    public static final String ACTION_INVOCATION = "com.opensymphony.xwork.ActionContext.actionInvocation";

    public static final String CONVERSION_ERRORS = "com.opensymphony.xwork.ActionContext.conversionErrors";

    Map context;

    private static class ActionContextThreadLocal extends ThreadLocal {

        protected Object initialValue() {
            OgnlValueStack vs = new OgnlValueStack();
            return new ActionContext(vs.getContext());
        }

        private ActionContextThreadLocal() {
        }

    }

    public ActionContext(Map context) {
        this.context = context;
    }

    public void setActionInvocation(ActionInvocation actionInvocation) {
        put("com.opensymphony.xwork.ActionContext.actionInvocation", actionInvocation);
    }

    public ActionInvocation getActionInvocation() {
        return (ActionInvocation) get("com.opensymphony.xwork.ActionContext.actionInvocation");
    }

    public void setApplication(Map application) {
        put("com.opensymphony.xwork.ActionContext.application", application);
    }

    public Map getApplication() {
        return (Map) get("com.opensymphony.xwork.ActionContext.application");
    }

    public static void setContext(ActionContext context) {
        actionContext.set(context);
    }

    public static ActionContext getContext() {
        ActionContext context = (ActionContext) actionContext.get();
        if (context == null) {
            OgnlValueStack vs = new OgnlValueStack();
            context = new ActionContext(vs.getContext());
            setContext(context);
        }
        return context;
    }

    public void setContextMap(Map contextMap) {
        getContext().context = contextMap;
    }

    public Map getContextMap() {
        return context;
    }

    public void setConversionErrors(Map conversionErrors) {
        put("com.opensymphony.xwork.ActionContext.conversionErrors", conversionErrors);
    }

    public Map getConversionErrors() {
        Map errors = (Map) get("com.opensymphony.xwork.ActionContext.conversionErrors");
        if (errors == null) {
            errors = new HashMap();
            setConversionErrors(errors);
        }
        return errors;
    }

    public void setLocale(Locale locale) {
        put("com.opensymphony.xwork.ActionContext.locale", locale);
    }

    public Locale getLocale() {
        Locale locale = (Locale) get("com.opensymphony.xwork.ActionContext.locale");
        if (locale == null) {
            locale = Locale.getDefault();
            setLocale(locale);
        }
        return locale;
    }

    public void setName(String name) {
        put("com.opensymphony.xwork.ActionContext.name", name);
    }

    public String getName() {
        return (String) get("com.opensymphony.xwork.ActionContext.name");
    }

    public void setParameters(Map parameters) {
        put("com.opensymphony.xwork.ActionContext.parameters", parameters);
    }

    public Map getParameters() {
        return (Map) get("com.opensymphony.xwork.ActionContext.parameters");
    }

    public void setSession(Map session) {
        put("com.opensymphony.xwork.ActionContext.session", session);
    }

    public Map getSession() {
        return (Map) get("com.opensymphony.xwork.ActionContext.session");
    }

    public void setValueStack(OgnlValueStack stack) {
        put("com.opensymphony.xwork.util.OgnlValueStack.ValueStack", stack);
    }

    public OgnlValueStack getValueStack() {
        return (OgnlValueStack) get("com.opensymphony.xwork.util.OgnlValueStack.ValueStack");
    }

    public Object get(Object key) {
        return context.get(key);
    }

    public void put(Object key, Object value) {
        context.put(key, value);
    }

}

TOP

Related Classes of com.opensymphony.xwork.ActionContext$ActionContextThreadLocal

TOP
Copyright © 2018 www.massapi.com. 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.