org.springframework.web.servlet.handler
Class AbstractUrlHandlerMapping

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.handler.AbstractHandlerMapping
              extended byorg.springframework.web.servlet.handler.AbstractUrlHandlerMapping
All Implemented Interfaces:
ApplicationContextAware, HandlerMapping, Ordered
Direct Known Subclasses:
AbstractPathMapHandlerMapping, BeanNameUrlHandlerMapping, SimpleUrlHandlerMapping

public abstract class AbstractUrlHandlerMapping
extends AbstractHandlerMapping

Abstract base class for URL-mapped HandlerMapping implementations. Provides infrastructure for mapping handlers to URLs and configurable URL lookup. For information on the latter, see alwaysUseFullPath property.

Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" pattern matches both "/test" and "/team", "/test/*" matches all paths in the "/test" directory, "/test/**" matches all paths below "/test". For details, see the PathMatcher class.

Since:
16.04.2003
Author:
Juergen Hoeller
See Also:
setAlwaysUseFullPath(boolean), setUrlDecode(boolean), PathMatcher

Field Summary
 
Fields inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
logger
 
Constructor Summary
AbstractUrlHandlerMapping()
           
 
Method Summary
protected  Object getHandlerInternal(HttpServletRequest request)
          Look up a handler for the URL path of the given request.
protected  Object lookupHandler(String urlPath)
          Look up a handler instance for the given URL path.
protected  void registerHandler(String urlPath, Object handler)
          Register the given handler instance for the given URL path.
 void setAlwaysUseFullPath(boolean alwaysUseFullPath)
          Set if URL lookup should always use full path within current servlet context.
 void setLazyInitHandlers(boolean lazyInitHandlers)
          Set whether to lazily initialize handlers.
 void setUrlDecode(boolean urlDecode)
          Set if context path and request URI should be URL-decoded.
 void setUrlPathHelper(UrlPathHelper urlPathHelper)
          Set the UrlPathHelper to use for resolution of lookup paths.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
getDefaultHandler, getHandler, getOrder, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUrlHandlerMapping

public AbstractUrlHandlerMapping()
Method Detail

setAlwaysUseFullPath

public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use full path within current servlet context. Else, the path within the current servlet mapping is used if applicable (i.e. in the case of a ".../*" servlet mapping in web.xml). Default is false.

See Also:
UrlPathHelper.setAlwaysUseFullPath(boolean)

setUrlDecode

public void setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.

Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).

Note: Setting this to true requires J2SE 1.4, as J2SE 1.3's URLDecoder class does not offer a way to specify the encoding.

See Also:
UrlPathHelper.setUrlDecode(boolean)

setUrlPathHelper

public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.

Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers.

See Also:
AbstractUrlMethodNameResolver.setUrlPathHelper(org.springframework.web.util.UrlPathHelper)

setLazyInitHandlers

public void setLazyInitHandlers(boolean lazyInitHandlers)
Set whether to lazily initialize handlers. Only applicable to singleton handlers, as prototypes are always lazily initialized. Default is false, as eager initialization allows for more efficiency through referencing the controller objects directly.

If you want to allow your controllers to be lazily initialized, make them "lazy-init" and set this flag to true. Just making them "lazy-init" will not work, as they are initialized through the references from the handler mapping in this case.


getHandlerInternal

protected Object getHandlerInternal(HttpServletRequest request)
                             throws Exception
Look up a handler for the URL path of the given request.

Specified by:
getHandlerInternal in class AbstractHandlerMapping
Parameters:
request - current HTTP request
Returns:
the looked up handler instance, or null
Throws:
Exception - if there is an internal error

lookupHandler

protected Object lookupHandler(String urlPath)
Look up a handler instance for the given URL path.

Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the PathMatcher class.

Parameters:
urlPath - URL the bean is mapped to
Returns:
the associated handler instance, or null if not found
See Also:
PathMatcher

registerHandler

protected void registerHandler(String urlPath,
                               Object handler)
                        throws BeansException
Register the given handler instance for the given URL path.

Parameters:
urlPath - URL the bean is mapped to
handler - the handler instance
Throws:
BeansException - if the handler couldn't be registered


Copyright (C) 2003-2004 The Spring Framework Project.