org.springframework.osgi.context.support
Class AbstractOsgiBundleApplicationContext

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
All Implemented Interfaces:
BeanFactory, DisposableBean, HierarchicalBeanFactory, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, ResourceLoader, ResourcePatternResolver, ConfigurableOsgiBundleApplicationContext
Direct Known Subclasses:
org.springframework.osgi.internal.context.support.AbstractDelegatedExecutionApplicationContext

public abstract class AbstractOsgiBundleApplicationContext
extends AbstractRefreshableApplicationContext
implements ConfigurableOsgiBundleApplicationContext

AbstractRefreshableApplicationContext subclass that implements the ConfigurableOsgiApplicationContext interface for OSGi environments. Pre-implements a "configLocation" property, to be populated through the ConfigurableOsgiApplicationContext interface on OSGi bundle startup.

This class is as easy to subclass as AbstractRefreshableApplicationContext: All you need to implement is the loadBeanDefinitions method; see the superclass javadoc for details. Note that implementations are supposed to load bean definitions from the files specified by the locations returned by the getConfigLocations method.

Interprets resource paths as OSGi bundle resources (either from the bundle classpath or OSGi entries).

In addition to the special beans detected by AbstractApplicationContext, this class registers the BundleContextAwareProcessor for processing beans that implement the BundleContextAware interface.

This application context offers the OSGi-specific, "bundle" scope. See OsgiBundleScope.

Note that OsgiApplicationContext implementations are generally supposed to configure themselves based on the configuration received through the ConfigurableOsgiBundleApplicationContext interface. In contrast, a standalone application context might allow for configuration in custom startup code (for example, GenericApplicationContext).

Author:
Costin Leau, Adrian Colyer, Hal Hildebrand

Field Summary
 
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.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Constructor Summary
AbstractOsgiBundleApplicationContext()
           
 
Method Summary
protected  void cleanOsgiBundleScope(ConfigurableListableBeanFactory beanFactory)
           
protected  ClassLoader createBundleClassLoader(Bundle bundle)
          Create the classloader that delegates to the underlying OSGi bundle.
protected  void destroyBeans()
           
protected  void doClose()
           
 Bundle getBundle()
          Return the OSGi bundle for this application context.
 BundleContext getBundleContext()
          Get the OSGi BundleContext for this application context
 String getBundleSymbolicName()
           
 ClassLoader getClassLoader()
           
 String[] getConfigLocations()
           
protected  String[] getDefaultConfigLocations()
          Return the default config locations to use, for the case where no explicit config locations have been specified.
 Resource getResource(String location)
           
protected  Resource getResourceByPath(String path)
           
protected  ResourcePatternResolver getResourcePatternResolver()
          This implementation supports pattern matching inside the OSGi bundle.
 Resource[] getResources(String locationPattern)
           
protected  ConfigurableListableBeanFactory obtainFreshBeanFactory()
           
protected  void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
          Register post processor for BeanContextAware beans.
protected  void publishContextAsOsgiServiceIfNecessary()
          Publish the application context as an OSGi service.
 void setBundleContext(BundleContext bundleContext)
          Set the bundleContext for this application context.
 void setClassLoader(ClassLoader classLoader)
           
 void setConfigLocations(String[] configLocations)
          Set the config locations for this OSGi bundle application context.
 void setPublishContextAsService(boolean publishContextAsService)
          Publish the application context as an OSGi service.
 
Methods inherited from class org.springframework.context.support.AbstractRefreshableApplicationContext
closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, loadBeanDefinitions, refreshBeanFactory
 
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, containsLocalBean, destroy, finishBeanFactoryInitialization, finishRefresh, 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, onClose, onRefresh, prepareBeanFactory, prepareRefresh, publishEvent, refresh, 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.context.ConfigurableApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, isActive, refresh, 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.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.context.Lifecycle
isRunning, start, stop
 

Constructor Detail

AbstractOsgiBundleApplicationContext

public AbstractOsgiBundleApplicationContext()
Method Detail

setBundleContext

