org.springframework.osgi.context.support
Class OsgiBundleXmlApplicationContext

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
All Implemented Interfaces:
BeanFactory, DisposableBean, HierarchicalBeanFactory, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, ResourceLoader, ResourcePatternResolver, ConfigurableOsgiBundleApplicationContext, DelegatedExecutionOsgiBundleApplicationContext

public class OsgiBundleXmlApplicationContext
extends AbstractDelegatedExecutionApplicationContext

Stand-alone XML application context, backed by an OSGi bundle.

The configuration location defaults can be overridden via getDefaultConfigLocations(). Note that locations can either denote concrete files like /myfiles/context.xml or Ant-style patterns like /myfiles/*-context.xml (see the AntPathMatcher javadoc for pattern details).

Note: In case of multiple configuration locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra XML file.

This is the main ApplicationContext class for OSGi environments.

Author:
Adrian Colyer, Costin Leau, Andy Piper, Hal Hildebrand

Field Summary
static String DEFAULT_CONFIG_LOCATION
          Default config location for the root context(s)
 
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.osgi.context.ConfigurableOsgiBundleApplicationContext
APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME, BUNDLE_CONTEXT_BEAN_NAME
 
Fields inherited from interface org.springframework.context.ConfigurableApplicationContext
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
 
Constructor Summary
OsgiBundleXmlApplicationContext()
          Creates a new OsgiBundleXmlApplicationContext with no parent.
OsgiBundleXmlApplicationContext(ApplicationContext parent)
          Creates a new OsgiBundleXmlApplicationContext with the given parent context.
OsgiBundleXmlApplicationContext(String[] configLocations)
          Creates a new OsgiBundleXmlApplicationContext with the given configLocations.
OsgiBundleXmlApplicationContext(String[] configLocations, ApplicationContext parent)
          Creates a new OsgiBundleXmlApplicationContext with the given configLocations and parent context.
 
Method Summary
protected  String[] getDefaultConfigLocations()
          Provide default locations for XML files.
protected  void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader)
          Allows subclasses to do custom initialisation here.
protected  void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
          

Loads the bean definitions via an XmlBeanDefinitionReader.

protected  void loadBeanDefinitions(XmlBeanDefinitionReader reader)
          Loads the bean definitions with the given XmlBeanDefinitionReader.
 
Methods inherited from class org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext
completeRefresh, doClose, finishRefresh, getMonitor, normalClose, normalRefresh, refresh, setExecutor, startRefresh
 
Methods inherited from class org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext
destroyBeans, getBundle, getBundleContext, getClassLoader, getConfigLocations, getResource, getResourceByPath, getResourcePatternResolver, getResources, postProcessBeanFactory, setBundleContext, setClassLoader, setConfigLocations, setPublishContextAsService
 
Methods inherited from class org.springframework.context.support.AbstractRefreshableApplicationContext
closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, hasBeanFactory, refreshBeanFactory
 
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, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleDependentBeans, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, prepareBeanFactory, prepareRefresh, publishEvent, registerBeanPostProcessors, registerListeners, registerShutdownHook, setDisplayName, 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.osgi.context.ConfigurableOsgiBundleApplicationContext
getBundle, getBundleContext, setBundleContext, setConfigLocations, setPublishContextAsService
 
Methods inherited from interface org.springframework.context.ConfigurableApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, isActive, registerShutdownHook, setParent
 
Methods inherited from interface org.springframework.context.ApplicationContext
getAutowireCapableBeanFactory, getDisplayName, 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
 

Field Detail

DEFAULT_CONFIG_LOCATION

public static final String DEFAULT_CONFIG_LOCATION
Default config location for the root context(s)

See Also:
Constant Field Values
Constructor Detail

OsgiBundleXmlApplicationContext

public OsgiBundleXmlApplicationContext()
Creates a new OsgiBundleXmlApplicationContext with no parent.


OsgiBundleXmlApplicationContext

public OsgiBundleXmlApplicationContext(ApplicationContext parent)
Creates a new OsgiBundleXmlApplicationContext with the given parent context.

Parameters:
parent - the parent context

OsgiBundleXmlApplicationContext

public OsgiBundleXmlApplicationContext(String[] configLocations)
Creates a new OsgiBundleXmlApplicationContext with the given configLocations.

Parameters:
configLocations - array of configuration resources

OsgiBundleXmlApplicationContext

public OsgiBundleXmlApplicationContext(String[] configLocations,
                                       ApplicationContext parent)
Creates a new OsgiBundleXmlApplicationContext with the given configLocations and parent context.

Parameters:
configLocations - array of configuration resources
parent - the parent context
Method Detail

loadBeanDefinitions

protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
                            throws IOException

Loads the bean definitions via an XmlBeanDefinitionReader.

Specified by:
loadBeanDefinitions in class AbstractRefreshableApplicationContext
Throws:
IOException

initBeanDefinitionReader

protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader)
Allows subclasses to do custom initialisation here.

Parameters:
beanDefinitionReader -

loadBeanDefinitions

protected void loadBeanDefinitions(XmlBeanDefinitionReader reader)
                            throws BeansException,
                                   IOException
Loads the bean definitions with the given XmlBeanDefinitionReader.

The lifecycle of the bean factory is handled by the refreshBeanFactory method; therefore this method is just supposed to load and/or register bean definitions.

Delegates to a ResourcePatternResolver for resolving location patterns into Resource instances.

Throws:
BeansException - in case of bean registration errors
IOException - if the required XML document isn't found
See Also:
AbstractRefreshableApplicationContext.refreshBeanFactory(), AbstractOsgiBundleApplicationContext.getConfigLocations(), AbstractOsgiBundleApplicationContext.getResources(java.lang.String), AbstractOsgiBundleApplicationContext.getResourcePatternResolver()

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.

Overrides:
getDefaultConfigLocations in class AbstractOsgiBundleApplicationContext
Returns:
default XML configuration locations
See Also:
AbstractOsgiBundleApplicationContext.setConfigLocations(java.lang.String[])


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