com.interface21.web.context.support
Class WebApplicationContextUtils

java.lang.Object
  |
  +--com.interface21.web.context.support.WebApplicationContextUtils

public abstract class WebApplicationContextUtils
extends java.lang.Object

Utilities common to all WebApplicationContext implementations.

Features a convenient method to retrieve the WebApplicationContext for a given ServletContext. This is e.g. useful to access a Spring context from within Struts actions.

Version:
$Id: WebApplicationContextUtils.java,v 1.6 2003/05/28 16:39:15 jhoeller Exp $
Author:
Rod Johnson

Field Summary
static java.lang.String CONFIG_OBJECT_PREFIX
          Config object prefix in bean names
 
Constructor Summary
WebApplicationContextUtils()
           
 
Method Summary
static java.lang.Object getConfigObject(javax.servlet.ServletContext sc, java.lang.String name, java.lang.Class requiredClass)
          Retrieve a config object by name.
static WebApplicationContext getWebApplicationContext(javax.servlet.ServletContext sc)
          Find the root WebApplicationContext for this web app.
static void publishConfigObjects(WebApplicationContext wac)
          Initialize all config objects if necessary, and publish them as ServletContext attributes.
static void publishWebApplicationContext(WebApplicationContext wac)
          Expose the given WebApplcicationContext as an attribute of the ServletContext it references.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_OBJECT_PREFIX

public static final java.lang.String CONFIG_OBJECT_PREFIX
Config object prefix in bean names
Constructor Detail

WebApplicationContextUtils

public WebApplicationContextUtils()
Method Detail

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(javax.servlet.ServletContext sc)
Find the root WebApplicationContext for this web app.
Parameters:
sc - ServletContext to find the application context for
Returns:
the WebApplicationContext for this web app, or null if none

publishWebApplicationContext

public static void publishWebApplicationContext(WebApplicationContext wac)
Expose the given WebApplcicationContext as an attribute of the ServletContext it references.

getConfigObject

public static java.lang.Object getConfigObject(javax.servlet.ServletContext sc,
                                               java.lang.String name,
                                               java.lang.Class requiredClass)
                                        throws javax.servlet.ServletException
Retrieve a config object by name. This will be sought in the ServletContext, where it must have been placed by config. Can only be called after the ServletContext is available. This means it can't be called in a subclass constructor.
Parameters:
sc - current ServletContext
name - name of the config object
requiredClass - type of the config object
Throws:
javax.servlet.ServletException - if the object isn't found, or isn't of the required type.

publishConfigObjects

public static void publishConfigObjects(WebApplicationContext wac)
                                 throws ApplicationContextException
Initialize all config objects if necessary, and publish them as ServletContext attributes.
Parameters:
wac - WebApplicationContext whose config objects should be published


Rod Johnson and Spring contributors 2001-2003.