public void setBundleContext(BundleContext bundleContext)
Set the bundleContext for this application context. Will automatically determine the bundle, create a new ResourceLoader (and set its classloader to a custom implementation that will delegate the calls to the bundle).

Specified by:
setBundleContext in interface ConfigurableOsgiBundleApplicationContext
See Also:
ConfigurableApplicationContext.refresh()

getBundleContext

public BundleContext getBundleContext()
Get the OSGi BundleContext for this application context

Specified by:
getBundleContext in interface ConfigurableOsgiBundleApplicationContext
Returns:
See Also:
ConfigurableOsgiBundleApplicationContext.getBundle()

getBundle

public Bundle getBundle()
Description copied from interface: ConfigurableOsgiBundleApplicationContext
Return the OSGi bundle for this application context.

Specified by:
getBundle in interface ConfigurableOsgiBundleApplicationContext
Returns:
the Bundle for this OSGi bundle application context.

setConfigLocations

public void setConfigLocations(String[] configLocations)
Description copied from interface: ConfigurableOsgiBundleApplicationContext
Set the config locations for this OSGi bundle application context. If not set, the implementation is supposed to use a default for the given namespace.

Specified by:
setConfigLocations in interface ConfigurableOsgiBundleApplicationContext

getConfigLocations

public String[] getConfigLocations()

doClose

protected void doClose()
Overrides:
doClose in class AbstractApplicationContext

destroyBeans

protected void destroyBeans()
Overrides:
destroyBeans in class AbstractApplicationContext

getDefaultConfigLocations

protected String[] getDefaultConfigLocations()
Return the default config locations to use, for the case where no explicit config locations have been specified.

Default implementation returns null, requiring explicit config locations.

See Also:
setConfigLocations(java.lang.String[])

postProcessBeanFactory

protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
                               throws BeansException
Register post processor for BeanContextAware beans.

Overrides:
postProcessBeanFactory in class AbstractApplicationContext
Throws:
BeansException

obtainFreshBeanFactory

protected ConfigurableListableBeanFactory obtainFreshBeanFactory()
Overrides:
obtainFreshBeanFactory in class AbstractApplicationContext

cleanOsgiBundleScope

protected void cleanOsgiBundleScope(ConfigurableListableBeanFactory beanFactory)

publishContextAsOsgiServiceIfNecessary

protected void publishContextAsOsgiServiceIfNecessary()
Publish the application context as an OSGi service. The method internally takes care of parsing the bundle headers and determined if actual publishing is required or not.


getBundleSymbolicName

public String getBundleSymbolicName()

getResourcePatternResolver

protected ResourcePatternResolver getResourcePatternResolver()
This implementation supports pattern matching inside the OSGi bundle.

Overrides:
getResourcePatternResolver in class AbstractApplicationContext
See Also:
OsgiBundleResourcePatternResolver

getClassLoader

public ClassLoader getClassLoader()
Specified by:
getClassLoader in interface ResourceLoader
Overrides:
getClassLoader in class DefaultResourceLoader

getResource

public Resource getResource(String location)
Specified by:
getResource in interface ResourceLoader
Overrides:
getResource in class DefaultResourceLoader

getResources

public Resource[] getResources(String locationPattern)
                        throws IOException
Specified by:
getResources in interface ResourcePatternResolver
Overrides:
getResources in class AbstractApplicationContext
Throws:
IOException

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Overrides:
setClassLoader in class DefaultResourceLoader

getResourceByPath

protected Resource getResourceByPath(String path)
Overrides:
getResourceByPath in class DefaultResourceLoader

setPublishContextAsService

public void setPublishContextAsService(boolean publishContextAsService)
Description copied from interface: ConfigurableOsgiBundleApplicationContext
Publish the application context as an OSGi service.

Specified by:
setPublishContextAsService in interface ConfigurableOsgiBundleApplicationContext
Parameters:
publishContextAsService - The publishContextAsService to set.

createBundleClassLoader

protected ClassLoader createBundleClassLoader(Bundle bundle)
Create the classloader that delegates to the underlying OSGi bundle.

Parameters:
bundle -
Returns:


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