Class ActionContextBase

java.lang.Object
org.apache.struts.chain.contexts.ContextWrapper
org.apache.struts.chain.contexts.ActionContextBase
All Implemented Interfaces:
Map<String,Object>, Context, ActionContext
Direct Known Subclasses:
MockActionContext, WebActionContext

public abstract class ActionContextBase extends ContextWrapper implements ActionContext

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.

  • Field Details

  • Constructor Details

    • ActionContextBase

      public ActionContextBase(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 interface ActionContext
    • getApplicationScope

      public abstract Map<String,Object> 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 interface ActionContext
      Returns:
      A Map of "application scope" attributes.
    • getRequestScope

      public abstract Map<String,Object> 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 an ActionContext.

      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 interface ActionContext
      Returns:
      a Map of "request scope" attributes.
    • getSessionScope

      public abstract Map<String,Object> 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 interface ActionContext
      Returns:
      A Map of "session scope" attributes.
    • getScope

      public Map<String,Object> getScope(String scopeName)
      Description copied from interface: ActionContext
      Return the Map representing the scope identified by scopeName. Implementations should support at minimum the names associated with the constants APPLICATION_SCOPE, SESSION_SCOPE, and REQUEST_SCOPE, but are permitted to support others as well.
      Specified by:
      getScope in interface ActionContext
      Parameters:
      scopeName - A token identifying a scope, including but not limited to APPLICATION_SCOPE, SESSION_SCOPE, REQUEST_SCOPE.
      Returns:
      A Map of attributes for the specified scope.
    • setAction

      public void setAction(Action action)
      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 interface ActionContext
      Parameters:
      action -
    • getAction

      public 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 interface ActionContext
      Returns:
      The action to be executed with this request
    • setActionForm

      public void setActionForm(ActionForm form)
      Description copied from interface: ActionContext

      Set the ActionForm instance which will carry any data submitted as part of this request.

      Specified by:
      setActionForm in interface ActionContext
      Parameters:
      form - The ActionForm instance to use with this request
    • getActionForm

      public ActionForm 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 interface ActionContext
      Returns:
      The ActionForm being used with this request
    • setActionConfig

      public void setActionConfig(ActionConfig config)
      Description copied from interface: ActionContext

      Set the ActionConfig class contains the details for processing this request.

      Specified by:
      setActionConfig in interface ActionContext
      Parameters:
      config - The ActionConfig class to use with this request
    • getActionConfig

      public ActionConfig getActionConfig()
      Description copied from interface: ActionContext

      Get the ActionConfig which contains the details for processing this request.

      Specified by:
      getActionConfig in interface ActionContext
      Returns:
      The ActionConfig class being used with this request

    • setForwardConfig

      public void setForwardConfig(ForwardConfig forward)
      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 interface ActionContext
      Parameters:
      forward - The ForwardConfig to use with this request
    • getForwardConfig

      public ForwardConfig getForwardConfig()
      Description copied from interface: ActionContext

      Get the ForwardConfig which has been identified as the basis for view-processing.

      Specified by:
      getForwardConfig in interface ActionContext
      Returns:
      The ForwardConfig being used with this request
    • setInclude

      public void setInclude(String include)
      Description copied from interface: ActionContext

      Set the include path which should be processed as part of processing this request.

      Specified by:
      setInclude in interface ActionContext
      Parameters:
      include - The include path to be used with this request
    • getInclude

      public String getInclude()
      Description copied from interface: ActionContext

      Get the include path which should be processed as part of processing this request.

      Specified by:
      getInclude in interface ActionContext
      Returns:
      The include path being used with this request
    • getFormValid

      public Boolean 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 interface ActionContext
      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

      public void setFormValid(Boolean valid)
      Description copied from interface: ActionContext

      Store the result of the validation of the Context's ActionForm.

      Specified by:
      setFormValid in interface ActionContext
      Parameters:
      valid - Whether the ActionForm for this request passes validation
    • getModuleConfig

      public ModuleConfig getModuleConfig()
      Description copied from interface: ActionContext

      Get the ModuleConfig which is operative for the current request.

      Specified by:
      getModuleConfig in interface ActionContext
      Returns:
      The MooduleConfig being used with this request
    • setModuleConfig

      public void setModuleConfig(ModuleConfig config)
      Description copied from interface: ActionContext

      Set the ModuleConfig which is operative for the current request.

      Specified by:
      setModuleConfig in interface ActionContext
      Parameters:
      config - The ModuleConfig to be used with this request
    • getException

      public Exception 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 interface ActionContext
      Returns:
      Any exception that may have been caught by this ActionContext
    • setException

      public void setException(Exception e)
      Description copied from interface: ActionContext

      Store an exception in this context for use by other handling code.

      Specified by:
      setException in interface ActionContext
      Parameters:
      e - An exception to be stored for handling by another member
    • addMessages

      public void addMessages(ActionMessages messages)
      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 interface ActionContext
      Parameters:
      messages - New ActionMessages to cache
    • addErrors

      public void addErrors(ActionMessages errors)
      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 interface ActionContext
      Parameters:
      errors - New ActionMessages to cache as errors
    • getErrors

      public ActionMessages 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 interface ActionContext
      Returns:
      The ActionMessage cache for errors
    • getMessages

      public ActionMessages 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 interface ActionContext
      Returns:
      The ActionMessage cache for errors
    • saveErrors

      public void saveErrors(ActionMessages errors)
      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 interface ActionContext
      Parameters:
      errors - ActionMesssages to cache as errors
    • saveMessages

      public void saveMessages(ActionMessages messages)
      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 interface ActionContext
      Parameters:
      messages - ActionMesssages to cache
    • addActionMessages

      public void addActionMessages(String key, ActionMessages messages)

      Add the given messages to a cache stored in this Context, under key.

      Parameters:
      key - The attribute name for the message cache
      messages - The ActionMessages to add
    • saveActionMessages

      public 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.

      Parameters:
      key - The attribute name for the message cache
      messages - The ActionMessages to add
    • saveActionMessages

      public void saveActionMessages(String scopeId, String key, ActionMessages messages)

      Save the given messages into the map identified by the given scopeId under the given key.

      Parameters:
      scopeId -
      key -
      messages -
    • saveMessages

      public void saveMessages(String scope, ActionMessages messages)

      Adapt a legacy form of SaveMessages to the ActionContext API by storing the ActoinMessages under the default scope.

      Specified by:
      saveMessages in interface ActionContext
      Parameters:
      scope - The scope for the internal cache
      messages - 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 interface ActionContext
    • generateToken

      public String 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 interface ActionContext
    • getTokenGeneratorId

      protected String 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 interface ActionContext
    • 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 interface ActionContext
      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 interface ActionContext
    • getCancelled

      public Boolean getCancelled()
      Description copied from interface: ActionContext
      Indicate if the "cancel event" state is set for for this context,
      Specified by:
      getCancelled in interface ActionContext
      See Also:
    • setCancelled

      public void setCancelled(Boolean cancelled)
      Description copied from interface: ActionContext
      Set the "cancel event" state for this context.
      Specified by:
      setCancelled in interface ActionContext
      Parameters:
      cancelled - On true, set the cancel event state to true. On false, set the cancel event state to false.
      See Also:
    • setMessageResources

      public void setMessageResources(MessageResources messageResources)
      Description copied from interface: ActionContext

      Set the default message resources for the current module.

      Specified by:
      setMessageResources in interface ActionContext
    • getMessageResources

      public MessageResources getMessageResources()
      Description copied from interface: ActionContext

      Return the default message resources for the current module.

      Specified by:
      getMessageResources in interface ActionContext
    • getMessageResources

      public MessageResources getMessageResources(String key)
      Description copied from interface: ActionContext

      Return the specified message resources for the current module.

      Specified by:
      getMessageResources in interface ActionContext
      Parameters:
      key - The key specified in the <message-resources> element for the requested bundle
    • setLocale

      public void setLocale(Locale locale)
      Description copied from interface: ActionContext

      Set the user's currently selected Locale.

      Specified by:
      setLocale in interface ActionContext
      Parameters:
      locale - The user's selected Locale to be set, or null to select the server's default Locale
    • getLocale

      public Locale getLocale()
      Description copied from interface: ActionContext

      Return the user's currently selected Locale.

      Specified by:
      getLocale in interface ActionContext
    • getLogger

      public Logger getLogger()

      Provide the currently configured commons-logging Log instance.

      Returns:
      Logger instance for this context
    • setLogger

      public void setLogger(Logger logger)
      Set the slf4j Logger 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, as ActionContextBase uses the logger for some of its own operations.
      Parameters:
      logger - instance for this context
    • findOrCreateActionForm

      Using this ActionContext's default ModuleConfig, return an existing ActionForm in the specified scope, or create a new one and add it to the specified scope.
      Parameters:
      formName - The name attribute of our ActionForm
      scopeName - The scope identifier (request, session)
      Returns:
      The ActionForm for this request
      Throws:
      InstantiationException - If object cannot be created
      IllegalAccessException - If object cannot be created
      IllegalArgumentException - If form config is missing from module or scopeName is invalid
      InvocationTargetException - if the underlying constructor throws an exception
      NoSuchMethodException - if a matching method is not found
      SecurityException - if there is a security-exception
      ClassNotFoundException - if the specified class cannot be loaded
      See Also:
    • findOrCreateActionForm

      In the context of the given ModuleConfig and this ActionContext, look for an existing ActionForm 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 ActionForm
      scopeName - The scope identier (request, session)
      Returns:
      The ActionForm for this request
      Throws:
      InstantiationException - If object cannot be created
      IllegalAccessException - If object cannot be created
      IllegalArgumentException - If form config is missing from module or scopeName is invalid
      InvocationTargetException - if the underlying constructor throws an exception
      NoSuchMethodException - if a matching method is not found
      SecurityException - if there is a security-exception
      ClassNotFoundException - if the specified class cannot be loaded