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

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

public abstract class AbstractOsgiServiceImportFactoryBean
extends AbstractDependableServiceImporter
implements SmartFactoryBean, InitializingBean, DisposableBean, BundleContextAware, BeanClassLoaderAware

Base class for importing OSGi services. Provides most of the constructs required for assembling the service proxies, leaving subclasses to decide on the service cardinality (one service or multiple).

Author:
Costin Leau, Adrian Colyer, Hal Hildebrand

Constructor Summary
AbstractOsgiServiceImportFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
 ClassLoader getBeanClassLoader()
          Returns the class loader used by this FactoryBean.
 BundleContext getBundleContext()
          Returns the bundleContext used by this FactoryBean.
 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.
 Object getObject()
          Returns a managed hook to access OSGi service(s).
 Filter getUnifiedFilter()
          Assembles the configuration properties into one unified OSGi filter.
 boolean isEagerInit()
           
 boolean isPrototype()
           
 boolean isSingleton()
           
 void setBeanClassLoader(ClassLoader classLoader)
           This method is called automatically by the container.
 void setBundleContext(BundleContext context)
          Set the BundleContext that this bean runs in.
 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 org.springframework.osgi.service.importer.support.AbstractDependableServiceImporter
getCardinality, isMandatory, registerListener, setCardinality
 
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
getObjectType
 
Methods inherited from interface org.springframework.osgi.service.dependency.ServiceDependency
isSatisfied
 

Constructor Detail

AbstractOsgiServiceImportFactoryBean

public AbstractOsgiServiceImportFactoryBean()
Method Detail

getObject

public Object getObject()
Returns a managed hook to access OSGi service(s). Subclasses can decide to create either a proxy managing only one OSGi service type or a collection of services matching a certain criteri

Specified by:
getObject in interface FactoryBean
Returns:
managed OSGi service(s)

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface FactoryBean

isEagerInit

public boolean isEagerInit()
Specified by:
isEagerInit in interface SmartFactoryBean

isPrototype

public boolean isPrototype()
Specified by:
isPrototype in interface SmartFactoryBean

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

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

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. For programmatic usage, make sure that the class loader is able to see the AOP infrastructure interfaces that are used during the proxy creation.

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


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