public class AnnotatedClassActionResolver extends Object implements ActionResolver
Uses Annotations on classes to identify the ActionBean that corresponds to the current
request. ActionBeans are annotated with an @UrlBinding annotation, which denotes the
web application relative URL that the ActionBean should respond to.
Individual methods on ActionBean classes are expected to be annotated with @HandlesEvent annotations, and potentially a @DefaultHandler annotation. Using these annotations the Resolver will determine which method should be executed for the current request.
UrlBinding| Modifier and Type | Field and Description |
|---|---|
static String |
PACKAGES
Configuration key used to lookup a comma-separated list of package names.
|
RESOLVED_ACTION| Constructor and Description |
|---|
AnnotatedClassActionResolver() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addActionBean(Class<? extends ActionBean> clazz)
Adds an ActionBean class to the set that this resolver can resolve.
|
protected void |
assertGetContextWorks(ActionBean bean)
Since many down stream parts of Stripes rely on the ActionBean properly returning the
context it is given, we'll just test it up front.
|
protected Set<Class<? extends ActionBean>> |
findClasses()
Helper method to find implementations of ActionBean in the packages specified in
Configuration using the
ResolverUtil class. |
ActionBean |
getActionBean(ActionBeanContext context)
Gets the logical name of the ActionBean that should handle the request.
|
ActionBean |
getActionBean(ActionBeanContext context,
String path)
Returns the ActionBean class that is bound to the UrlBinding supplied.
|
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 would respond were a
request made with the path specified.
|
protected Configuration |
getConfiguration()
Provides subclasses with access to the configuration object.
|
Method |
getDefaultHandler(Class<? extends ActionBean> bean)
Returns the Method that is the default handler for events in the ActionBean class supplied.
|
String |
getEventName(Class<? extends ActionBean> bean,
ActionBeanContext context)
Try various means to determine which event is to be executed on the current ActionBean.
|
protected String |
getEventNameFromEventNameParam(Class<? extends ActionBean> bean,
ActionBeanContext context)
Looks to see if there is a single non-empty parameter value for the parameter name
specified by
StripesConstants.URL_KEY_EVENT_NAME. |
protected String |
getEventNameFromPath(Class<? extends ActionBean> bean,
ActionBeanContext context)
Looks to see if there is extra path information beyond simply the url binding of the
bean.
|
protected String |
getEventNameFromRequestAttribute(Class<? extends ActionBean> bean,
ActionBeanContext context)
Checks a special request attribute to get the event name.
|
protected String |
getEventNameFromRequestParams(Class<? extends ActionBean> bean,
ActionBeanContext context)
Loops through the set of known events for the ActionBean to see if the event
names are present as parameter names in the request.
|
String |
getHandledEvent(Method handler)
Responsible for determining the name of the event handled by this method, if indeed
it handles one at all.
|
Method |
getHandler(Class<? extends ActionBean> bean,
String eventName)
Uses the Maps constructed earlier to locate the Method which can handle the event.
|
protected String |
getRequestedPath(HttpServletRequest request)
Deprecated.
Use
HttpUtil.getRequestedPath(HttpServletRequest) instead. |
String |
getUrlBinding(Class<? extends ActionBean> clazz)
Takes a class that implements ActionBean and returns the URL binding of that class.
|
UrlBindingFactory |
getUrlBindingFactory()
Get the
UrlBindingFactory that is being used by this action resolver. |
String |
getUrlBindingFromPath(String path)
Returns the URL binding that is a substring of the path provided.
|
void |
init(Configuration configuration)
Scans the classpath of the current classloader (not including parents) to find implementations
of the ActionBean interface.
|
protected ActionBean |
makeNewActionBean(Class<? extends ActionBean> type,
ActionBeanContext context)
Helper method to construct and return a new ActionBean instance.
|
protected void |
processMethods(Class<?> clazz,
Map<String,Method> classMappings)
Helper method that examines a class, starting at it's highest super class and
working it's way down again, to find method annotations and ensure that child
class annotations take precedence.
|
protected void |
removeActionBean(Class<? extends ActionBean> clazz)
Removes an ActionBean class from the set that this resolver can resolve.
|
protected void |
setActionBeanContext(ActionBean bean,
ActionBeanContext context)
Calls
ActionBean.setContext(ActionBeanContext) with the given context only if
necessary. |
public static final String PACKAGES
public void init(Configuration configuration) throws Exception
init in interface ConfigurableComponentconfiguration - the Configuration object being used by StripesException - should be thrown if the component cannot be configured well enough to use.public UrlBindingFactory getUrlBindingFactory()
UrlBindingFactory that is being used by this action resolver.protected void addActionBean(Class<? extends ActionBean> clazz)
clazz - a class that implements ActionBeanprotected void removeActionBean(Class<? extends ActionBean> clazz)
clazz - a class that implements ActionBeanpublic String getUrlBindingFromPath(String path)
/user/Profile.action the path
/user/Profile.action/view would return /user/Profile.action.getUrlBindingFromPath in interface ActionResolverpath - the path being used to access an ActionBean, either in a form or link tag,
or in a request that is hitting the DispatcherServlet.public String getUrlBinding(Class<? extends ActionBean> clazz)
getUrlBinding in interface ActionResolverclazz - a class that implements ActionBeanprotected void processMethods(Class<?> clazz, Map<String,Method> classMappings)
public String getHandledEvent(Method handler)
getHandledEvent in interface ActionResolverhandler - a method that might or might not be a handler methodpublic Class<? extends ActionBean> getActionBeanType(String path)
Fetches the Class representing the type of ActionBean that would respond were a request made with the path specified. Checks to see if the full path matches any bean's UrlBinding. If no ActionBean matches then successively removes path segments (separated by slashes) from the end of the path until a match is found.
getActionBeanType in interface ActionResolverpath - the path segment of a URLpublic ActionBean getActionBean(ActionBeanContext context) throws StripesServletException
getActionBean in interface ActionResolvercontext - the ActionBeanContext for the current requestStripesServletException - thrown if a ActionBean cannot be resolved for any reason@Deprecated protected String getRequestedPath(HttpServletRequest request)
HttpUtil.getRequestedPath(HttpServletRequest) instead.request - the current HttpServletRequestpublic ActionBean getActionBean(ActionBeanContext context, String path) throws StripesServletException
getActionBean in interface ActionResolverpath - a URL to which an ActionBean is bound, or a path starting with the URL
to which an ActionBean has been bound.context - the current ActionBeanContextStripesServletException - if the UrlBinding does not match an ActionBean bindingprotected void setActionBeanContext(ActionBean bean, ActionBeanContext context)
ActionBean.setContext(ActionBeanContext) with the given context only if
necessary. Subclasses should use this method instead of setting the context directly because
it can be somewhat tricky to determine when it needs to be done.bean - The bean whose context may need to be set.context - The context to pass to the bean if necessary.protected void assertGetContextWorks(ActionBean bean) throws StripesServletException
bean - the ActionBean to test to see if getContext() works correctlyStripesServletException - if getContext() returns nullprotected ActionBean makeNewActionBean(Class<? extends ActionBean> type, ActionBeanContext context) throws Exception
type - the type of ActionBean to createcontext - the current ActionBeanContextException - if anything goes wrong!public String getEventName(Class<? extends ActionBean> bean, ActionBeanContext context)
Try various means to determine which event is to be executed on the current ActionBean. If a
'special' request attribute (StripesConstants.REQ_ATTR_EVENT_NAME) is present in
the request, then return its value. This attribute is used to handle internal forwards, when
request parameters are merged and cannot reliably determine the desired event name.
If that doesn't work, the value of a 'special' request parameter (StripesConstants.URL_KEY_EVENT_NAME)
is checked to see if contains a single value matching an event name.
Failing that, search for a parameter in the request whose name matches one of the named
events handled by the ActionBean. For example, if the ActionBean can handle events foo and
bar, this method will scan the request for foo=somevalue and bar=somevalue. If it finds a
request parameter with a matching name it will return that name. If there are multiple
matching names, the result of this method cannot be guaranteed and a
StripesRuntimeException will be thrown.
Finally, if the event name cannot be determined through the parameter names and there is extra path information beyond the URL binding of the ActionBean, it is checked to see if it matches an event name.
getEventName in interface ActionResolverbean - the ActionBean type bound to the requestcontext - the ActionBeanContect for the current requestprotected String getEventNameFromRequestAttribute(Class<? extends ActionBean> bean, ActionBeanContext context)
bean - the ActionBean type bound to the requestcontext - the ActionBeanContect for the current requestStripesConstants.REQ_ATTR_EVENT_NAMEprotected String getEventNameFromRequestParams(Class<? extends ActionBean> bean, ActionBeanContext context)
bean - the ActionBean type bound to the requestcontext - the ActionBeanContext for the current requestprotected String getEventNameFromPath(Class<? extends ActionBean> bean, ActionBeanContext context)
bean - the ActionBean type bound to the requestcontext - the ActionBeanContect for the current requestprotected String getEventNameFromEventNameParam(Class<? extends ActionBean> bean, ActionBeanContext context)
StripesConstants.URL_KEY_EVENT_NAME. If there is, and it
matches a known event it is returned, otherwise returns null.bean - the ActionBean type bound to the requestcontext - the ActionBeanContect for the current requestpublic Method getHandler(Class<? extends ActionBean> bean, String eventName) throws StripesServletException
getHandler in interface ActionResolverbean - the subclass of ActionBean that is bound to the request.eventName - the name of the event being handledStripesServletException - thrown when no method handles the named event.public Method getDefaultHandler(Class<? extends ActionBean> bean) throws StripesServletException
getDefaultHandler in interface ActionResolverbean - the ActionBean type bound to the requestStripesServletException - if no default handler could be locatedprotected Configuration getConfiguration()
protected Set<Class<? extends ActionBean>> findClasses()
ResolverUtil class.public Collection<Class<? extends ActionBean>> getActionBeanClasses()
ActionBean that are recognized by this
ActionResolver.getActionBeanClasses in interface ActionResolver© Copyright 2005-2006, Stripes Development Team.