org.springframework.osgi.service.importer.support
Class AbstractOsgiServiceImportFactoryBean

java.lang.Object
  extended by org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, BeanNameAware, DisposableBean, FactoryBean, InitializingBean, BundleContextAware
Direct Known Subclasses:
OsgiServiceCollectionProxyFactoryBean, OsgiServiceProxyFactoryBean

public abstract class AbstractOsgiServiceImportFactoryBean
extends Object
implements FactoryBean, InitializingBean, DisposableBean, BundleContextAware, BeanClassLoaderAware, BeanNameAware

Base class for importing OSGi services. Provides the common properties and contracts between importers.

Author:
Costin Leau, Adrian Colyer, Hal Hildebrand

Constructor Summary
AbstractOsgiServiceImportFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 ClassLoader getBeanClassLoader()
          Returns the class loader used by this FactoryBean.
 String getBeanName()
          Returns the bean name associated with the instance of this class (when running inside the Spring container).
 BundleContext getBundleContext()
          Returns the bundleContext used by this FactoryBean.
 Cardinality getCardinality()
          Returns the cardinality used by this importer.
 ImportContextClassLoader getContextClassLoader()
          Returns the context class loader management strategy.
 String getFilter()
          Returns the filter describing the imported service(s).
 Class[] getInterfaces()
          Returns the interfaces used for discovering the imported service(s).
 OsgiServiceLifecycleListener[] getListeners()
          Returns the listeners interested in receiving events for this importer.
 Filter getUnifiedFilter()
          Assembles the configuration properties into one unified OSGi filter.
 void setBeanClassLoader(ClassLoader classLoader)
           This method is called automatically by the container.
 void setBeanName(String name)
           
 void setBundleContext(BundleContext context)
          Set the BundleContext that this bean runs in.
 void setCardinality(Cardinality cardinality)
          Sets the importer cardinality (0..1, 1..1, 0..N, or 1..N).
 void setContextClassLoader(ImportContextClassLoader contextClassLoader)
          Sets the thread context class loader management strategy to use for services imported by this service.
 void setFilter(String filter)
          Sets the OSGi service filter.
 void setInterfaces(Class[] interfaces)
          Sets the classes that the imported service advertises.
 void setListeners(OsgiServiceLifecycleListener[] listeners)
          Sets the lifecycle listeners interested in receiving events for this importer.
 void setServiceBeanName(String serviceBeanName)
          Sets the OSGi service bean name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.beans.factory.FactoryBean
getObject, getObjectType, isSingleton
 
Methods inherited from interface org.springframework.beans.factory.DisposableBean
destroy
 

Constructor Detail

AbstractOsgiServiceImportFactoryBean

public AbstractOsgiServiceImportFactoryBean()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

getUnifiedFilter

public Filter getUnifiedFilter()
Assembles the configuration properties into one unified OSGi filter. Note that this implementation creates the filter on the first call and caches it afterwards.

Returns:
unified filter based on this factory bean configuration

setInterfaces

public void setInterfaces(Class[] interfaces)
Sets the classes that the imported service advertises.

Parameters:
interfaces - array of advertised classes.

setContextClassLoader

public void setContextClassLoader(ImportContextClassLoader contextClassLoader)
Sets the thread context class loader management strategy to use for services imported by this service. By default ImportContextClassLoader.CLIENT is used.

Parameters:
contextClassLoader - import context class loader management strategy
See Also:
ImportContextClassLoader

setBundleContext

public void setBundleContext(BundleContext context)
Description copied from interface: BundleContextAware
Set the BundleContext that this bean runs in. Normally this can be used to initialize an object.

Specified by:
setBundleContext in interface BundleContextAware
Parameters:
context - the BundleContext object to be used by this object

setFilter

public void setFilter(String filter)
Sets the OSGi service filter. The filter will be concatenated with the rest of the configuration properties specified (such as interfaces) so there is no need to include them in the filter.

Parameters:
filter - OSGi filter describing the importing OSGi service

setListeners

public void setListeners(OsgiServiceLifecycleListener[] listeners)
Sets the lifecycle listeners interested in receiving events for this importer.

Parameters:
listeners - importer listeners

setServiceBeanName

public void setServiceBeanName(String serviceBeanName)
Sets the OSGi service bean name. This setting should be normally used when the imported service has been exported by Spring DM exporter. You may specify additional filtering criteria if needed (using the filter property) but this is not required.

Parameters:
serviceBeanName - importer service bean name

setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)
This method is called automatically by the container.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware

getBeanClassLoader

public ClassLoader getBeanClassLoader()
Returns the class loader used by this FactoryBean.

Returns:
factory bean class loader

getBundleContext

public BundleContext getBundleContext()
Returns the bundleContext used by this FactoryBean.

Returns:
factory bean class loader

getInterfaces

public Class[] getInterfaces()
Returns the interfaces used for discovering the imported service(s).

Returns:
interfaces advertised by services in the OSGi space

getFilter

public String getFilter()
Returns the filter describing the imported service(s).

Returns:
filter describing the imported service(s)

getListeners

public OsgiServiceLifecycleListener[] getListeners()
Returns the listeners interested in receiving events for this importer.

Returns:
lifecycle listeners used by this importer

getContextClassLoader

public ImportContextClassLoader getContextClassLoader()
Returns the context class loader management strategy.

Returns:
the context class loader management strategy

getCardinality

public Cardinality getCardinality()
Returns the cardinality used by this importer.

Returns:
importer cardinality

setCardinality

public void setCardinality(Cardinality cardinality)
Sets the importer cardinality (0..1, 1..1, 0..N, or 1..N). Default is 1..X.

Parameters:
cardinality - importer cardinality.

getBeanName

public String getBeanName()
Returns the bean name associated with the instance of this class (when running inside the Spring container).

Returns:
component bean name

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface BeanNameAware


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