Class ApplicationObjectSupport
- All Implemented Interfaces:
Aware, ApplicationContextAware
- Direct Known Subclasses:
AbstractHandlerMapping, WebApplicationObjectSupport
There is no requirement to subclass this class: It just makes things a little easier if you need access to the context, for example, 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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger that is available to subclasses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @Nullable ApplicationContextReturn the ApplicationContext that this object is associated with.protected final @Nullable MessageSourceAccessorReturn a MessageSourceAccessor for the application context used by this object, for easy message access.protected voidSubclasses can override this for custom initialization behavior.protected voidinitApplicationContext(ApplicationContext context) Subclasses can override this for custom initialization behavior.protected booleanDetermine whether this application object needs to run in an ApplicationContext.protected final ApplicationContextObtain the ApplicationContext for actual use.protected Class<?> Determine the context class that any context passed tosetApplicationContextmust be an instance of.final voidSet the ApplicationContext that this object runs in.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLogger that is available to subclasses.
-
-
Constructor Details
-
ApplicationObjectSupport
public ApplicationObjectSupport()
-
-
Method Details
-
setApplicationContext
Description copied from interface:ApplicationContextAwareSet 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
InitializingBean.afterPropertiesSet()or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
context- the ApplicationContext object to be used by this object- Throws:
BeansException- if thrown by application context methods- See Also:
-
isContextRequired
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).
- See Also:
-
requiredContextClass
Determine the context class that any context passed tosetApplicationContextmust be an instance of. Can be overridden in subclasses.- See Also:
-
initApplicationContext
Subclasses can override this for custom initialization behavior. Gets called bysetApplicationContextafter setting the context instance.Note: Does not get called on re-initialization 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 errorsBeansException- if thrown by ApplicationContext methods- See Also:
-
initApplicationContext
Subclasses can override this for custom initialization behavior.The default implementation is empty. Called by
initApplicationContext(ApplicationContext).- Throws:
ApplicationContextException- in case of initialization errorsBeansException- if thrown by ApplicationContext methods- See Also:
-
getApplicationContext
Return the ApplicationContext that this object is associated with.- Throws:
IllegalStateException- if not running in an ApplicationContext
-
obtainApplicationContext
Obtain the ApplicationContext for actual use.- Returns:
- the ApplicationContext (never
null) - Throws:
IllegalStateException- in case of no ApplicationContext set- Since:
- 5.0
-
getMessageSourceAccessor
protected final @Nullable MessageSourceAccessor getMessageSourceAccessor() throws IllegalStateExceptionReturn a MessageSourceAccessor for the application context used by this object, for easy message access.- Throws:
IllegalStateException- if not running in an ApplicationContext
-