net.sourceforge.stripes.controller
Class DispatcherServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by net.sourceforge.stripes.controller.DispatcherServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class DispatcherServlet
extends HttpServlet

Servlet that controls how requests to the Stripes framework are processed. Uses an instance of the ActionResolver interface to locate the bean and method used to handle the current request and then delegates processing to the bean.

While the DispatcherServlet is structured so that it can be easily subclassed and overridden much of the processing work is delegated to the DispatcherHelper class.

Author:
Tim Fennell
See Also:
Serialized Form

Field Summary
static String RUN_CUSTOM_VALIDATION_WHEN_ERRORS
          Configuration key used to lookup up a property that determines whether or not beans' custom validate() method gets invoked when validation errors are generated during the binding process
 
Constructor Summary
DispatcherServlet()
           
 
Method Summary
protected  Resolution doBindingAndValidation(ExecutionContext ctx)
          Responsible for executing binding and validation for the current request.
protected  Resolution doCustomValidation(ExecutionContext ctx)
          Responsible for executing custom validation methods for the current request.
protected  void executeResolution(ExecutionContext ctx, Resolution resolution)
          Responsible for executing the Resolution for the current request.
protected  Stack<ActionBean> getActionBeanStack(HttpServletRequest request, boolean create)
          Fetches, and lazily creates if required, a Stack in the request to store ActionBeans should the current request involve forwards or includes to other ActionBeans.
protected  Resolution handleValidationErrors(ExecutionContext ctx)
          Responsible for handling any validation errors that arise during validation.
protected  Resolution invokeEventHandler(ExecutionContext ctx)
          Responsible for invoking the event handler if no validation errors occur.
protected  Resolution resolveActionBean(ExecutionContext ctx)
          Responsible for resolving the ActionBean for the current request.
protected  Resolution resolveHandler(ExecutionContext ctx)
          Responsible for resolving the event handler method for the current request.
protected  void restoreActionBean(HttpServletRequest request)
          Restores the previous value of the 'actionBean' attribute in the request.
protected  void saveActionBean(HttpServletRequest request)
          Saves the current value of the 'actionBean' attribute in the request so that it can be restored at a later date by calling restoreActionBean(HttpServletRequest).
protected  void service(HttpServletRequest request, HttpServletResponse response)
          Invokes the following instance level methods in order to coordinate the processing of requests:
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RUN_CUSTOM_VALIDATION_WHEN_ERRORS

public static final String RUN_CUSTOM_VALIDATION_WHEN_ERRORS
Configuration key used to lookup up a property that determines whether or not beans' custom validate() method gets invoked when validation errors are generated during the binding process

See Also:
Constant Field Values
Constructor Detail

DispatcherServlet

public DispatcherServlet()
Method Detail

service

protected void service(HttpServletRequest request,
                       HttpServletResponse response)
                throws ServletException

Invokes the following instance level methods in order to coordinate the processing of requests:

If any of the above methods return a Resolution the rest of the request processing is aborted and the resolution is executed.

Overrides:
service in class HttpServlet
Parameters:
request - the HttpServletRequest handed to the class by the container
response - the HttpServletResponse paired to the request
Throws:
ServletException - thrown when the system fails to process the request in any way

resolveActionBean

protected Resolution resolveActionBean(ExecutionContext ctx)
                                throws Exception
Responsible for resolving the ActionBean for the current request. Delegates to DispatcherHelper.resolveActionBean(ExecutionContext).

Throws:
Exception

resolveHandler

protected Resolution resolveHandler(ExecutionContext ctx)
                             throws Exception
Responsible for resolving the event handler method for the current request. Delegates to DispatcherHelper.resolveHandler(ExecutionContext).

Throws:
Exception

doBindingAndValidation

protected Resolution doBindingAndValidation(ExecutionContext ctx)
                                     throws Exception
Responsible for executing binding and validation for the current request. Delegates to DispatcherHelper.doBindingAndValidation(ExecutionContext, boolean).

Throws:
Exception

doCustomValidation

protected Resolution doCustomValidation(ExecutionContext ctx)
                                 throws Exception
Responsible for executing custom validation methods for the current request. Delegates to DispatcherHelper.doCustomValidation(ExecutionContext, boolean).

Throws:
Exception

handleValidationErrors

protected Resolution handleValidationErrors(ExecutionContext ctx)
                                     throws Exception
Responsible for handling any validation errors that arise during validation. Delegates to DispatcherHelper.handleValidationErrors(ExecutionContext).

Throws:
Exception

invokeEventHandler

protected Resolution invokeEventHandler(ExecutionContext ctx)
                                 throws Exception
Responsible for invoking the event handler if no validation errors occur. Delegates to DispatcherHelper.invokeEventHandler(ExecutionContext).

Throws:
Exception

executeResolution

protected void executeResolution(ExecutionContext ctx,
                                 Resolution resolution)
                          throws Exception
Responsible for executing the Resolution for the current request. Delegates to DispatcherHelper.executeResolution(ExecutionContext, Resolution).

Throws:
Exception

getActionBeanStack

protected Stack<ActionBean> getActionBeanStack(HttpServletRequest request,
                                               boolean create)
Fetches, and lazily creates if required, a Stack in the request to store ActionBeans should the current request involve forwards or includes to other ActionBeans.

Parameters:
request - the current HttpServletRequest
Returns:
the Stack if present, or if creation is requested

saveActionBean

protected void saveActionBean(HttpServletRequest request)
Saves the current value of the 'actionBean' attribute in the request so that it can be restored at a later date by calling restoreActionBean(HttpServletRequest). If no ActionBean is currently stored in the request, nothing is changed.

Parameters:
request - the current HttpServletRequest

restoreActionBean

protected void restoreActionBean(HttpServletRequest request)
Restores the previous value of the 'actionBean' attribute in the request. If no ActionBeans have been saved using saveActionBean(HttpServletRequest) then this method has no effect.

Parameters:
request - the current HttpServletRequest


? Copyright 2005-2006, Stripes Development Team.