net.sourceforge.stripes.controller
Interface ActionResolver

All Superinterfaces:
ConfigurableComponent
All Known Implementing Classes:
AnnotatedClassActionResolver, NameBasedActionResolver

public interface ActionResolver
extends ConfigurableComponent

Resolvers are responsible for locating ActionBean instances that can handle the submitted request. Once an appropriate ActionBean has been identified the ActionResolver is also responsible for identifying the individual method on the ActionBean class that should handle this specific request.

Throughout this class two terms are used that refer to similar but not interchangeable concepts. UrlBinding refers to the exact URL to which a bean is bound, e.g. /account/Profile.action. Path refers to the path segment of the requested URL and is generally composed of the URL binding and possibly some additional information, e.g. /account/Profile.action/edit. In general the methods in this class are capable of taking in a path and extracting the UrlBinding from it.

Author:
Tim Fennell

Field Summary
static String RESOLVED_ACTION
          Key that is to be used by ActionResolvers to store, as a request attribute, the action that was resolved in the current request.
 
Method Summary
 ActionBean getActionBean(ActionBeanContext context)
          Resolves the Class, implementing ActionBean, that should be used to handle the request.
 ActionBean getActionBean(ActionBeanContext context, String path)
          Returns the ActionBean class that responds to the path provided.
 Collection<Class<? extends ActionBean>> getActionBeanClasses()
          Get all the classes implementing ActionBean that are recognized by this ActionResolver.
 Class<? extends ActionBean> getActionBeanType(String path)
          Fetches the Class representing the type of ActionBean that has been bound to the URL contained within the path supplied.
 Method getDefaultHandler(Class<? extends ActionBean> bean)
          Locates and returns the default handler method that should be invoked when no specific event is named.
 String getEventName(Class<? extends ActionBean> bean, ActionBeanContext context)
          Determines the name of the event fired by the front end.
 String getHandledEvent(Method handler)
          Returns the name of the event to which a given handler method responds.
 Method getHandler(Class<? extends ActionBean> bean, String eventName)
          Resolves the Method which handles the named event.
 String getUrlBinding(Class<? extends ActionBean> clazz)
          Takes a class that implements ActionBean and returns the URL binding of that class.
 String getUrlBindingFromPath(String path)
          Returns the URL binding that is a substring of the path provided.
 
Methods inherited from interface net.sourceforge.stripes.config.ConfigurableComponent
init
 

Field Detail

RESOLVED_ACTION

static final String RESOLVED_ACTION
Key that is to be used by ActionResolvers to store, as a request attribute, the action that was resolved in the current request. The 'action' stored is always a String.

See Also:
Constant Field Values
Method Detail

getUrlBindingFromPath

String getUrlBindingFromPath(String path)
Returns the URL binding that is a substring of the path provided. For example, if there is an ActionBean bound to /user/Profile.action, invoking getUrlBindingFromPath("/user/Profile.action/view" should return "/user/Profile.action".

Parameters:
path - the path being used to access an ActionBean, either in a form or link tag, or in a request that is hitting the DispatcherServlet.
Returns:
the UrlBinding of the ActionBean appropriate for the request, or null if the path supplied cannot be mapped to an ActionBean.

getActionBean

ActionBean getActionBean(ActionBeanContext context)
                         throws StripesServletException
Resolves the Class, implementing ActionBean, that should be used to handle the request. If more than one class can be mapped to the request the results of this method are undefined - implementations may return one of the implementations located or throw an exception.

Parameters:
context - the ActionBeanContext for the current request
Returns:
an instance of ActionBean to handle the current request
Throws:
StripesServletException - thrown if a ActionBean cannot be resolved for any reason

getActionBean

ActionBean getActionBean(ActionBeanContext context,
                         String path)
                         throws StripesServletException
Returns the ActionBean class that responds to the path provided. If the path does not contain a UrlBinding to which an ActionBean is bound a StripesServletException will be thrown.

Parameters:
context - the current action bean context
path - the path segment of the request (or link or action)
Returns:
an instance of ActionBean that is bound to the UrlBinding contained within the path supplied
Throws:
StripesServletException - if a matching ActionBean cannot be found

getActionBeanType

Class<? extends ActionBean> getActionBeanType(String path)
Fetches the Class representing the type of ActionBean that has been bound to the URL contained within the path supplied. Will not cause any ActionBean to be instantiated. If no ActionBean has been bound to the URL then null will be returned.

Parameters:
path - the path segment of a request url or form action or link
Returns:
the class object for the type of action bean bound to the url, or null if no bean is bound to that url

getUrlBinding

String getUrlBinding(Class<? extends ActionBean> clazz)
Takes a class that implements ActionBean and returns the URL binding of that class. Essentially the inverse of the getActionBean() methods, this method allows you to find out the URL binding of any ActionBean class. The binding can then be used to generate URLs or for any other purpose. If the bean is not bound, this method may return null.

Parameters:
clazz - a class that implements ActionBean
Returns:
the UrlBinding or null if none can be determined
Since:
Stripes 1.2

getEventName

String getEventName(Class<? extends ActionBean> bean,
                    ActionBeanContext context)
Determines the name of the event fired by the front end. Allows implementations to easiliy vary their strategy for specifying event names (e.g. button names, hidden field rewrites via JavaScript etc.).

Parameters:
bean - the ActionBean type that has been bound to the request
context - the ActionBeanContext for the current request
Returns:
the name of the event fired by the front end, or null if none is found

getHandler

Method getHandler(Class<? extends ActionBean> bean,
                  String eventName)
                  throws StripesServletException
Resolves the Method which handles the named event. If more than one method is declared as able to handle the event the results of this method are undefined - implementations may return one of the implementations or throw an exception.

Parameters:
bean - the ActionBean type that has been bound to the request
eventName - the named event being handled by the ActionBean
Returns:
a Method object representing the handling method - never null
Throws:
StripesServletException - thrown if a method cannot be resolved for any reason, including but not limited to, when a Method does not exist that handles the event.

getDefaultHandler

Method getDefaultHandler(Class<? extends ActionBean> bean)
                         throws StripesServletException
Locates and returns the default handler method that should be invoked when no specific event is named. This occurs most often when a user submits a form via the Enter button and no button or image button name is passed.

Parameters:
bean - the ActionBean type that has been bound to the request
Returns:
a Method object representing the handling method - never null
Throws:
StripesServletException - thrown if a default handler method cannot be found.

getHandledEvent

String getHandledEvent(Method handler)
                       throws StripesServletException
Returns the name of the event to which a given handler method responds. Primarily useful when the default event is fired and it is necessary to figure out if the handler also responds to a named event.

Parameters:
handler - the handler method who's event name to find
Returns:
String the name of the event handled by this method, or null if an event is not mapped to this method.
Throws:
StripesServletException

getActionBeanClasses

Collection<Class<? extends ActionBean>> getActionBeanClasses()
Get all the classes implementing ActionBean that are recognized by this ActionResolver. This method must return the full set of ActionBean classes after the call to init().



? Copyright 2005-2006, Stripes Development Team.