com.interface21.web.context.support
Class XmlWebApplicationContext

java.lang.Object
  |
  +--com.interface21.context.support.AbstractApplicationContext
        |
        +--com.interface21.context.support.AbstractXmlApplicationContext
              |
              +--com.interface21.ui.context.support.AbstractXmlUiApplicationContext
                    |
                    +--com.interface21.web.context.support.XmlWebApplicationContext
All Implemented Interfaces:
ApplicationContext, BeanFactory, ListableBeanFactory, MessageSource, ThemeSource, WebApplicationContext

public class XmlWebApplicationContext
extends AbstractXmlUiApplicationContext
implements WebApplicationContext

WebApplicationContext implementation that takes configuration from an XML document.

Supports various servlet context init parameters for config file lookup. By default, the lookup occurs in the web app's WEB-INF directory, looking for "WEB-INF/applicationContext.xml" for a root context, and "WEB-INF/test-servlet.xml" for a namespaced context with the name "test-servlet" (like for a DispatcherServlet instance with the web.xml servlet name "test").

Interprets (file) paths as servlet context resources, i.e. as paths beneath the web application root. Thus, absolute paths, i.e. files outside the web app root, should be accessed via "file:" URLs.

Version:
$Revision: 1.14 $
Author:
Rod Johnson, Juergen Hoeller

Field Summary
static java.lang.String CONFIG_LOCATION_PARAM
          Name of servlet context parameter that can specify the config location for the root context, falling back to DEFAULT_CONFIG_LOCATION.
static java.lang.String CONFIG_LOCATION_PREFIX_PARAM
          Name of servlet context parameter that can specify the config location prefix for namespaced contexts, falling back to DEFAULT_CONFIG_LOCATION_PREFIX.
static java.lang.String CONFIG_LOCATION_SUFFIX_PARAM
          Name of servlet context parameter that can specify the config location suffix for namespaced contexts, falling back to DEFAULT_CONFIG_LOCATION_SUFFIX.
static java.lang.String DEFAULT_CONFIG_LOCATION
          Default config location for the root context.
static java.lang.String DEFAULT_CONFIG_LOCATION_PREFIX
          Default prefix for config locations, followed by the namespace
static java.lang.String DEFAULT_CONFIG_LOCATION_SUFFIX
          Default suffix for config locations, following the namespace
 
Fields inherited from class com.interface21.context.support.AbstractApplicationContext
logger, MESSAGE_SOURCE_BEAN_NAME, OPTIONS_BEAN_NAME
 
Fields inherited from interface com.interface21.web.context.WebApplicationContext
WEB_APPLICATION_CONTEXT_ATTRIBUTE_NAME
 
Constructor Summary
XmlWebApplicationContext()
          Create a new root web application context, for use in an entire web application.
XmlWebApplicationContext(ApplicationContext parent, java.lang.String namespace)
          Create a new child WebApplicationContext.
 
Method Summary
protected  java.lang.String getConfigLocation()
           
protected  java.lang.String getConfigLocationForNamespace()
          Initialize the config location for the current namespace.
protected  java.io.InputStream getInputStreamForBeanFactory()
          Open and return the input stream for the bean factory for this namespace.
 java.lang.String getNamespace()
           
 java.lang.String getResourceBasePath()
          This implementation returns the real path of the root directory of the web application that this WebApplicationContext is associated with.
protected  java.io.InputStream getResourceByPath(java.lang.String path)
          This implementation supports file paths beneath the root of the web application.
 javax.servlet.ServletContext getServletContext()
          Return the standard Servlet API ServletContext for this application.
 void setServletContext(javax.servlet.ServletContext servletContext)
          Initialize and attach to the given context.
 java.lang.String toString()
          Show information about this context
 
Methods inherited from class com.interface21.ui.context.support.AbstractXmlUiApplicationContext
getTheme, onRefresh
 
Methods inherited from class com.interface21.context.support.AbstractXmlApplicationContext
getBeanFactory, refreshBeanFactory
 
Methods inherited from class com.interface21.context.support.AbstractApplicationContext
addListener, configureManagedObject, getAliases, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanDefinitionNames, getDisplayName, getMessage, getMessage, getMessage, getOptions, getParent, getResourceAsStream, getStartupDate, isSingleton, publishEvent, refresh, removeSharedObject, setDisplayName, setParent, sharedObject, shareObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.interface21.context.ApplicationContext
getDisplayName, getOptions, getParent, getResourceAsStream, getStartupDate, publishEvent, refresh, removeSharedObject, sharedObject, shareObject
 
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
 
Methods inherited from interface com.interface21.ui.context.ThemeSource
getTheme
 

Field Detail

CONFIG_LOCATION_PREFIX_PARAM

public static final java.lang.String CONFIG_LOCATION_PREFIX_PARAM
Name of servlet context parameter that can specify the config location prefix for namespaced contexts, falling back to DEFAULT_CONFIG_LOCATION_PREFIX.

CONFIG_LOCATION_SUFFIX_PARAM

public static final java.lang.String CONFIG_LOCATION_SUFFIX_PARAM
Name of servlet context parameter that can specify the config location suffix for namespaced contexts, falling back to DEFAULT_CONFIG_LOCATION_SUFFIX.

CONFIG_LOCATION_PARAM

public static final java.lang.String CONFIG_LOCATION_PARAM
Name of servlet context parameter that can specify the config location for the root context, falling back to DEFAULT_CONFIG_LOCATION.

DEFAULT_CONFIG_LOCATION_PREFIX

public static final java.lang.String DEFAULT_CONFIG_LOCATION_PREFIX
Default prefix for config locations, followed by the namespace

DEFAULT_CONFIG_LOCATION_SUFFIX

public static final java.lang.String DEFAULT_CONFIG_LOCATION_SUFFIX
Default suffix for config locations, following the namespace

DEFAULT_CONFIG_LOCATION

public static final java.lang.String DEFAULT_CONFIG_LOCATION
Default config location for the root context.
Constructor Detail

XmlWebApplicationContext

public XmlWebApplicationContext()
Create a new root web application context, for use in an entire web application. This context will be the parent for individual servlet contexts.

XmlWebApplicationContext

public XmlWebApplicationContext(ApplicationContext parent,
                                java.lang.String namespace)
Create a new child WebApplicationContext.
Method Detail

getNamespace

public java.lang.String getNamespace()
Returns:
the namespace of this context, or null if root

setServletContext

public void setServletContext(javax.servlet.ServletContext servletContext)
                       throws ApplicationContextException
Initialize and attach to the given context.
Specified by:
setServletContext in interface WebApplicationContext
Parameters:
servletContext - ServletContext to use to load configuration, and in which this web application context should be set as an attribute.

getServletContext

public final javax.servlet.ServletContext getServletContext()
Description copied from interface: WebApplicationContext
Return the standard Servlet API ServletContext for this application.
Specified by:
getServletContext in interface WebApplicationContext

getConfigLocationForNamespace

protected java.lang.String getConfigLocationForNamespace()
Initialize the config location for the current namespace. This can be overridden in subclasses for custom config lookup.

Default implementation returns the namespace with the default prefix "WEB-INF/" and suffix ".xml", if a namespace is set. For the root context, the "configLocation" servlet context parameter is used, falling back to "WEB-INF/applicationContext.xml" if no parameter is found.

Returns:
the URL or path of the configuration to use

getConfigLocation

protected final java.lang.String getConfigLocation()
Returns:
the URL or path of the configuration

getInputStreamForBeanFactory

protected java.io.InputStream getInputStreamForBeanFactory()
                                                    throws java.io.IOException
Open and return the input stream for the bean factory for this namespace. If namespace is null, return the input stream for the default bean factory.
Overrides:
getInputStreamForBeanFactory in class AbstractXmlApplicationContext
Throws:
java.io.IOException - if the required XML document isn't found

getResourceByPath

protected java.io.InputStream getResourceByPath(java.lang.String path)
                                         throws java.io.IOException
This implementation supports file paths beneath the root of the web application.
Overrides:
getResourceByPath in class AbstractApplicationContext
Following copied from class: com.interface21.context.support.AbstractApplicationContext
Parameters:
path - path to the resource
Returns:
InputStream for the specified resource, can be null if not found (instead of throwing an exception)
Throws:
java.io.IOException - exception when opening the specified resource

getResourceBasePath

public java.lang.String getResourceBasePath()
This implementation returns the real path of the root directory of the web application that this WebApplicationContext is associated with.
Specified by:
getResourceBasePath in interface ApplicationContext
Overrides:
getResourceBasePath in class AbstractApplicationContext
See Also:
ApplicationContext.getResourceBasePath(), ServletContext.getRealPath(java.lang.String)

toString

public java.lang.String toString()
Description copied from class: AbstractApplicationContext
Show information about this context
Overrides:
toString in class AbstractApplicationContext
Returns:
diagnostic information


Rod Johnson and Spring contributors 2001-2003.