The Spring Framework

org.springframework.web.servlet.mvc.support
Class ControllerClassNameHandlerMapping

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.handler.AbstractHandlerMapping
              extended by org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
                  extended by org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
All Implemented Interfaces:
ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping

public class ControllerClassNameHandlerMapping
extends AbstractUrlHandlerMapping
implements HandlerMapping

Implementation of HandlerMapping that follows a simple convention for generating URL path mappings from the class names of registered Controller and ThrowawayController beans.

For simple Controller implementations (those that handle a single request type), the convention is to take the short name of the Class, remove the 'Controller' suffix if it exists and return the remaining text, lowercased, as the mapping, with a leading /. For example:

For MultiActionControllers then a similar mapping is registered, except that all sub-paths are registed using the trailing wildcard pattern /*. For example:

For MultiActionController it is often useful to use this mapping strategy in conjunction with the InternalPathMethodNameResolver.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
Controller, ThrowawayController, MultiActionController

Field Summary
protected  Log logger
          Logger available to subclasses
 
Fields inherited from interface org.springframework.web.servlet.HandlerMapping
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
ControllerClassNameHandlerMapping()
           
 
Method Summary
protected  void detectControllers()
          Detect all the Controller and ThrowawayController beans registered in the ApplicationContext and register a URL path mapping for each one based on rules defined here.
protected  String generatePathMapping(Class controllerClass)
          Generate the actual URL path for the given Controller class.
protected  void initApplicationContext()
          Calls the detectControllers() method in addition to the superclass's initialization.
protected  void registerController(String beanName)
          Register the controller with the given name, as defined in the current application context.
protected  void registerControllers(Class controllerType)
          Register all controllers of the given type, searching the current DispatcherServlet's ApplicationContext for matching beans.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
exposePathWithinMapping, getHandlerInternal, getHandlerMap, lookupHandler, registerHandler, registerHandler, setAlwaysUseFullPath, setLazyInitHandlers, setPathMatcher, setUrlDecode, setUrlPathHelper
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, getDefaultHandler, getHandler, getOrder, initInterceptors, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.web.servlet.HandlerMapping
getHandler
 

Field Detail

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

ControllerClassNameHandlerMapping

public ControllerClassNameHandlerMapping()
Method Detail

initApplicationContext

protected void initApplicationContext()
Calls the detectControllers() method in addition to the superclass's initialization.

Overrides:
initApplicationContext in class AbstractHandlerMapping
See Also:
detectControllers()

detectControllers

protected void detectControllers()
                          throws BeansException
Detect all the Controller and ThrowawayController beans registered in the ApplicationContext and register a URL path mapping for each one based on rules defined here.

Throws:
BeansException - if the controllers couldn't be obtained or registered
See Also:
generatePathMapping(Class)

registerControllers

protected void registerControllers(Class controllerType)
                            throws BeansException
Register all controllers of the given type, searching the current DispatcherServlet's ApplicationContext for matching beans.

Parameters:
controllerType - the type of controller to search for
Throws:
BeansException - if the controllers couldn't be obtained or registered

registerController

protected void registerController(String beanName)
                           throws BeansException,
                                  IllegalStateException
Register the controller with the given name, as defined in the current application context.

Parameters:
beanName - the name of the controller bean
Throws:
BeansException - if the controller couldn't be registered
IllegalStateException - if there is a conflicting handler registered
See Also:
ApplicationObjectSupport.getApplicationContext()

generatePathMapping

protected String generatePathMapping(Class controllerClass)
Generate the actual URL path for the given Controller class. Sub-classes may choose to customize the paths that are generated by overriding this method.


The Spring Framework

Copyright © 2002-2006 The Spring Framework.