Class ActionContextBase
- All Implemented Interfaces:
Map<String,
,Object> org.apache.commons.chain.Context
,ActionContext
- Direct Known Subclasses:
MockActionContext
,WebActionContext
Provide an abstract but semi-complete implementation of ActionContext to serve as the base for concrete implementations.
The abstract
methods to implement are the accessors for the named states,
getApplicationScope
, getRequestScope
, and
getSessionScope
.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
Provide the default context attribute under which to store the ActionMessage cache for errors.static final String
static final String
static final String
static final String
static final String
Provide the default context attribute under which to store the ActionMessage cache.static final String
static final String
protected TokenProcessor
Store the TokenProcessor instance for this Context.static final String
Provide the default context attribute under which to store the token key.static final String
Provide the default context attribute under which to store the transaction token key.static final String
Fields inherited from interface org.apache.struts.chain.contexts.ActionContext
APPLICATION_SCOPE, REQUEST_SCOPE, SESSION_SCOPE
-
Constructor Summary
ConstructorDescriptionInstantiate ActionContextBase, wrapping a default ContextBase instance.ActionContextBase
(org.apache.commons.chain.Context context) Instantiate ActionContextBase, wrapping the given Context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addActionMessages
(String key, ActionMessages messages) Add the given messages to a cache stored in this Context, under key.void
addErrors
(ActionMessages errors) Append the given errors keys to an internal cache, creating the cache if one is not already present.void
addMessages
(ActionMessages messages) Append the given messages keys to an internal cache, creating the cache if one is not already present.findOrCreateActionForm
(String formName, String scopeName) Using thisActionContext
's defaultModuleConfig
, return an existingActionForm
in the specified scope, or create a new one and add it to the specified scope.findOrCreateActionForm
(String formName, String scopeName, ModuleConfig moduleConfig) In the context of the givenModuleConfig
and thisActionContext
, look for an existingActionForm
in the specified scope.Generate a new transaction token, to be used for enforcing a single request for a particular transaction.Get the action which has been identified to be executed as part of processing this request.Get the ActionConfig which contains the details for processing this request.Get the ActionForm instance which will carry any data submitted as part of this request.Return aMap
of Application scoped values.Indicate if the "cancel event" state is set for for this context,Retrieve error messages from an internal cache, creating an empty cache if one is not already present.Retrieve an exception which may have been caught by some code using this ActionContext, usually by an exception handler.Is the ActionForm for this context valid? This method does not actually perform form validation.Get the ForwardConfig which has been identified as the basis for view-processing.Get the include path which should be processed as part of processing this request.Return the user's currently selected Locale.org.slf4j.Logger
Provide the currently configured commons-loggingLog
instance.Return the default message resources for the current module.Return the specified message resources for the current module.Retrieve messages from an internal cache, creating an empty cache if one is not already present.Get the ModuleConfig which is operative for the current request.Return aMap
of request scoped values.Return the Map representing the scope identified byscopeName
.Return aMap
of Session scoped values.protected String
boolean
Indicate whether a transaction token for this context is valid.boolean
isTokenValid
(boolean reset) Indicate whether a transaction token is stored in the "session" scope for this context, optionally clearing the token, so that the next check would return false.void
release()
Signal to the instance that it will not be used any more, so that any resources which should be cleaned up can be cleaned up.void
Clear any transactional token stored in the "session" scope for this context, so that the next check would return false.void
saveActionMessages
(String scopeId, String key, ActionMessages messages) Save the givenmessages
into the map identified by the givenscopeId
under the givenkey
.void
saveActionMessages
(String key, ActionMessages messages) Save the given ActionMessages into the request scope under the given key, clearing the attribute if the messages are empty or null.void
saveErrors
(ActionMessages errors) Save the given error messages to the internal cache, clearing any previous messages in the cache.void
saveMessages
(String scope, ActionMessages messages) Adapt a legacy form of SaveMessages to the ActionContext API by storing the ActoinMessages under the default scope.void
saveMessages
(ActionMessages messages) Save the given messages to the internal cache, clearing any previous messages in the cache.void
Save a new transaction token in the "session" scope for this context, creating new resources, if needed.void
Set the action which has been identified to be executed as part of processing this request.void
setActionConfig
(ActionConfig config) Set the ActionConfig class contains the details for processing this request.void
setActionForm
(ActionForm form) Set the ActionForm instance which will carry any data submitted as part of this request.void
setCancelled
(Boolean cancelled) Set the "cancel event" state for this context.void
Store an exception in this context for use by other handling code.void
setFormValid
(Boolean valid) Store the result of the validation of the Context's ActionForm.void
setForwardConfig
(ForwardConfig forward) Set the ForwardConfig which should be used as the basis of the view segment of the overall processing.void
setInclude
(String include) Set the include path which should be processed as part of processing this request.void
Set the user's currently selectedLocale
.void
setLogger
(org.slf4j.Logger logger) Set the slf4jLogger
instance which should be used to LOG messages.void
setMessageResources
(MessageResources messageResources) Set the default message resources for the current module.void
setModuleConfig
(ModuleConfig config) Set the ModuleConfig which is operative for the current request.Methods inherited from class org.apache.struts.chain.contexts.ContextWrapper
clear, containsKey, containsValue, entrySet, get, getBaseContext, isEmpty, keySet, put, putAll, remove, size, values
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.struts.chain.contexts.ActionContext
getParameterMap
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Field Details
-
ACTION_KEY
- See Also:
-
ACTION_CONFIG_KEY
- See Also:
-
ACTION_FORM_KEY
- See Also:
-
FORWARD_CONFIG_KEY
- See Also:
-
MODULE_CONFIG_KEY
- See Also:
-
EXCEPTION_KEY
- See Also:
-
ERROR_ACTION_MESSAGES_KEY
Provide the default context attribute under which to store the ActionMessage cache for errors.- See Also:
-
MESSAGE_ACTION_MESSAGES_KEY
Provide the default context attribute under which to store the ActionMessage cache.- See Also:
-
MESSAGE_RESOURCES_KEY
- See Also:
-
INCLUDE_KEY
- See Also:
-
LOCALE_KEY
- See Also:
-
CANCEL_KEY
- See Also:
-
VALID_KEY
- See Also:
-
TRANSACTION_TOKEN_KEY
Provide the default context attribute under which to store the transaction token key.- See Also:
-
TOKEN_KEY
Provide the default context attribute under which to store the token key.- See Also:
-
token
Store the TokenProcessor instance for this Context.
-
-
Constructor Details
-
ActionContextBase
public ActionContextBase(org.apache.commons.chain.Context context) Instantiate ActionContextBase, wrapping the given Context.- Parameters:
context
- Context to wrap
-
ActionContextBase
public ActionContextBase()Instantiate ActionContextBase, wrapping a default ContextBase instance.
-
-
Method Details
-
release
public void release()Description copied from interface:ActionContext
Signal to the instance that it will not be used any more, so that any resources which should be cleaned up can be cleaned up.- Specified by:
release
in interfaceActionContext
-
getApplicationScope
Description copied from interface:ActionContext
Return a
Map
of Application scoped values.This is implemented in analogy with the Application scope in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "application scope" is an implementation detail left unspecified by Struts.
- Specified by:
getApplicationScope
in interfaceActionContext
- Returns:
- A Map of "application scope" attributes.
-
getRequestScope
Description copied from interface:ActionContext
Return a
Map
of request scoped values. A request is understood as the fundamental motivation for any particular instance of anActionContext
.This is implemented in analogy with the Request Context in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "request scope" is an implementation detail left unspecified by Struts.
- Specified by:
getRequestScope
in interfaceActionContext
- Returns:
- a Map of "request scope" attributes.
-
getSessionScope
Description copied from interface:ActionContext
Return a
Map
of Session scoped values. A session is understood as a sequence of requests made by the same user.This is implemented in analogy with the Session scope in the Servlet API, but it seems reasonable to expect that any Struts implementation will have an equivalent concept.
The ultimate meaning of "session scope" is an implementation detail left unspecified by Struts.
- Specified by:
getSessionScope
in interfaceActionContext
- Returns:
- A Map of "session scope" attributes.
-
getScope
Description copied from interface:ActionContext
Return the Map representing the scope identified byscopeName
. Implementations should support at minimum the names associated with the constantsAPPLICATION_SCOPE
,SESSION_SCOPE
, andREQUEST_SCOPE
, but are permitted to support others as well.- Specified by:
getScope
in interfaceActionContext
- Parameters:
scopeName
- A token identifying a scope, including but not limited toAPPLICATION_SCOPE
,SESSION_SCOPE
,REQUEST_SCOPE
.- Returns:
- A Map of attributes for the specified scope.
-
setAction
Description copied from interface:ActionContext
Set the action which has been identified to be executed as part of processing this request.
- Specified by:
setAction
in interfaceActionContext
- Parameters:
action
-
-
getAction
Description copied from interface:ActionContext
Get the action which has been identified to be executed as part of processing this request.
- Specified by:
getAction
in interfaceActionContext
- Returns:
- The action to be executed with this request
-
setActionForm
Description copied from interface:ActionContext
Set the ActionForm instance which will carry any data submitted as part of this request.
- Specified by:
setActionForm
in interfaceActionContext
- Parameters:
form
- The ActionForm instance to use with this request
-
getActionForm
Description copied from interface:ActionContext
Get the ActionForm instance which will carry any data submitted as part of this request.
- Specified by:
getActionForm
in interfaceActionContext
- Returns:
- The ActionForm being used with this request
-
setActionConfig
Description copied from interface:ActionContext
Set the ActionConfig class contains the details for processing this request.
- Specified by:
setActionConfig
in interfaceActionContext
- Parameters:
config
- The ActionConfig class to use with this request
-
getActionConfig
Description copied from interface:ActionContext
Get the ActionConfig which contains the details for processing this request.
- Specified by:
getActionConfig
in interfaceActionContext
- Returns:
- The ActionConfig class being used with this request
-
setForwardConfig
Description copied from interface:ActionContext
Set the ForwardConfig which should be used as the basis of the view segment of the overall processing. This is the primary method of "communication" with the "view" sub-chain.
- Specified by:
setForwardConfig
in interfaceActionContext
- Parameters:
forward
- The ForwardConfig to use with this request
-
getForwardConfig
Description copied from interface:ActionContext
Get the ForwardConfig which has been identified as the basis for view-processing.
- Specified by:
getForwardConfig
in interfaceActionContext
- Returns:
- The ForwardConfig being used with this request
-
setInclude
Description copied from interface:ActionContext
Set the include path which should be processed as part of processing this request.
- Specified by:
setInclude
in interfaceActionContext
- Parameters:
include
- The include path to be used with this request
-
getInclude
Description copied from interface:ActionContext
Get the include path which should be processed as part of processing this request.
- Specified by:
getInclude
in interfaceActionContext
- Returns:
- The include path being used with this request
-
getFormValid
Description copied from interface:ActionContext
Is the ActionForm for this context valid? This method does not actually perform form validation. It is simply a holder property where processes which perform validation can store the results of the validation for other processes' benefit.
- Specified by:
getFormValid
in interfaceActionContext
- Returns:
Boolean.TRUE
if the form passed validation;Boolean.FALSE
if the form failed validation; null if the form has not yet been validated
-
setFormValid
Description copied from interface:ActionContext
Store the result of the validation of the Context's ActionForm.
- Specified by:
setFormValid
in interfaceActionContext
- Parameters:
valid
- Whether the ActionForm for this request passes validation
-
getModuleConfig
Description copied from interface:ActionContext
Get the ModuleConfig which is operative for the current request.
- Specified by:
getModuleConfig
in interfaceActionContext
- Returns:
- The MooduleConfig being used with this request
-
setModuleConfig
Description copied from interface:ActionContext
Set the ModuleConfig which is operative for the current request.
- Specified by:
setModuleConfig
in interfaceActionContext
- Parameters:
config
- The ModuleConfig to be used with this request
-
getException
Description copied from interface:ActionContext
Retrieve an exception which may have been caught by some code using this ActionContext, usually by an exception handler.
- Specified by:
getException
in interfaceActionContext
- Returns:
- Any exception that may have been caught by this ActionContext
-
setException
Description copied from interface:ActionContext
Store an exception in this context for use by other handling code.
- Specified by:
setException
in interfaceActionContext
- Parameters:
e
- An exception to be stored for handling by another member
-
addMessages
Description copied from interface:ActionContext
Append the given messages keys to an internal cache, creating the cache if one is not already present.
- Specified by:
addMessages
in interfaceActionContext
- Parameters:
messages
- New ActionMessages to cache
-
addErrors
Description copied from interface:ActionContext
Append the given errors keys to an internal cache, creating the cache if one is not already present.
- Specified by:
addErrors
in interfaceActionContext
- Parameters:
errors
- New ActionMessages to cache as errors
-
getErrors
Description copied from interface:ActionContext
Retrieve error messages from an internal cache, creating an empty cache if one is not already present.
- Specified by:
getErrors
in interfaceActionContext
- Returns:
- The ActionMessage cache for errors
-
getMessages
Description copied from interface:ActionContext
Retrieve messages from an internal cache, creating an empty cache if one is not already present.
- Specified by:
getMessages
in interfaceActionContext
- Returns:
- The ActionMessage cache for errors
-
saveErrors
Description copied from interface:ActionContext
Save the given error messages to the internal cache, clearing any previous messages in the cache.
If the parameter is null or empty, the internal cache is removed.
- Specified by:
saveErrors
in interfaceActionContext
- Parameters:
errors
- ActionMesssages to cache as errors
-
saveMessages
Description copied from interface:ActionContext
Save the given messages to the internal cache, clearing any previous messages in the cache.
If the parameter is null or empty, the internal cache is removed.
- Specified by:
saveMessages
in interfaceActionContext
- Parameters:
messages
- ActionMesssages to cache
-
addActionMessages
Add the given messages to a cache stored in this Context, under key.
- Parameters:
key
- The attribute name for the message cachemessages
- The ActionMessages to add
-
saveActionMessages
Save the given ActionMessages into the request scope under the given key, clearing the attribute if the messages are empty or null.
- Parameters:
key
- The attribute name for the message cachemessages
- The ActionMessages to add
-
saveActionMessages
Save the given
messages
into the map identified by the givenscopeId
under the givenkey
.- Parameters:
scopeId
-key
-messages
-
-
saveMessages
Adapt a legacy form of SaveMessages to the ActionContext API by storing the ActoinMessages under the default scope.
- Specified by:
saveMessages
in interfaceActionContext
- Parameters:
scope
- The scope for the internal cachemessages
- ActionMesssages to cache
-
saveToken
public void saveToken()Description copied from interface:ActionContext
Save a new transaction token in the "session" scope for this context, creating new resources, if needed.
- Specified by:
saveToken
in interfaceActionContext
-
generateToken
Description copied from interface:ActionContext
Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
- Specified by:
generateToken
in interfaceActionContext
-
getTokenGeneratorId
-
isTokenValid
public boolean isTokenValid()Description copied from interface:ActionContext
Indicate whether a transaction token for this context is valid.
A typical implementation will place a transaction token in the session" scope Map and a matching value in the "parameter" Map. If the "session" token does not match the "parameter" attribute, or the session token is missing, then the transactional token is deemed invalid.
- Specified by:
isTokenValid
in interfaceActionContext
-
isTokenValid
public boolean isTokenValid(boolean reset) Description copied from interface:ActionContext
Indicate whether a transaction token is stored in the "session" scope for this context, optionally clearing the token, so that the next check would return false.
- Specified by:
isTokenValid
in interfaceActionContext
- Parameters:
reset
- On true, clear the transactional token
-
resetToken
public void resetToken()Description copied from interface:ActionContext
Clear any transactional token stored in the "session" scope for this context, so that the next check would return false.
- Specified by:
resetToken
in interfaceActionContext
-
getCancelled
Description copied from interface:ActionContext
Indicate if the "cancel event" state is set for for this context,- Specified by:
getCancelled
in interfaceActionContext
- See Also:
-
setCancelled
Description copied from interface:ActionContext
Set the "cancel event" state for this context.- Specified by:
setCancelled
in interfaceActionContext
- Parameters:
cancelled
- On true, set the cancel event state to true. On false, set the cancel event state to false.- See Also:
-
setMessageResources
Description copied from interface:ActionContext
Set the default message resources for the current module.
- Specified by:
setMessageResources
in interfaceActionContext
-
getMessageResources
Description copied from interface:ActionContext
Return the default message resources for the current module.
- Specified by:
getMessageResources
in interfaceActionContext
-
getMessageResources
Description copied from interface:ActionContext
Return the specified message resources for the current module.
- Specified by:
getMessageResources
in interfaceActionContext
- Parameters:
key
- The key specified in the<message-resources>
element for the requested bundle
-
setLocale
Description copied from interface:ActionContext
Set the user's currently selected
Locale
.- Specified by:
setLocale
in interfaceActionContext
- Parameters:
locale
- The user's selected Locale to be set, or null to select the server's default Locale
-
getLocale
Description copied from interface:ActionContext
Return the user's currently selected Locale.
- Specified by:
getLocale
in interfaceActionContext
-
getLogger
public org.slf4j.Logger getLogger()Provide the currently configured commons-logging
Log
instance.- Returns:
- Logger instance for this context
-
setLogger
public void setLogger(org.slf4j.Logger logger) Set the slf4jLogger
instance which should be used to LOG messages. This is initialized at instantiation time but may be overridden. Be advised not to set the value to null, asActionContextBase
uses the logger for some of its own operations.- Parameters:
logger
- instance for this context
-
findOrCreateActionForm
public ActionForm findOrCreateActionForm(String formName, String scopeName) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException Using thisActionContext
's defaultModuleConfig
, return an existingActionForm
in the specified scope, or create a new one and add it to the specified scope.- Parameters:
formName
- The name attribute of our ActionFormscopeName
- The scope identifier (request, session)- Returns:
- The ActionForm for this request
- Throws:
InstantiationException
- If object cannot be createdIllegalAccessException
- If object cannot be createdIllegalArgumentException
- If form config is missing from module or scopeName is invalidInvocationTargetException
- if the underlying constructor throws an exceptionNoSuchMethodException
- if a matching method is not foundSecurityException
- if there is a security-exceptionClassNotFoundException
- if the specified class cannot be loaded- See Also:
-
findOrCreateActionForm
public ActionForm findOrCreateActionForm(String formName, String scopeName, ModuleConfig moduleConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException In the context of the givenModuleConfig
and thisActionContext
, look for an existingActionForm
in the specified scope. If one is found, return it; otherwise, create a new instance, add it to that scope, and then return it.- Parameters:
formName
- The name attribute of our ActionFormscopeName
- The scope identier (request, session)- Returns:
- The ActionForm for this request
- Throws:
InstantiationException
- If object cannot be createdIllegalAccessException
- If object cannot be createdIllegalArgumentException
- If form config is missing from module or scopeName is invalidInvocationTargetException
- if the underlying constructor throws an exceptionNoSuchMethodException
- if a matching method is not foundSecurityException
- if there is a security-exceptionClassNotFoundException
- if the specified class cannot be loaded
-