java的actioncontext_【疑惑】ActionContext ac = ActionContext.getContext();?

java的actioncontext_【疑惑】ActionContext ac = ActionContext.getContext();?该楼层疑似违规已被系统折叠隐藏此楼查看此楼ActionContext.getContext()返回的是一个ActionContext对象,get(Stringkey)也是ActionContext里面的一个方法。xwork源码贴出来了:publicclassActionContextimplementsSerializable{staticThreadLocalactionCon…

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

ActionContext.getContext()返回的是一个ActionContext对象,get(String key)也是ActionContext里面的一个方法。

xwork源码贴出来了:

public class ActionContext implements Serializable {

static ThreadLocal actionContext = new ThreadLocal();

//public static final String DEV_MODE = “__devMode”;

public static final String ACTION_NAME = “com.opensymphony.xwork2.ActionContext.name”;

public static final String VALUE_STACK = ValueStack.VALUE_STACK;

public static final String SESSION = “com.opensymphony.xwork2.ActionContext.session”;

public static final String APPLICATION = “com.opensymphony.xwork2.ActionContext.application”;

public static final String PARAMETERS = “com.opensymphony.xwork2.ActionContext.parameters”;

public static final String LOCALE = “com.opensymphony.xwork2.ActionContext.locale”;

public static final String TYPE_CONVERTER = “com.opensymphony.xwork2.ActionContext.typeConverter”;

public static final String ACTION_INVOCATION = “com.opensymphony.xwork2.ActionContext.actionInvocation”;

public static final String CONVERSION_ERRORS = “com.opensymphony.xwork2.ActionContext.conversionErrors”;

public static final String CONTAINER = “com.opensymphony.xwork2.ActionContext.container”;

Map context;

public ActionContext(Map context) {

this.context = context;

}

public void setActionInvocation(ActionInvocation actionInvocation) {

put(ACTION_INVOCATION, actionInvocation);

}

public ActionInvocation getActionInvocation() {

return (ActionInvocation) get(ACTION_INVOCATION);

}

public void setApplication(Map application) {

put(APPLICATION, application);

}

public Map getApplication() {

return (Map) get(APPLICATION);

}

public static void setContext(ActionContext context) {

actionContext.set(context);

}

public static ActionContext getContext() {

return (ActionContext) actionContext.get();

// Don’t do lazy context creation, as it requires container; the creation of which may

// precede the context creation

//if (context == null) {

// ValueStack vs = ValueStackFactory.getFactory().createValueStack();

// context = new ActionContext(vs.getContext());

// setContext(context);

//}

}

public void setContextMap(Map contextMap) {

getContext().context = contextMap;

}

public Map getContextMap() {

return context;

}

public void setConversionErrors(Map conversionErrors) {

put(CONVERSION_ERRORS, conversionErrors);

}

public Map getConversionErrors() {

Map errors = (Map) get(CONVERSION_ERRORS);

if (errors == null) {

errors = new HashMap();

setConversionErrors(errors);

}

return errors;

}

public void setLocale(Locale locale) {

put(LOCALE, locale);

}

public Locale getLocale() {

Locale locale = (Locale) get(LOCALE);

if (locale == null) {

locale = Locale.getDefault();

setLocale(locale);

}

return locale;

}

public void setName(String name) {

put(ACTION_NAME, name);

}

public String getName() {

return (String) get(ACTION_NAME);

}

public void setParameters(Map parameters) {

put(PARAMETERS, parameters);

}

public Map getParameters() {

return (Map) get(PARAMETERS);

}

public void setSession(Map session) {

put(SESSION, session);

}

public Map getSession() {

return (Map) get(SESSION);

}

public void setValueStack(ValueStack stack) {

put(VALUE_STACK, stack);

}

public ValueStack getValueStack() {

return (ValueStack) get(VALUE_STACK);

}

public void setContainer(Container cont) {

put(CONTAINER, cont);

}

public Container getContainer() {

return (Container) get(CONTAINER);

}

public T getInstance(Class type) {

Container cont = getContainer();

if (cont != null) {

return cont.getInstance(type);

} else {

throw new XWorkException(“Cannot find an initialized container for this request.”);

}

}

public Object get(String key) {

return context.get(key);

}

public void put(String key, Object value) {

context.put(key, value);

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/37291.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注