com.interface21.web.servlet.view
Class AbstractCachingViewResolver

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.view.AbstractCachingViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver
Direct Known Subclasses:
InternalResourceViewResolver, ResourceBundleViewResolver, XmlViewResolver

public abstract class AbstractCachingViewResolver
extends ApplicationObjectSupport
implements ViewResolver

Convenient superclass for view resolvers. Caches views once resolved. This means that view resolution won't be a performance problem, no matter how costly initial view retrieval is. View retrieval is deferred to subclasses.

Author:
Rod Johnson

Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
AbstractCachingViewResolver()
           
 
Method Summary
 boolean isCache()
          If caching is enabled.
protected abstract  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
 View resolveViewName(java.lang.String viewName, java.util.Locale locale)
          Resolve the given view by name.
 void setCache(boolean cache)
          Enable caching.
 
Methods inherited from class com.interface21.context.support.ApplicationObjectSupport
getApplicationContext, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.interface21.context.ApplicationContextAware
setApplicationContext
 

Constructor Detail

AbstractCachingViewResolver

public AbstractCachingViewResolver()
Method Detail

setCache

public void setCache(boolean cache)
Enable caching. Disable this only for debugging and development. Default is for caching to be enabled.

Warning: disabling caching severely impacts performance. Tests indicate that turning caching off reduces performance by at least 20%. Increased object churn probably eventually makes the problem even worse.


isCache

public boolean isCache()
If caching is enabled.

resolveViewName

public final View resolveViewName(java.lang.String viewName,
                                  java.util.Locale locale)
                           throws javax.servlet.ServletException
Description copied from interface: ViewResolver
Resolve the given view by name.
Specified by:
resolveViewName in interface ViewResolver
Following copied from interface: com.interface21.web.servlet.ViewResolver
Parameters:
viewName - name of the view to resolve
locale - Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.
Throws:
javax.servlet.ServletException - if the view cannot be resolved.

loadView

protected abstract View loadView(java.lang.String viewName,
                                 java.util.Locale locale)
                          throws javax.servlet.ServletException
Subclasses must implement this method. There need be no concern for efficiency, as this class will cache views. Not all subclasses may support internationalization: A subclass that doesn't can ignore the locale parameter.
Parameters:
viewName - name of the view to retrieve
locale - Locale to retrieve the view for
Returns:
the View if it can be resolved, or null
Throws:
javax.servlet.ServletException - if there is an error trying to resolve the view


Rod Johnson and Spring contributors 2001-2003.