📄 actioncontextbase.java
字号:
/*
* $Id: ActionContextBase.java 471754 2006-11-06 14:55:09Z husted $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts.chain.contexts;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.impl.ContextBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.chain.Constants;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.TokenProcessor;
import java.util.Locale;
import java.util.Map;
/**
* <p> Provide an abstract but semi-complete implementation of ActionContext
* to serve as the base for concrete implementations. </p> <p> The abstract
* methods to implement are the accessors for the named states,
* <code>getApplicationScope</code>, <code>getRequestScope</code>, and
* <code>getSessionScope</code>. </p>
*/
public abstract class ActionContextBase extends ContextWrapper
implements ActionContext {
/**
* @see Constants.ACTION_KEY
*/
public static final String ACTION_KEY = Constants.ACTION_KEY;
/**
* @see
*/
public static final String ACTION_CONFIG_KEY = Constants.ACTION_CONFIG_KEY;
/**
* @see Constants.ACTION_FORM_KEY
*/
public static final String ACTION_FORM_KEY = Constants.ACTION_FORM_KEY;
/**
* @see Constants.FORWARD_CONFIG_KEY
*/
public static final String FORWARD_CONFIG_KEY =
Constants.FORWARD_CONFIG_KEY;
/**
* @see Constants.MODULE_CONFIG_KEY
*/
public static final String MODULE_CONFIG_KEY = Constants.MODULE_CONFIG_KEY;
/**
* @see Constants.EXCEPTION_KEY
*/
public static final String EXCEPTION_KEY = Constants.EXCEPTION_KEY;
/**
* <p> Provide the default context attribute under which to store the
* ActionMessage cache for errors. </p>
*/
public static final String ERROR_ACTION_MESSAGES_KEY = "errors";
/**
* <p> Provide the default context attribute under which to store the
* ActionMessage cache. </p>
*/
public static final String MESSAGE_ACTION_MESSAGES_KEY = "messages";
/**
* @see Constants.MESSAGE_RESOURCES_KEY
*/
public static final String MESSAGE_RESOURCES_KEY =
Constants.MESSAGE_RESOURCES_KEY;
/**
* @see Constants.INCLUDE_KEY
*/
public static final String INCLUDE_KEY = Constants.INCLUDE_KEY;
/**
* @see Constants.LOCALE_KEY
*/
public static final String LOCALE_KEY = Constants.LOCALE_KEY;
/**
* @see Constants.CANCEL_KEY
*/
public static final String CANCEL_KEY = Constants.CANCEL_KEY;
/**
* @see Constants.VALID_KEY
*/
public static final String VALID_KEY = Constants.VALID_KEY;
/**
* Provide the default context attribute under which to store the
* transaction token key.
*/
public static final String TRANSACTION_TOKEN_KEY = "TRANSACTION_TOKEN_KEY";
/**
* Provide the default context attribute under which to store the token
* key.
*/
public static final String TOKEN_KEY = "TOKEN_KEY";
/**
* Store the TokenProcessor instance for this Context.
*/
protected TokenProcessor token = null;
/**
* Store the Log instance for this Context.
*/
private Log logger = null;
/**
* Instantiate ActionContextBase, wrapping the given Context.
*
* @param context Context to wrap
*/
public ActionContextBase(Context context) {
super(context);
token = TokenProcessor.getInstance();
logger = LogFactory.getLog(this.getClass());
}
/**
* Instantiate ActionContextBase, wrapping a default ContextBase
* instance.
*/
public ActionContextBase() {
this(new ContextBase());
}
// -------------------------------
// General Application Support
// -------------------------------
public void release() {
this.token = null;
}
public abstract Map getApplicationScope();
public abstract Map getRequestScope();
public abstract Map getSessionScope();
public Map getScope(String scopeName) {
if (REQUEST_SCOPE.equals(scopeName)) {
return this.getRequestScope();
}
if (SESSION_SCOPE.equals(scopeName)) {
return this.getSessionScope();
}
if (APPLICATION_SCOPE.equals(scopeName)) {
return this.getApplicationScope();
}
throw new IllegalArgumentException("Invalid scope: " + scopeName);
}
// -------------------------------
// General Struts properties
// -------------------------------
public void setAction(Action action) {
this.put(ACTION_KEY, action);
}
public Action getAction() {
return (Action) this.get(ACTION_KEY);
}
public void setActionForm(ActionForm form) {
this.put(ACTION_FORM_KEY, form);
}
public ActionForm getActionForm() {
return (ActionForm) this.get(ACTION_FORM_KEY);
}
public void setActionConfig(ActionConfig config) {
this.put(ACTION_CONFIG_KEY, config);
}
public ActionConfig getActionConfig() {
return (ActionConfig) this.get(ACTION_CONFIG_KEY);
}
public void setForwardConfig(ForwardConfig forward) {
this.put(FORWARD_CONFIG_KEY, forward);
}
public ForwardConfig getForwardConfig() {
return (ForwardConfig) this.get(FORWARD_CONFIG_KEY);
}
public void setInclude(String include) {
this.put(INCLUDE_KEY, include);
}
public String getInclude() {
return (String) this.get(INCLUDE_KEY);
}
public Boolean getFormValid() {
return (Boolean) this.get(VALID_KEY);
}
public void setFormValid(Boolean valid) {
this.put(VALID_KEY, valid);
}
public ModuleConfig getModuleConfig() {
return (ModuleConfig) this.get(MODULE_CONFIG_KEY);
}
public void setModuleConfig(ModuleConfig config) {
this.put(MODULE_CONFIG_KEY, config);
}
public Exception getException() {
return (Exception) this.get(EXCEPTION_KEY);
}
public void setException(Exception e) {
this.put(EXCEPTION_KEY, e);
}
// -------------------------------
// ActionMessage Processing
// -------------------------------
public void addMessages(ActionMessages messages) {
this.addActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
}
public void addErrors(ActionMessages errors) {
this.addActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
}
public ActionMessages getErrors() {
return (ActionMessages) this.get(ERROR_ACTION_MESSAGES_KEY);
}
public ActionMessages getMessages() {
return (ActionMessages) this.get(MESSAGE_ACTION_MESSAGES_KEY);
}
public void saveErrors(ActionMessages errors) {
this.saveActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -