public abstract class

WebApplicationObjectSupport

extends ApplicationObjectSupport
implements ServletContextAware
java.lang.Object
   ↳ org.springframework.context.support.ApplicationObjectSupport
     ↳ org.springframework.web.context.support.WebApplicationObjectSupport
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Convenient superclass for application objects running in a WebApplicationContext. Provides getWebApplicationContext(), getServletContext(), and getTempDir() methods.

Summary

[Expand]
Inherited Fields
From class org.springframework.context.support.ApplicationObjectSupport
Public Constructors
WebApplicationObjectSupport()
Public Methods
final void setServletContext(ServletContext servletContext)
Set the ServletContext that this object runs in.
Protected Methods
final ServletContext getServletContext()
Return the current ServletContext.
final File getTempDir()
Return the temporary directory for the current web application, as provided by the servlet container.
final WebApplicationContext getWebApplicationContext()
Return the current application context as WebApplicationContext.
void initApplicationContext(ApplicationContext context)
void initServletContext(ServletContext servletContext)
Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.
boolean isContextRequired()
Overrides the base class behavior to enforce running in an ApplicationContext.
[Expand]
Inherited Methods
From class org.springframework.context.support.ApplicationObjectSupport
From class java.lang.Object
From interface org.springframework.context.ApplicationContextAware
From interface org.springframework.web.context.ServletContextAware

Public Constructors

public WebApplicationObjectSupport ()

Public Methods

public final void setServletContext (ServletContext servletContext)

Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Parameters
servletContext ServletContext object to be used by this object

Protected Methods

protected final ServletContext getServletContext ()

Return the current ServletContext.

Throws
IllegalStateException if not running within a ServletContext

protected final File getTempDir ()

Return the temporary directory for the current web application, as provided by the servlet container.

Returns
  • the File representing the temporary directory
Throws
IllegalStateException if not running within a ServletContext

protected final WebApplicationContext getWebApplicationContext ()

Return the current application context as WebApplicationContext.

NOTE: Only use this if you actually need to access WebApplicationContext-specific functionality. Preferably use getApplicationContext() or getServletContext() else, to be able to run in non-WebApplicationContext environments as well.

Throws
IllegalStateException if not running in a WebApplicationContext

protected void initApplicationContext (ApplicationContext context)

Calls initServletContext(javax.servlet.ServletContext) if the given ApplicationContext is a WebApplicationContext.

Parameters
context the containing ApplicationContext

protected void initServletContext (ServletContext servletContext)

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty. Called by initApplicationContext(org.springframework.context.ApplicationContext) as well as setServletContext(javax.servlet.ServletContext).

Parameters
servletContext the ServletContext that this application object runs in (never null)

protected boolean isContextRequired ()

Overrides the base class behavior to enforce running in an ApplicationContext. All accessors will throw IllegalStateException if not running in a context.