net.sourceforge.stripes.controller
Class DispatcherHelper

java.lang.Object
  extended by net.sourceforge.stripes.controller.DispatcherHelper

public class DispatcherHelper
extends Object

Helper class that contains much of the logic used when dispatching requests in Stripes. Used primarily by the DispatcherSerlvet, but also by the UseActionBean tag.

Author:
Tim Fennell

Constructor Summary
DispatcherHelper()
           
 
Method Summary
static boolean applies(ValidationMethod info, String event)
          Determines if the ValidationMethod annotation should be applied to the named event.
static Resolution doBindingAndValidation(ExecutionContext ctx, boolean validate)
          Responsible for performing binding and validation.
static Resolution doCustomValidation(ExecutionContext ctx, boolean alwaysInvokeValidate)
          Responsible for coordinating the invocation of any custom validation logic exposed by the ActionBean.
static void executeResolution(ExecutionContext ctx, Resolution resolution)
          Responsible for executing the Resolution returned by the request.
static void fillInValidationErrors(ExecutionContext ctx)
          Makes sure that validation errors have all the necessary information to render themselves properly, including the UrlBinding of the action bean and the field value if it hasn't already been set.
static Method[] findCustomValidationMethods(Class<? extends ActionBean> type)
          Finds and returns all methods in the ActionBean class and it's superclasses that are marked with the ValidationMethod annotation and returns them ordered by priority (and alphabetically within priorities).
static PageContext getPageContext()
          Used by the validation subsystem to access a page context that can be used to create an expression evaluator for use in the expression validation code.
static Resolution handleValidationErrors(ExecutionContext ctx)
          Responsible for checking to see if validation errors exist and if so for handling them appropriately.
static Resolution invokeEventHandler(ExecutionContext ctx)
          Responsible for invoking the event handler identified.
static void logValidationErrors(ActionBeanContext context)
          Log validation errors at DEBUG to help during development.
static Resolution resolveActionBean(ExecutionContext ctx)
          Responsible for resolving the ActionBean for this request and setting it on the ExecutionContext.
static Resolution resolveHandler(ExecutionContext ctx)
          Responsible for resolving the event name for this request and setting it on the ActionBeanContext contained within the ExecutionContext.
static void setPageContext(PageContext ctx)
          Should be called prior to invoking validation related methods to provide the helper with access to a PageContext object that can be used to manufacture expression evaluator instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatcherHelper

public DispatcherHelper()
Method Detail

setPageContext

public static void setPageContext(PageContext ctx)
Should be called prior to invoking validation related methods to provide the helper with access to a PageContext object that can be used to manufacture expression evaluator instances.

Parameters:
ctx - a page context object supplied by the container

getPageContext

public static PageContext getPageContext()
Used by the validation subsystem to access a page context that can be used to create an expression evaluator for use in the expression validation code.

Returns:
a page context object if one was set with setPageContext()

resolveActionBean

public static Resolution resolveActionBean(ExecutionContext ctx)
                                    throws Exception
Responsible for resolving the ActionBean for this request and setting it on the ExecutionContext. If no ActionBean can be found the ActionResolver will throw an exception, thereby aborting the current request.

Parameters:
ctx - the ExecutionContext being used to process the current request
Returns:
a Resolution if any interceptor determines that the request processing should be aborted in favor of another Resolution, null otherwise.
Throws:
Exception

resolveHandler

public static Resolution resolveHandler(ExecutionContext ctx)
                                 throws Exception
Responsible for resolving the event name for this request and setting it on the ActionBeanContext contained within the ExecutionContext. Once the event name has been determined this method must resolve the handler method. If a handler method cannot be determined an exception should be thrown to abort processing.

Parameters:
ctx - the ExecutionContext being used to process the current request
Returns:
a Resolution if any interceptor determines that the request processing should be aborted in favor of another Resolution, null otherwise.
Throws:
Exception

doBindingAndValidation

