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).
| Modifier and Type | Field and Description |
|---|---|
private java.security.AccessControlContext |
acc |
private org.osgi.framework.Bundle |
bundle
OSGi bundle - determined from the BundleContext
|
private org.osgi.framework.BundleContext |
bundleContext
OSGi bundle context
|
private java.lang.ClassLoader |
classLoader
class loader used for loading the beans
|
private java.lang.String[] |
configLocations
Path to configuration files
|
private static java.lang.String |
EXPORTER_IMPORTER_DEPENDENCY_MANAGER |
private org.springframework.core.io.support.ResourcePatternResolver |
osgiPatternResolver
Internal pattern resolver.
|
private boolean |
publishContextAsService
Should context be published as an OSGi service?
|
private org.osgi.framework.ServiceRegistration |
serviceRegistration
Used for publishing the app context
|
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAMEAPPLICATION_CONTEXT_SERVICE_PROPERTY_NAME, BUNDLE_BEAN_NAME, BUNDLE_CONTEXT_BEAN_NAME, SPRING_DM_APPLICATION_CONTEXT_SERVICE_PROPERTY_NAMECONFIG_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 |
|---|---|
private void |
addPredefinedBean(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
java.lang.String name,
java.lang.Object value) |
private void |
cleanOsgiBundleScope(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) |
private java.lang.ClassLoader |
createBundleClassLoader(org.osgi.framework.Bundle bundle)
Create the class loader that delegates to the underlying OSGi bundle.
|
protected org.springframework.core.io.support.ResourcePatternResolver |
createResourcePatternResolver()
Creates an OSGi specific resource pattern resolver.
|
protected void |
customizeApplicationContextServiceProperties(java.util.Map<java.lang.Object,java.lang.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).
|
private void |
enforceExporterImporterDependency(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Takes care of enforcing the relationship between exporter and importers.
|
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. |
private java.lang.String |
getBundleSymbolicName() |
java.lang.ClassLoader |
getClassLoader() |
java.lang.String[] |
getConfigLocations()
Returns this application context configuration locations.
|
protected java.lang.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(java.lang.String location) |
protected org.springframework.core.io.Resource |
getResourceByPath(java.lang.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(java.lang.String locationPattern) |
protected void |
postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) |
protected void |
prepareRefresh() |
private void |
publishContextAsOsgiServiceIfNecessary()
Publishes the application context as an OSGi service.
|
private void |
registerPropertyEditors(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Register OSGi-specific
PropertyEditors. |
void |
setBundleContext(org.osgi.framework.BundleContext bundleContext)
Sets the
BundleContext used by this OSGi bundle
application context. |
void |
setClassLoader(java.lang.ClassLoader classLoader) |
void |
setConfigLocations(java.lang.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.
|
private void |
unpublishContextAsOsgiService()
Unpublishes the application context OSGi service.
|
cancelRefresh, closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, hasBeanFactory, loadBeanDefinitions, refreshBeanFactory, setAllowBeanDefinitionOverriding, setAllowCircularReferencesaddApplicationListener, addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, findAnnotationOnBean, finishBeanFactoryInitialization, getAliases, getApplicationListeners, getApplicationName, 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, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddApplicationListener, addBeanFactoryPostProcessor, close, getBeanFactory, getEnvironment, isActive, refresh, registerShutdownHook, setEnvironment, setId, setParentgetApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDatecontainsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotationcontainsLocalBean, getParentBeanFactorycontainsBean, getAliases, getBean, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatchprivate static final java.lang.String EXPORTER_IMPORTER_DEPENDENCY_MANAGER
private org.osgi.framework.Bundle bundle
private org.osgi.framework.BundleContext bundleContext
private java.lang.String[] configLocations
private org.osgi.framework.ServiceRegistration serviceRegistration
private boolean publishContextAsService
private java.lang.ClassLoader classLoader
private org.springframework.core.io.support.ResourcePatternResolver osgiPatternResolver
private volatile java.security.AccessControlContext acc
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 ConfigurableOsgiBundleApplicationContextbundleContext - the BundleContext used by this
application context.ConfigurableApplicationContext.refresh()public org.osgi.framework.BundleContext getBundleContext()
ConfigurableOsgiBundleApplicationContextBundleContext 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 ConfigurableOsgiBundleApplicationContextBundleContext in which this application
context runsConfigurableOsgiBundleApplicationContext.getBundle()public org.osgi.framework.Bundle getBundle()
ConfigurableOsgiBundleApplicationContextBundle for this application context.getBundle in interface ConfigurableOsgiBundleApplicationContextBundle for this OSGi bundle application
context.public void setConfigLocations(java.lang.String[] configLocations)
ConfigurableOsgiBundleApplicationContextsetConfigLocations in interface ConfigurableOsgiBundleApplicationContextconfigLocations - array of configuration locationspublic java.lang.String[] getConfigLocations()
getDefaultConfigLocations()protected void doClose()
doClose in class org.springframework.context.support.AbstractApplicationContextprotected void destroyBeans()
destroyBeans in class org.springframework.context.support.AbstractApplicationContextprotected java.lang.String[] getDefaultConfigLocations()
Default implementation returns null, requiring explicit configuration locations.
setConfigLocations(java.lang.String[])protected void prepareRefresh()
prepareRefresh in class org.springframework.context.support.AbstractApplicationContextprotected void finishRefresh()
finishRefresh in class org.springframework.context.support.AbstractApplicationContextprotected void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
throws org.springframework.beans.BeansException
postProcessBeanFactory in class org.springframework.context.support.AbstractApplicationContextorg.springframework.beans.BeansExceptionprivate void addPredefinedBean(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
java.lang.String name,
java.lang.Object value)
private void enforceExporterImporterDependency(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
beanFactory - private void registerPropertyEditors(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
PropertyEditors.beanFactory - beanFactory used for registration.private void cleanOsgiBundleScope(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
private void publishContextAsOsgiServiceIfNecessary()
private void unpublishContextAsOsgiService()
protected void customizeApplicationContextServiceProperties(java.util.Map<java.lang.Object,java.lang.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)private java.lang.String getBundleSymbolicName()
protected org.springframework.core.io.support.ResourcePatternResolver createResourcePatternResolver()
protected org.springframework.core.io.support.ResourcePatternResolver getResourcePatternResolver()
getResourcePatternResolver in class org.springframework.context.support.AbstractApplicationContextOsgiBundleResourcePatternResolverpublic java.lang.ClassLoader getClassLoader()
getClassLoader in interface org.springframework.core.io.ResourceLoadergetClassLoader in class org.springframework.core.io.DefaultResourceLoaderpublic org.springframework.core.io.Resource getResource(java.lang.String location)
getResource in interface org.springframework.core.io.ResourceLoadergetResource in class org.springframework.core.io.DefaultResourceLoaderpublic org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
throws java.io.IOException
getResources in interface org.springframework.core.io.support.ResourcePatternResolvergetResources in class org.springframework.context.support.AbstractApplicationContextjava.io.IOExceptionpublic void setClassLoader(java.lang.ClassLoader classLoader)
setClassLoader in class org.springframework.core.io.DefaultResourceLoaderprotected org.springframework.core.io.Resource getResourceByPath(java.lang.String path)
getResourceByPath in class org.springframework.core.io.DefaultResourceLoaderpublic void setPublishContextAsService(boolean publishContextAsService)
ConfigurableOsgiBundleApplicationContexttrue.setPublishContextAsService in interface ConfigurableOsgiBundleApplicationContextpublishContextAsService - true if the application context should be
published as a service, false otherwiseprivate java.lang.ClassLoader createBundleClassLoader(org.osgi.framework.Bundle bundle)
bundle -