Class AbstractDispatcher

java.lang.Object
org.apache.struts.dispatcher.AbstractDispatcher
All Implemented Interfaces:
Serializable, Dispatcher
Direct Known Subclasses:
AbstractMappingDispatcher, AbstractParameterDispatcher

public abstract class AbstractDispatcher extends Object implements Dispatcher, Serializable
This abstract class is the stock template for Dispatcher implementations.
Since:
Struts 1.4
Version:
$Rev$
See Also:
  • Field Details

  • Constructor Details

    • AbstractDispatcher

      public AbstractDispatcher(MethodResolver methodResolver)
      Constructs a new dispatcher with the specified method resolver.
      Parameters:
      methodResolver - the method resolver
  • Method Details

    • dispatch

      public Object dispatch(ActionContext context) throws Exception
      Description copied from interface: Dispatcher
      Dispatches to the action referenced by the specified context.
      Specified by:
      dispatch in interface Dispatcher
      Parameters:
      context - the current action context
      Returns:
      the result type, null if the response was handled directly, or Void if the executed method has no return signature
      Throws:
      Exception - if an exception occurs
    • dispatchMethod

      protected final Object dispatchMethod(ActionContext context, Method method, String name) throws Exception
      Dispatches to the specified method.
      Parameters:
      context - the current action context
      method - The method to invoke
      name - The name of the method to invoke
      Returns:
      the return value of the method
      Throws:
      Exception - if the dispatch fails with an exception
      See Also:
      • buildMethodArguments(ActionContext, Method)
    • getDefaultMethodName

      protected String getDefaultMethodName()
      Retrieves the name of the method to fallback upon if no method name can be resolved. The default implementation returns EXECUTE_METHOD_NAME.
      Returns:
      the fallback method name; can be null
      See Also:
    • getMethod

      protected final Method getMethod(ActionContext context, String methodName) throws NoSuchMethodException
      Introspects the action to identify a method of the specified name that will be the target of the dispatch. This implementation caches the method instance for subsequent invocations.
      Parameters:
      context - the current action context
      methodName - the name of the method to be introspected
      Returns:
      the method of the specified name
      Throws:
      NoSuchMethodException - if no such method can be found
      See Also:
      • resolveMethod(ActionContext, String)
      • flushMethodCache()
    • invoke

      protected final Object invoke(Object target, Method method, Object[] args, String path) throws Exception
      Convenience method to help dispatch the specified method. The method is invoked via reflection.
      Parameters:
      target - the target object
      method - the method of the target object
      args - the arguments for the method
      path - the mapping path
      Returns:
      the return value of the method
      Throws:
      Exception - if the dispatch fails with an exception
    • isCancelled

      protected boolean isCancelled(ActionContext context)
      Determines whether the current form's cancel button was pressed. The default behavior method will check if the ActionContext.getCancelled() context property is set , which normally occurs if the cancel button generated by CancelTag was pressed by the user in the current request.
      Parameters:
      context - the current action context
      Returns:
      true if the request is cancelled; otherwise false
    • unspecified

      protected Object unspecified(ActionContext context) throws Exception
      Services the case when the dispatch fails because the method name cannot be resolved. The default behavior throws an IllegalStateException. Subclasses should override this to provide custom handling such as sending an HTTP 404 error or dispatching elsewhere.
      Parameters:
      context - the current action context
      Returns:
      the return value of the dispatch
      Throws:
      Exception - if an error occurs
      See Also:
      • resolveMethodName(ActionContext)