public class ConditionalApplicationContextCreator extends Object implements OsgiApplicationContextCreator, org.springframework.beans.factory.InitializingBean
OsgiApplicationContextCreator implementation that dictates
whether the default application context used by the Spring-DM extender should
be created (or not) based on a boolean value. This allows
clients to handle only the bundleContext filtering while being decoupled from
the context creation process:
ConditionalApplicationContextCreator creator = new ConditionalApplicationContextCreator();
creator.setFilter(new ConditionalApplicationContextCreator.BundleContextFilter() {
// filter bundles with no copyright
public boolean matches(BundleContext bundleContext) {
return bundleContext.getBundle().getHeaders().get(Constants.BUNDLE_COPYRIGHT) != null)
}
}
creator.createApplicationContext(bundleContext);
OsgiApplicationContextCreator| Modifier and Type | Class and Description |
|---|---|
static interface |
ConditionalApplicationContextCreator.BundleContextFilter
Callback used to filter the bundle contexts for which the default
application contexts are created.
|
| Constructor and Description |
|---|
ConditionalApplicationContextCreator() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
DelegatedExecutionOsgiBundleApplicationContext |
createApplicationContext(org.osgi.framework.BundleContext bundleContext)
Creates an application context for the given bundle context.
|
void |
setDelegatedApplicationContextCreator(OsgiApplicationContextCreator delegatedContextCreator)
Sets the
OsgiApplicationContextCreator used by this context
creator for the actual creation. |
void |
setFilter(ConditionalApplicationContextCreator.BundleContextFilter filter)
Sets the
ConditionalApplicationContextCreator.BundleContextFilter used by this context creator. |
public ConditionalApplicationContextCreator()
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(org.osgi.framework.BundleContext bundleContext) throws Exception
OsgiApplicationContextCreatornull should be
returned. Exceptions will be caught and logged but will not prevent the
creation of other application contexts.createApplicationContext in interface OsgiApplicationContextCreatorbundleContext - OSGi bundle context determining the context creationnull if no context should be created, non-
null otherwiseException - if something goes wrongpublic void setFilter(ConditionalApplicationContextCreator.BundleContextFilter filter)
ConditionalApplicationContextCreator.BundleContextFilter used by this context creator.filter - The bundle context filter to set.public void setDelegatedApplicationContextCreator(OsgiApplicationContextCreator delegatedContextCreator)
OsgiApplicationContextCreator used by this context
creator for the actual creation. If none is specified,
DefaultOsgiApplicationContextCreator is used.delegatedContextCreator - the instance used for creating the
application contextCopyright © 2006–2015. All rights reserved.