Package org.apache.struts.dispatcher
Class AbstractDispatcher
java.lang.Object
org.apache.struts.dispatcher.AbstractDispatcher
- All Implemented Interfaces:
Serializable
,Dispatcher
- Direct Known Subclasses:
AbstractMappingDispatcher
,AbstractParameterDispatcher
This abstract class is the stock template for
Dispatcher
implementations.- Since:
- Struts 1.4
- Version:
- $Rev$
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractDispatcher
(MethodResolver methodResolver) Constructs a new dispatcher with the specified method resolver. -
Method Summary
Modifier and TypeMethodDescriptiondispatch
(ActionContext context) Dispatches to the action referenced by the specified context.protected final Object
dispatchMethod
(ActionContext context, Method method, String name) Dispatches to the specified method.protected String
Retrieves the name of the method to fallback upon if no method name can be resolved.protected final Method
getMethod
(ActionContext context, String methodName) Introspects the action to identify a method of the specified name that will be the target of the dispatch.protected final Object
Convenience method to help dispatch the specified method.protected boolean
isCancelled
(ActionContext context) Determines whether the current form's cancel button was pressed.protected Object
unspecified
(ActionContext context) Services the case when the dispatch fails because the method name cannot be resolved.
-
Field Details
-
CANCELLED_METHOD_NAME
The name of thecancelled
method.- See Also:
-
EXECUTE_METHOD_NAME
The name of theexecute
method.- See Also:
-
-
Constructor Details
-
AbstractDispatcher
Constructs a new dispatcher with the specified method resolver.- Parameters:
methodResolver
- the method resolver
-
-
Method Details
-
dispatch
Description copied from interface:Dispatcher
Dispatches to the action referenced by the specified context.- Specified by:
dispatch
in interfaceDispatcher
- Parameters:
context
- the current action context- Returns:
- the result type,
null
if the response was handled directly, orVoid
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 contextmethod
- The method to invokename
- 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:
-
getDefaultMethodName
Retrieves the name of the method to fallback upon if no method name can be resolved. The default implementation returnsEXECUTE_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 contextmethodName
- 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:
-
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 objectmethod
- the method of the target objectargs
- the arguments for the methodpath
- the mapping path- Returns:
- the return value of the method
- Throws:
Exception
- if the dispatch fails with an exception
-
isCancelled
Determines whether the current form's cancel button was pressed. The default behavior method will check if theActionContext.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; otherwisefalse
-
unspecified
Services the case when the dispatch fails because the method name cannot be resolved. The default behavior throws anIllegalStateException
. 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:
-