public abstract class AbstractOsgiBundleApplicationContext extends org.springframework.context.support.AbstractRefreshableApplicationContext implements ConfigurableOsgiBundleApplicationContext
AbstractRefreshableApplicationContext
subclass that implements the
ConfigurableOsgiBundleApplicationContext
interface for OSGi environments. Pre-implements a
configLocation
property, to be populated through the ConfigurableOsgiApplicationContext
interface after OSGi bundle startup.
This class is as easy to subclass as AbstractRefreshableApplicationContext
(see the javadoc for
details): all you need to implement is the loadBeanDefinitions
method Note that implementations are
supposed to load bean definitions from the files specified by the locations returned by
getConfigLocations
method.
In addition to the special beans detected by AbstractApplicationContext
, this class registers the
BundleContextAwareProcessor
for processing beans that implement the BundleContextAware
interface. Also it interprets resource paths as OSGi bundle resources (either from the bundle class space, bundle
space or jar space).
This application context implementation offers the OSGi-specific, bundle scope.
Note: OsgiApplicationContext
implementations are generally supposed to configure
themselves based on the configuration received through the ConfigurableOsgiBundleApplicationContext
interface. In contrast, a stand-alone application context might allow for configuration in custom startup code (for
example, GenericApplicationContext
).
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME, BUNDLE_BEAN_NAME, BUNDLE_CONTEXT_BEAN_NAME, SPRING_DM_APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME
CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
Constructor and Description |
---|
AbstractOsgiBundleApplicationContext()
Creates a new
AbstractOsgiBundleApplicationContext with no parent. |
AbstractOsgiBundleApplicationContext(org.springframework.context.ApplicationContext parent)
Creates a new
AbstractOsgiBundleApplicationContext with the given parent context. |
Modifier and Type | Method and Description |
---|---|
protected org.springframework.core.io.support.ResourcePatternResolver |
createResourcePatternResolver()
Creates an OSGi specific resource pattern resolver.
|
protected void |
customizeApplicationContextServiceProperties(Map<Object,Object> serviceProperties)
Customizes the properties of the application context OSGi service.
|
protected void |
destroyBeans() |
protected void |
doClose()
Unregister the ApplicationContext OSGi service (in case there is any).
|
protected void |
finishRefresh() |
org.osgi.framework.Bundle |
getBundle()
Returns the OSGi
Bundle for this application context. |
org.osgi.framework.BundleContext |
getBundleContext()
Return the
BundleContext for this application context. |
ClassLoader |
getClassLoader() |
String[] |
getConfigLocations()
Returns this application context configuration locations.
|
protected String[] |
getDefaultConfigLocations()
Returns the default configuration locations to use, for the case where no explicit configuration locations have
been specified.
|
org.springframework.core.io.Resource |
getResource(String location) |
protected org.springframework.core.io.Resource |
getResourceByPath(String path) |
protected org.springframework.core.io.support.ResourcePatternResolver |
getResourcePatternResolver()
This implementation supports pattern matching inside the OSGi bundle.
|
org.springframework.core.io.Resource[] |
getResources(String locationPattern) |
protected void |
postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) |
protected void |
prepareRefresh() |
void |
setBundleContext(org.osgi.framework.BundleContext bundleContext)
Sets the
BundleContext used by this OSGi bundle
application context. |
void |
setClassLoader(ClassLoader classLoader) |
void |
setConfigLocations(String[] configLocations)
Sets the config locations for this OSGi bundle application context.
|
void |
setPublishContextAsService(boolean publishContextAsService)
Indicates whether this application context should be publish as an OSGi
service if successfully started.
|
cancelRefresh, closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, hasBeanFactory, loadBeanDefinitions, refreshBeanFactory, setAllowBeanDefinitionOverriding, setAllowCircularReferences
addApplicationListener, addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, findAnnotationOnBean, finishBeanFactoryInitialization, getAliases, getApplicationListeners, getAutowireCapableBeanFactory, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, prepareBeanFactory, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, setDisplayName, setEnvironment, setId, setParent, start, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, getEnvironment, isActive, refresh, registerShutdownHook, setEnvironment, setId, setParent
getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation
containsLocalBean, getParentBeanFactory
containsBean, getAliases, getBean, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
public AbstractOsgiBundleApplicationContext()
AbstractOsgiBundleApplicationContext
with no parent.public AbstractOsgiBundleApplicationContext(org.springframework.context.ApplicationContext parent)
AbstractOsgiBundleApplicationContext
with the given parent context.parent
- the parent contextpublic void setBundleContext(org.osgi.framework.BundleContext bundleContext)
BundleContext
used by this OSGi bundle
application context. Normally it's the BundleContext
in
which the context runs.
Does not cause an initialization of the context: ConfigurableApplicationContext.refresh()
needs
to be called after the setting of all configuration properties.
ResourceLoader
(and set its
ClassLoader
(if none is set already) to a custom implementation that will delegate the calls to the
bundle).setBundleContext
in interface ConfigurableOsgiBundleApplicationContext
bundleContext
- the BundleContext
used by this
application context.ConfigurableApplicationContext.refresh()
public org.osgi.framework.BundleContext getBundleContext()
ConfigurableOsgiBundleApplicationContext
BundleContext
for this application context.
This method is offered as a helper since as of OSGi 4.1, the bundle
context can be discovered directly from the given bundle.getBundleContext
in interface ConfigurableOsgiBundleApplicationContext
BundleContext
in which this application
context runsConfigurableOsgiBundleApplicationContext.getBundle()
public org.osgi.framework.Bundle getBundle()
ConfigurableOsgiBundleApplicationContext
Bundle
for this application context.getBundle
in interface ConfigurableOsgiBundleApplicationContext
Bundle
for this OSGi bundle application
context.public void setConfigLocations(String[] configLocations)
ConfigurableOsgiBundleApplicationContext
setConfigLocations
in interface ConfigurableOsgiBundleApplicationContext
configLocations
- array of configuration locationspublic String[] getConfigLocations()
getDefaultConfigLocations()
protected void doClose()
doClose
in class org.springframework.context.support.AbstractApplicationContext
protected void destroyBeans()
destroyBeans
in class org.springframework.context.support.AbstractApplicationContext
protected String[] getDefaultConfigLocations()
Default implementation returns null
, requiring explicit configuration locations.
setConfigLocations(java.lang.String[])
protected void prepareRefresh()
prepareRefresh
in class org.springframework.context.support.AbstractApplicationContext
protected void finishRefresh()
finishRefresh
in class org.springframework.context.support.AbstractApplicationContext
protected void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
postProcessBeanFactory
in class org.springframework.context.support.AbstractApplicationContext
org.springframework.beans.BeansException
protected void customizeApplicationContextServiceProperties(Map<Object,Object> serviceProperties)
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).serviceProperties
- service properties map (can be casted to Dictionary
)protected org.springframework.core.io.support.ResourcePatternResolver createResourcePatternResolver()
protected org.springframework.core.io.support.ResourcePatternResolver getResourcePatternResolver()
getResourcePatternResolver
in class org.springframework.context.support.AbstractApplicationContext
OsgiBundleResourcePatternResolver
public ClassLoader getClassLoader()
getClassLoader
in interface org.springframework.core.io.ResourceLoader
getClassLoader
in class org.springframework.core.io.DefaultResourceLoader
public org.springframework.core.io.Resource getResource(String location)
getResource
in interface org.springframework.core.io.ResourceLoader
getResource
in class org.springframework.core.io.DefaultResourceLoader
public org.springframework.core.io.Resource[] getResources(String locationPattern) throws IOException
getResources
in interface org.springframework.core.io.support.ResourcePatternResolver
getResources
in class org.springframework.context.support.AbstractApplicationContext
IOException
public void setClassLoader(ClassLoader classLoader)
setClassLoader
in class org.springframework.core.io.DefaultResourceLoader
protected org.springframework.core.io.Resource getResourceByPath(String path)
getResourceByPath
in class org.springframework.core.io.DefaultResourceLoader
public void setPublishContextAsService(boolean publishContextAsService)
ConfigurableOsgiBundleApplicationContext
true
.setPublishContextAsService
in interface ConfigurableOsgiBundleApplicationContext
publishContextAsService
- true if the application context should be
published as a service, false otherwiseCopyright © 2006-2013. All Rights Reserved.