org.springframework.osgi.web.context.support
Class OsgiBundleXmlWebApplicationContext

java.lang.Object
  extended by org.springframework.core.io.DefaultResourceLoader
      extended by org.springframework.context.support.AbstractApplicationContext
          extended by org.springframework.context.support.AbstractRefreshableApplicationContext
              extended by org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext
                  extended by org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext
                      extended by org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext
                          extended by org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext
All Implemented Interfaces:
BeanFactory, DisposableBean, HierarchicalBeanFactory, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, ResourceLoader, ResourcePatternResolver, ConfigurableOsgiBundleApplicationContext, DelegatedExecutionOsgiBundleApplicationContext, ThemeSource, ConfigurableWebApplicationContext, WebApplicationContext

public class OsgiBundleXmlWebApplicationContext
extends OsgiBundleXmlApplicationContext
implements ConfigurableWebApplicationContext, ThemeSource

OSGi variant for XmlWebApplicationContext. The implementation mandates that the OSGi bundle context is either set (AbstractOsgiBundleApplicationContext.setBundleContext(BundleContext) before setting the ServletContext or that the given ServletContext contains the BundleContext as an attribute under BUNDLE_CONTEXT_ATTRIBUTE (org.springframework.osgi.web.org.osgi.framework.BundleContext).

Additionally, this implementation replaces the ServletContext resource loading with an OSGi specific loader which provides equivalent functionality.

The OSGi service published for this application context contains the namespace property (if non-null) under org.springframework.web.context.namespace property.

Author:
Costin Leau
See Also:
XmlWebApplicationContext, OsgiBundleResourceLoader, OsgiBundleXmlApplicationContext

Field Summary
static String BUNDLE_CONTEXT_ATTRIBUTE
          ServletContext attribute for retrieving the bundle context
 
Fields inherited from class org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext
DEFAULT_CONFIG_LOCATION
 
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
 
Fields inherited from interface org.springframework.web.context.WebApplicationContext
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, SCOPE_GLOBAL_SESSION, SCOPE_REQUEST, SCOPE_SESSION
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Fields inherited from interface org.springframework.context.ConfigurableApplicationContext
CONFIG_LOCATION_DELIMITERS, LOAD_TIME_WEAVER_BEAN_NAME
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Fields inherited from interface org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext
APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME, BUNDLE_CONTEXT_BEAN_NAME
 
Constructor Summary
OsgiBundleXmlWebApplicationContext()
           
 
Method Summary
protected  void customizeApplicationContextServiceProperties(Map serviceProperties)
          Customizes the properties of the application context OSGi service. Additionally, this implementation published the context namespace under org.springframework.context.web.namespace property.
protected  String[] getDefaultConfigLocations()
          Provide default locations for XML files. Returns the default location for the root context.
 String getNamespace()
           
 ServletConfig getServletConfig()
           
 ServletContext getServletContext()
           
 Theme getTheme(String themeName)
           
protected  void onRefresh()
           Initializes the theme capability.
protected  void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
           Registers request/session scopes, a ServletContextAwareProcessor, etc.
 void setConfigLocation(String location)
           Sets the config locations for this application context in init-param style, i.e. with distinct locations separated by commas, semicolons or whitespace.
 void setNamespace(String namespace)
           
 void setServletConfig(ServletConfig servletConfig)
           Additionally, it also sets the context namespace if it's not initialized (null).
 void setServletContext(ServletContext servletContext)
           Additionally, if the BundleContext is not set, it is looked up under BUNDLE_CONTEXT_ATTRIBUTE.
 
Methods inherited from class org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext
getConfigLocations, initBeanDefinitionReader, loadBeanDefinitions, loadBeanDefinitions
 
Methods inherited from class org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext
completeRefresh, doClose, finishRefresh, getContextClassLoader, getDelegatedEventMulticaster, getMonitor, normalClose, normalRefresh, refresh, setContextClassLoaderProvider, setDelegatedEventMulticaster, setDelegatedEventMulticaster, setExecutor, startRefresh
 
Methods inherited from class org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext
createResourcePatternResolver, destroyBeans, getBundle, getBundleContext, getClassLoader, getResource, getResourceByPath, getResourcePatternResolver, getResources, setBundleContext, setClassLoader, setConfigLocations, setPublishContextAsService
 
Methods inherited from class org.springframework.context.support.AbstractRefreshableApplicationContext
closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, hasBeanFactory, refreshBeanFactory, setAllowBeanDefinitionOverriding, setAllowCircularReferences
 
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, addListener, cancelRefresh, close, containsBean, containsBeanDefinition, containsLocalBean, destroy, finishBeanFactoryInitialization, getAliases, getApplicationListeners, getAutowireCapableBeanFactory, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getDisplayName, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getType, initApplicationEventMulticaster, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, obtainFreshBeanFactory, onClose, prepareBeanFactory, prepareRefresh, publishEvent, registerBeanPostProcessors, registerListeners, registerShutdownHook, setDisplayName, setId, setParent, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.web.context.ConfigurableWebApplicationContext
getConfigLocations, setConfigLocations
 
Methods inherited from interface org.springframework.context.ApplicationContext
getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
 
Methods inherited from interface org.springframework.beans.factory.ListableBeanFactory
containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
 
Methods inherited from interface org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
 
Methods inherited from interface org.springframework.context.MessageSource
getMessage, getMessage, getMessage
 
Methods inherited from interface org.springframework.context.ApplicationEventPublisher
publishEvent
 
Methods inherited from interface org.springframework.core.io.support.ResourcePatternResolver
getResources
 
Methods inherited from interface org.springframework.core.io.ResourceLoader
getClassLoader, getResource
 
Methods inherited from interface org.springframework.context.ConfigurableApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, isActive, refresh, registerShutdownHook, setParent
 
Methods inherited from interface org.springframework.context.ApplicationContext
getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
 
Methods inherited from interface org.springframework.beans.factory.ListableBeanFactory
containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
 
Methods inherited from interface org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
 
Methods inherited from interface org.springframework.context.MessageSource
getMessage, getMessage, getMessage
 
Methods inherited from interface org.springframework.context.ApplicationEventPublisher
publishEvent
 
Methods inherited from interface org.springframework.core.io.support.ResourcePatternResolver
getResources
 
Methods inherited from interface org.springframework.core.io.ResourceLoader
getClassLoader, getResource
 
Methods inherited from interface org.springframework.context.Lifecycle
isRunning, start, stop
 
Methods inherited from interface org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext
getBundle, getBundleContext, setBundleContext, setConfigLocations, setPublishContextAsService
 

Field Detail

BUNDLE_CONTEXT_ATTRIBUTE

public static final String BUNDLE_CONTEXT_ATTRIBUTE
ServletContext attribute for retrieving the bundle context

Constructor Detail

OsgiBundleXmlWebApplicationContext

public OsgiBundleXmlWebApplicationContext()
Method Detail

setServletContext

public void setServletContext(ServletContext servletContext)
Additionally, if the BundleContext is not set, it is looked up under BUNDLE_CONTEXT_ATTRIBUTE.

Specified by:
setServletContext in interface ConfigurableWebApplicationContext

getServletContext

public ServletContext getServletContext()
Specified by:
getServletContext in interface WebApplicationContext

setServletConfig

public void setServletConfig(ServletConfig servletConfig)
Additionally, it also sets the context namespace if it's not initialized (null).

Specified by:
setServletConfig in interface ConfigurableWebApplicationContext

getServletConfig

public ServletConfig getServletConfig()
Specified by:
getServletConfig in interface ConfigurableWebApplicationContext

setNamespace

public void setNamespace(String namespace)
Specified by:
setNamespace in interface ConfigurableWebApplicationContext

getNamespace

public String getNamespace()
Specified by:
getNamespace in interface ConfigurableWebApplicationContext

postProcessBeanFactory

protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Registers request/session scopes, a ServletContextAwareProcessor, etc.

Overrides:
postProcessBeanFactory in class AbstractOsgiBundleApplicationContext

customizeApplicationContextServiceProperties

protected void customizeApplicationContextServiceProperties(Map serviceProperties)
Customizes the properties of the application context OSGi service. This method is called only if the application context will be published as an OSGi service.

The default implementation stores the bundle symbolic name under Constants.BUNDLE_SYMBOLICNAME and ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME and the bundle version under Constants.BUNDLE_VERSION property. Can be overridden by subclasses to add more properties if needed (for example for web applications where multiple application contexts are available inside the same bundle). Additionally, this implementation published the context namespace under org.springframework.context.web.namespace property.

Overrides:
customizeApplicationContextServiceProperties in class AbstractOsgiBundleApplicationContext
Parameters:
serviceProperties - service properties map (can be casted to Dictionary)

onRefresh

protected void onRefresh()
Initializes the theme capability.

Overrides:
onRefresh in class AbstractApplicationContext

getTheme

public Theme getTheme(String themeName)
Specified by:
getTheme in interface ThemeSource

getDefaultConfigLocations

protected String[] getDefaultConfigLocations()
Provide default locations for XML files. This implementation returns META-INF/spring/*.xml relying on the default resource environment for actual localisation. By default, the bundle space will be used for locating the resources.

Note: Instead of overriding this method, consider using the Spring-DM specific header inside your manifest bundle. Returns the default location for the root context. Default values are "/WEB-INF/applicationContext.xml", and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

Overrides:
getDefaultConfigLocations in class OsgiBundleXmlApplicationContext
Returns:
default XML configuration locations
See Also:
XmlWebApplicationContext.getDefaultConfigLocations(), XmlWebApplicationContext.DEFAULT_CONFIG_LOCATION

setConfigLocation

public void setConfigLocation(String location)
Sets the config locations for this application context in init-param style, i.e. with distinct locations separated by commas, semicolons or whitespace.

If not set, the implementation may use a default as appropriate.

Specified by:
setConfigLocation in interface ConfigurableWebApplicationContext
See Also:
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS


Copyright © 2006-2009 Spring Framework. All Rights Reserved.