org.springframework.web.portlet.handler
Class AbstractMapBasedHandlerMapping<K>

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.portlet.handler.AbstractHandlerMapping
          extended by org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping<K>
All Implemented Interfaces:
Aware, ApplicationContextAware, Ordered, HandlerMapping
Direct Known Subclasses:
DefaultAnnotationHandlerMapping, ParameterHandlerMapping, PortletModeHandlerMapping, PortletModeParameterHandlerMapping

public abstract class AbstractMapBasedHandlerMapping<K>
extends AbstractHandlerMapping

Abstract base class for HandlerMapping implementations that rely on a map which caches handler objects per lookup key. Supports arbitrary lookup keys, and automatically resolves handler bean names into handler bean instances.

Since:
2.0
Author:
Juergen Hoeller
See Also:
getLookupKey(javax.portlet.PortletRequest), registerHandler(Object, Object)

Nested Class Summary
protected static interface AbstractMapBasedHandlerMapping.PortletRequestMappingPredicate
          Predicate interface for determining a match with a given request.
 
Field Summary
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
AbstractMapBasedHandlerMapping()
           
 
Method Summary
protected  Object getHandlerInternal(PortletRequest request)
          Determines a handler for the computed lookup key for the given request.
protected abstract  K getLookupKey(PortletRequest request)
          Build a lookup key for the given request.
protected  void registerHandler(K lookupKey, Object handler)
          Register the given handler instance for the given parameter value.
protected  void registerHandler(K lookupKey, Object handler, AbstractMapBasedHandlerMapping.PortletRequestMappingPredicate predicate)
          Register the given handler instance for the given parameter value.
protected  void registerHandlers(Map<K,?> handlerMap)
          Register all handlers specified in the Portlet mode map for the corresponding modes.
 void setLazyInitHandlers(boolean lazyInitHandlers)
          Set whether to lazily initialize handlers.
 
Methods inherited from class org.springframework.web.portlet.handler.AbstractHandlerMapping
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initApplicationContext, initInterceptors, setApplyWebRequestInterceptorsToRenderPhaseOnly, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMapBasedHandlerMapping

public AbstractMapBasedHandlerMapping()
Method Detail

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 handler objects directly.

If you want to allow your handlers 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(PortletRequest request)
                             throws Exception
Determines a handler for the computed lookup key for the given request.

Specified by:
getHandlerInternal in class AbstractHandlerMapping
Parameters:
request - current portlet request
Returns:
the corresponding handler instance, or null if none found
Throws:
Exception - if there is an internal error
See Also:
getLookupKey(javax.portlet.PortletRequest)

getLookupKey

protected abstract K getLookupKey(PortletRequest request)
                           throws Exception
Build a lookup key for the given request.

Parameters:
request - current portlet request
Returns:
the lookup key (never null)
Throws:
Exception - if key computation failed

registerHandlers

protected void registerHandlers(Map<K,?> handlerMap)
                         throws BeansException
Register all handlers specified in the Portlet mode map for the corresponding modes.

Parameters:
handlerMap - Map with lookup keys as keys and handler beans or bean names as values
Throws:
BeansException - if the handler couldn't be registered

registerHandler

protected void registerHandler(K lookupKey,
                               Object handler)
                        throws BeansException,
                               IllegalStateException
Register the given handler instance for the given parameter value.

Parameters:
lookupKey - the key to map the handler onto
handler - the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
Throws:
BeansException - if the handler couldn't be registered
IllegalStateException - if there is a conflicting handler registered

registerHandler

protected void registerHandler(K lookupKey,
                               Object handler,
                               AbstractMapBasedHandlerMapping.PortletRequestMappingPredicate predicate)
                        throws BeansException,
                               IllegalStateException
Register the given handler instance for the given parameter value.

Parameters:
lookupKey - the key to map the handler onto
handler - the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
predicate - a predicate object for this handler (may be null), determining a match with the primary lookup key
Throws:
BeansException - if the handler couldn't be registered
IllegalStateException - if there is a conflicting handler registered