public abstract class

ApplicationObjectSupport

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

Class Overview

Convenient superclass for application objects that want to be aware of the application context, e.g. for custom lookup of collaborating beans or for context-specific resource access. It saves the application context reference and provides an initialization callback method. Furthermore, it offers numerous convenience methods for message lookup.

There is no requirement to subclass this class: It just makes things a little easier if you need access to the context, e.g. for access to file resources or to the message source. Note that many application objects do not need to be aware of the application context at all, as they can receive collaborating beans via bean references.

Many framework classes are derived from this class, particularly within the web support.

Summary

Fields
protected final Log logger Logger that is available to subclasses
Public Constructors
ApplicationObjectSupport()
Public Methods
final ApplicationContext getApplicationContext()
Return the ApplicationContext that this object is associated with.
final void setApplicationContext(ApplicationContext context)
Set the ApplicationContext that this object runs in.
Protected Methods
final MessageSourceAccessor getMessageSourceAccessor()
Return a MessageSourceAccessor for the application context used by this object, for easy message access.
void initApplicationContext()
Subclasses can override this for custom initialization behavior.
void initApplicationContext(ApplicationContext context)
Subclasses can override this for custom initialization behavior.
boolean isContextRequired()
Determine whether this application object needs to run in an ApplicationContext.
Class requiredContextClass()
Determine the context class that any context passed to setApplicationContext must be an instance of.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.context.ApplicationContextAware

Fields

protected final Log logger

Logger that is available to subclasses

Public Constructors

public ApplicationObjectSupport ()

Public Methods

public final ApplicationContext getApplicationContext ()

Return the ApplicationContext that this object is associated with.

Throws
IllegalStateException if not running in an ApplicationContext

public final void setApplicationContext (ApplicationContext context)

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as afterPropertiesSet() or a custom init-method. Invoked after setResourceLoader(ResourceLoader), setApplicationEventPublisher(ApplicationEventPublisher) and MessageSourceAware, if applicable.

Parameters
context the ApplicationContext object to be used by this object

Protected Methods

protected final MessageSourceAccessor getMessageSourceAccessor ()

Return a MessageSourceAccessor for the application context used by this object, for easy message access.

Throws
IllegalStateException if not running in an ApplicationContext

protected void initApplicationContext ()

Subclasses can override this for custom initialization behavior.

The default implementation is empty. Called by initApplicationContext(org.springframework.context.ApplicationContext).

Throws
ApplicationContextException in case of initialization errors
BeansException if thrown by ApplicationContext methods

protected void initApplicationContext (ApplicationContext context)

Subclasses can override this for custom initialization behavior. Gets called by setApplicationContext after setting the context instance.

Note: Does not get called on reinitialization of the context but rather just on first initialization of this object's context reference.

The default implementation calls the overloaded initApplicationContext() method without ApplicationContext reference.

Parameters
context the containing ApplicationContext
Throws
ApplicationContextException in case of initialization errors
BeansException if thrown by ApplicationContext methods

protected boolean isContextRequired ()

Determine whether this application object needs to run in an ApplicationContext.

Default is "false". Can be overridden to enforce running in a context (i.e. to throw IllegalStateException on accessors if outside a context).

protected Class requiredContextClass ()

Determine the context class that any context passed to setApplicationContext must be an instance of. Can be overridden in subclasses.