public static Resolution doBindingAndValidation(ExecutionContext ctx,
                                                boolean validate)
                                         throws Exception
Responsible for performing binding and validation. Once properties have been bound and validation complete then they ValidationErrors object must be accessible through the ActionBeanContext contained within the ExecutionContext (regardless of whether any errors were generated or not).

Parameters:
ctx - the ExecutionContext being used to process the current request
Returns:
a Resolution if any interceptor determines that the request processing should be aborted in favor of another Resolution, null otherwise.
Throws:
Exception

doCustomValidation

public static Resolution doCustomValidation(ExecutionContext ctx,
                                            boolean alwaysInvokeValidate)
                                     throws Exception
Responsible for coordinating the invocation of any custom validation logic exposed by the ActionBean. Will only call the validation methods if certain conditions are met (there are no errors, or the always call validate flag is set etc.).

Parameters:
ctx - the ExecutionContext being used to process the current request
Returns:
a Resolution if any interceptor determines that the request processing should be aborted in favor of another Resolution, null otherwise.
Throws:
Exception

applies

public static boolean applies(ValidationMethod info,
                              String event)

Determines if the ValidationMethod annotation should be applied to the named event. True if the list of events to apply the validation to is empty, or it contains the event name, or it contains event names starting with "!" but not the event name. Some examples to illustrate the point

Parameters:
info - the ValidationMethod being examined
event - the event being processed
Returns:
true if the custom validation should be applied to this event, false otherwise

findCustomValidationMethods

public static Method[] findCustomValidationMethods(Class<? extends ActionBean> type)
                                            throws Exception
Finds and returns all methods in the ActionBean class and it's superclasses that are marked with the ValidationMethod annotation and returns them ordered by priority (and alphabetically within priorities). Looks first in an instance level cache, and if that does not contain information for an ActionBean, examines the ActionBean and adds the information to the cache.

Parameters:
type - a Class representing an ActionBean
Returns:
a Method[] containing all methods marked as custom validations. May return an empty array, but never null.
Throws:
Exception

handleValidationErrors

public static Resolution handleValidationErrors(ExecutionContext ctx)
                                         throws Exception
Responsible for checking to see if validation errors exist and if so for handling them appropriately. This includes ensuring that the error objects have all information necessary to render themselves appropriately and invoking any error handling code.

Parameters:
ctx - the ExecutionContext being used to process the current request
Returns:
a Resolution if the error handling code determines that some kind of resolution should be processed in favor of continuing on to handler invocation
Throws:
Exception

fillInValidationErrors

public static void fillInValidationErrors(ExecutionContext ctx)
Makes sure that validation errors have all the necessary information to render themselves properly, including the UrlBinding of the action bean and the field value if it hasn't already been set.

Parameters:
ctx - the ExecutionContext being used to process the current request

invokeEventHandler

public static Resolution invokeEventHandler(ExecutionContext ctx)
                                     throws Exception
Responsible for invoking the event handler identified. This method will only be called if an event handler was identified, and can assume that the bean and handler are present in the ExecutionContext.

Parameters:
ctx - the ExecutionContext being used to process the current request type conversion should occur
Returns:
a Resolution if the error handling code determines that some kind of resolution should be processed in favor of continuing on to handler invocation
Throws:
Exception

executeResolution

public static void executeResolution(ExecutionContext ctx,
                                     Resolution resolution)
                              throws Exception
Responsible for executing the Resolution returned by the request. Transitions the execution context to LifecycleStage.ResolutionExecution, sets the resolution on the execution context and then invokes the interceptor chain to execute the Resolution.

Parameters:
ctx - the current execution context representing the request
resolution - the resolution to be executed unless another is substituted by an interceptor before calling ctx.proceed()
Throws:
Exception

logValidationErrors

public static final void logValidationErrors(ActionBeanContext context)
Log validation errors at DEBUG to help during development.



? Copyright 2005-2006, Stripes Development Team.