org.springframework.osgi.extender.support
Class ConditionalApplicationContextCreator

java.lang.Object
  extended by org.springframework.osgi.extender.support.ConditionalApplicationContextCreator
All Implemented Interfaces:
InitializingBean, OsgiApplicationContextCreator

public class ConditionalApplicationContextCreator
extends Object
implements OsgiApplicationContextCreator, InitializingBean

Useful 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); 
 

Author:
Costin Leau
See Also:
OsgiApplicationContextCreator

Nested Class Summary
static interface ConditionalApplicationContextCreator.BundleContextFilter
          Callback used to filter the bundle contexts for which the default application contexts are created.
 
Constructor Summary
ConditionalApplicationContextCreator()
           
 
Method Summary
 void afterPropertiesSet()
           
 DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionalApplicationContextCreator

public ConditionalApplicationContextCreator()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

createApplicationContext

public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext)
                                                                        throws Exception
Description copied from interface: OsgiApplicationContextCreator
Creates an application context for the given bundle context. If no application context needs to be created, then null should be returned. Exceptions will be caught and logged but will not prevent the creation of other application contexts.

Specified by:
createApplicationContext in interface OsgiApplicationContextCreator
Parameters:
bundleContext - OSGi bundle context determining the context creation
Returns:
null if no context should be created, non-null otherwise
Throws:
Exception - if something goes wrong

setFilter

public void setFilter(ConditionalApplicationContextCreator.BundleContextFilter filter)
Sets the ConditionalApplicationContextCreator.BundleContextFilter used by this context creator.

Parameters:
filter - The bundle context filter to set.

setDelegatedApplicationContextCreator

public void setDelegatedApplicationContextCreator(OsgiApplicationContextCreator delegatedContextCreator)
Sets the OsgiApplicationContextCreator used by this context creator for the actual creation. If none is specified, DefaultOsgiApplicationContextCreator is used.

Parameters:
delegatedContextCreator - the instance used for creating the application context


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