|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.controller.AnnotatedClassActionResolver
public class AnnotatedClassActionResolver
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
Field Summary | |
---|---|
static String |
PACKAGES
Configuration key used to lookup a comma-separated list of package names. |
Fields inherited from interface net.sourceforge.stripes.controller.ActionResolver |
---|
RESOLVED_ACTION |
Constructor Summary | |
---|---|
AnnotatedClassActionResolver()
|
Method Summary | |
---|---|
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. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PACKAGES
Constructor Detail |
---|
public AnnotatedClassActionResolver()
Method Detail |
---|
public void init(Configuration configuration) throws Exception
init
in interface ConfigurableComponent
configuration
- the Configuration object being used by Stripes
Exception
- should be thrown if the component cannot be configured well enough to use.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 ActionResolver
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.
public String getUrlBinding(Class<? extends ActionBean> clazz)
getUrlBinding
in interface ActionResolver
clazz
- a class that implements ActionBean
protected void processMethods(Class<?> clazz, Map<String,Method> classMappings)
public String getHandledEvent(Method handler)
getHandledEvent
in interface ActionResolver
handler
- a method that might or might not be a handler method
public 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 ActionResolver
path
- the path segment of a URL
public ActionBean getActionBean(ActionBeanContext context) throws StripesServletException
getActionBean
in interface ActionResolver
context
- the ActionBeanContext for the current request
StripesServletException
- thrown if a ActionBean cannot be resolved for any reason@Deprecated protected String getRequestedPath(HttpServletRequest request)
HttpUtil.getRequestedPath(HttpServletRequest)
instead.
request
- the current HttpServletRequest
public ActionBean getActionBean(ActionBeanContext context, String path) throws StripesServletException
getActionBean
in interface ActionResolver
path
- 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 ActionBeanContext
StripesServletException
- 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 correctly
StripesServletException
- if getContext() returns nullprotected ActionBean makeNewActionBean(Class<? extends ActionBean> type, ActionBeanContext context) throws Exception
type
- the type of ActionBean to createcontext
- the current ActionBeanContext
Exception
- 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 ActionResolver
bean
- the ActionBean type bound to the requestcontext
- the ActionBeanContect for the current request
protected String getEventNameFromRequestAttribute(Class<? extends ActionBean> bean, ActionBeanContext context)
bean
- the ActionBean type bound to the requestcontext
- the ActionBeanContect for the current request
StripesConstants.REQ_ATTR_EVENT_NAME
protected String getEventNameFromRequestParams(Class<? extends ActionBean> bean, ActionBeanContext context)
bean
- the ActionBean type bound to the requestcontext
- the ActionBeanContext for the current request
protected String getEventNameFromPath(Class<? extends ActionBean> bean, ActionBeanContext context)
bean
- the ActionBean type bound to the requestcontext
- the ActionBeanContect for the current request
protected 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 request
public Method getHandler(Class<? extends ActionBean> bean, String eventName) throws StripesServletException
getHandler
in interface ActionResolver
bean
- the subclass of ActionBean that is bound to the request.eventName
- the name of the event being handled
StripesServletException
- thrown when no method handles the named event.public Method getDefaultHandler(Class<? extends ActionBean> bean) throws StripesServletException
getDefaultHandler
in interface ActionResolver
bean
- the ActionBean type bound to the request
StripesServletException
- 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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |