com.interface21.context
Interface ApplicationContext

All Superinterfaces:
BeanFactory, ListableBeanFactory, MessageSource
All Known Subinterfaces:
WebApplicationContext
All Known Implementing Classes:
AbstractApplicationContext

public interface ApplicationContext
extends MessageSource, ListableBeanFactory

Interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded if the implementation supports this.

The configuration provides:

Version:
$Revision: 1.8 $
Author:
Rod Johnson

Method Summary
 java.lang.String getDisplayName()
          Return a friendly name for this context.
 ContextOptions getOptions()
          Return context options.
 ApplicationContext getParent()
          Return the parent context, or null if there is no parent, and this is the root of the context hierarchy.
 java.io.InputStream getResourceAsStream(java.lang.String location)
          Open an InputStream to the specified resource: Must support fully qualified URLs, e.g.
 java.lang.String getResourceBasePath()
          Return the base path for relatively addressed resources for this application context.
 long getStartupDate()
          Return the timestamp when this context was first loaded
 void publishEvent(ApplicationEvent event)
          Notify all listeners registered with this application of an application event.
 void refresh()
          Load or refresh the persistent representation of the configuration, which might for example be an XML file, properties file or relational database schema.
 java.lang.Object removeSharedObject(java.lang.String key)
          Remove a shared object added with a call to shareObject().
 java.lang.Object sharedObject(java.lang.String key)
          Retrieve a shared object added with a call to shareObject().
 void shareObject(java.lang.String key, java.lang.Object o)
          Put an object available for sharing.
 
Methods inherited from interface com.interface21.context.MessageSource
getMessage, getMessage, getMessage
 
Methods inherited from interface com.interface21.beans.factory.ListableBeanFactory
getBeanDefinitionCount, getBeanDefinitionNames, getBeanDefinitionNames
 
Methods inherited from interface com.interface21.beans.factory.BeanFactory
getAliases, getBean, getBean, isSingleton
 

Method Detail

getParent

public ApplicationContext getParent()
Return the parent context, or null if there is no parent, and this is the root of the context hierarchy.
Returns:
the parent context, or null if there is no parent

getDisplayName

public java.lang.String getDisplayName()
Return a friendly name for this context.
Returns:
a display name for this context

getStartupDate

public long getStartupDate()
Return the timestamp when this context was first loaded
Returns:
the timestamp (ms) when this context was first loaded

getOptions

public ContextOptions getOptions()
Return context options. These control reloading etc.

ApplicationContext implementations may subclass ContextOptions to add additional properties. It must always be a bean.

Returns:
context options (must not be null).

refresh

public void refresh()
             throws ApplicationContextException
Load or refresh the persistent representation of the configuration, which might for example be an XML file, properties file or relational database schema.
Throws:
ApplicationContextException - if the config cannot be loaded

publishEvent

public void publishEvent(ApplicationEvent event)
Notify all listeners registered with this application of an application event. Events may be framework events (such as RequestHandledEvent) or application-specific events.
Parameters:
event - event to publish

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String location)
                                        throws java.io.IOException
Open an InputStream to the specified resource: Note that the safest way to access an absolute file path is via a "file:" URL, as this must be supported by all implementations.

Note: Callers are responsible for closing the input stream.

Parameters:
location - location to the resource
Returns:
InputStream for the specified resource
Throws:
java.io.IOException - exception when opening the specified resource

getResourceBasePath

public java.lang.String getResourceBasePath()
Return the base path for relatively addressed resources for this application context. Normally, this path will be the same as the one that getResourceAsStream uses for evaluating relative paths.

Note that this method returns null if this application context does not have a dedicated base path. Accordingly, getResourceAsStream may not support relative paths at all, or use more than one base path for evaluating relative paths.

Returns:
the resource base path (ending with a separator), or null

shareObject

public void shareObject(java.lang.String key,
                        java.lang.Object o)
Put an object available for sharing. Note that this method is not synchronized. As with Java 2 collections, it's up to calling code to ensure thread safety. Also, this doesn't work in a cluster. It's analogous to putting something in a ServletContext.
Parameters:
key - object key
o - object to put

sharedObject

public java.lang.Object sharedObject(java.lang.String key)
Retrieve a shared object added with a call to shareObject().
Returns:
the object, or null if no object is known under this name (this is not an error).

removeSharedObject

public java.lang.Object removeSharedObject(java.lang.String key)
Remove a shared object added with a call to shareObject(). Does nothing if the object was null.
Parameters:
key - the object was added with
Returns:
the object if it was found, or null.


Rod Johnson and Spring contributors 2001-2003.