org.springframework.context.support
Class ApplicationObjectSupport

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
All Implemented Interfaces:
ApplicationContextAware
Direct Known Subclasses:
EventPublicationInterceptor, WebApplicationObjectSupport

public abstract class ApplicationObjectSupport
extends java.lang.Object
implements ApplicationContextAware

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.

Author:
Rod Johnson, Juergen Hoeller

Field Summary
protected  org.apache.commons.logging.Log logger
          Logger that is available to subclasses
 
Constructor Summary
ApplicationObjectSupport()
          Constructor for bean usage via subclassing.
ApplicationObjectSupport(ApplicationContext context)
          Constructor for usage as helper to delegate to.
 
Method Summary
 ApplicationContext getApplicationContext()
          Return the ApplicationContext instance used by this object.
protected  MessageSourceAccessor getMessageSourceAccessor()
          Return a MessageSourceAccessor for the application context used by this object, for easy message access.
protected  void initApplicationContext()
          Subclasses can override this for custom initialization behavior.
protected  java.lang.Class requiredContextClass()
          Determine the context class that any context passed to setApplicationContext must be an instance of.
 void setApplicationContext(ApplicationContext context)
          Set the ApplicationContext that this object runs in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger that is available to subclasses

Constructor Detail

ApplicationObjectSupport

public ApplicationObjectSupport()
Constructor for bean usage via subclassing.


ApplicationObjectSupport

public ApplicationObjectSupport(ApplicationContext context)
Constructor for usage as helper to delegate to.

Parameters:
context - ApplicationContext object to be used by this object
Method Detail

setApplicationContext

public final void setApplicationContext(ApplicationContext context)
                                 throws BeansException
Description copied from interface: ApplicationContextAware
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 like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ResourceLoaderAware's setResourceLoader.

Specified by:
setApplicationContext in interface ApplicationContextAware
Parameters:
context - ApplicationContext object to be used by this object
Throws:
BeansException - if thrown by application context methods
See Also:
BeanInitializationException

requiredContextClass

protected java.lang.Class requiredContextClass()
Determine the context class that any context passed to setApplicationContext must be an instance of. Can be overridden in subclasses.


initApplicationContext

protected void initApplicationContext()
                               throws BeansException
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.

Throws:
ApplicationContextException - in case of initialization errors
BeansException - if thrown by application context methods

getApplicationContext

public final ApplicationContext getApplicationContext()
Return the ApplicationContext instance used by this object.


getMessageSourceAccessor

protected final MessageSourceAccessor getMessageSourceAccessor()
Return a MessageSourceAccessor for the application context used by this object, for easy message access.



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