org.springframework.osgi.service.exporter
Class OsgiServiceFactoryBean

java.lang.Object
  extended by org.springframework.osgi.internal.service.exporter.AbstractServiceExporter
      extended by org.springframework.osgi.internal.service.exporter.AbstractListenerAwareExporter
          extended by org.springframework.osgi.service.exporter.OsgiServiceFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, FactoryBean, InitializingBean, Ordered, BundleContextAware, org.springframework.osgi.internal.OsgiLifecycle, org.springframework.osgi.internal.service.ServiceExporter

public class OsgiServiceFactoryBean
extends org.springframework.osgi.internal.service.exporter.AbstractListenerAwareExporter
implements BeanFactoryAware, DisposableBean, BundleContextAware, FactoryBean, Ordered, BeanClassLoaderAware, BeanNameAware

FactoryBean that transparently publishes other beans in the same application context as OSGi services returning the ServiceRegistration for the given object.

The service properties used when publishing the service are determined by the OsgiServicePropertiesResolver. The default implementation uses

Author:
Adrian Colyer, Costin Leau, Hal Hildebrand, Andy Piper

Field Summary
static int AUTO_EXPORT_ALL
           
static int AUTO_EXPORT_CLASS_HIERARCHY
           
static int AUTO_EXPORT_DISABLED
           
static int AUTO_EXPORT_INTERFACES
           
 
Fields inherited from class org.springframework.osgi.internal.service.exporter.AbstractServiceExporter
publishAtStartup
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
OsgiServiceFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  Class[] autoDetectClassesForPublishing(Class clazz)
          Return an array of classes for the given bean that have been discovered using the autoExportMode.
 void destroy()
           
 String getActivationMethod()
           
 String getDeactivationMethod()
           
 Object getObject()
           
 Class getObjectType()
           
 int getOrder()
           
 int getRanking()
           
 OsgiServicePropertiesResolver getResolver()
           
 Map getServiceProperties()
           
protected  boolean isBeanBundleScoped()
           
 boolean isSingleton()
           
 void registerService()
          Publish the given object as an OSGi service.
protected  ServiceRegistration registerService(Class[] classes, Dictionary serviceProperties)
          Registration method.
 void setActivationMethod(String activationMethod)
           
 void setAutoExport(String autoExportMode)
          Set the autoexport mode to use.
 void setAutoExportNumber(int autoExportMode)
          Set the autoexport mode to use.
 void setBeanClassLoader(ClassLoader classLoader)
           
 void setBeanFactory(BeanFactory beanFactory)
           
 void setBeanName(String name)
           
 void setBundleContext(BundleContext context)
           
 void setContextClassloader(String classloaderManagementOption)
          Set the context classloader management strategy to use when invoking operations on the exposed target bean
 void setDeactivationMethod(String deactivationMethod)
           
 void setInterfaces(Class[] serviceInterfaces)
           
 void setOrder(int order)
           
 void setRanking(int ranking)
           
 void setResolver(OsgiServicePropertiesResolver resolver)
           
 void setServiceProperties(Map serviceProperties)
           
 void setTarget(Object target)
          Export the given object as an OSGi service.
 void setTargetBeanName(String name)
           
 void unregisterService()
           
protected  void unregisterService(ServiceRegistration registration)
          Unregisters (literally stops) a service.
 
Methods inherited from class org.springframework.osgi.internal.service.exporter.AbstractListenerAwareExporter
notifyListeners, setListeners
 
Methods inherited from class org.springframework.osgi.internal.service.exporter.AbstractServiceExporter
isRunning, setPublishAtStartup, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO_EXPORT_DISABLED

public static final int AUTO_EXPORT_DISABLED
See Also:
Constant Field Values

AUTO_EXPORT_INTERFACES

public static final int AUTO_EXPORT_INTERFACES
See Also:
Constant Field Values

AUTO_EXPORT_CLASS_HIERARCHY

public static final int AUTO_EXPORT_CLASS_HIERARCHY
See Also:
Constant Field Values

AUTO_EXPORT_ALL

public static final int AUTO_EXPORT_ALL
See Also:
Constant Field Values
Constructor Detail

OsgiServiceFactoryBean

public OsgiServiceFactoryBean()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class org.springframework.osgi.internal.service.exporter.AbstractServiceExporter
Throws:
Exception

autoDetectClassesForPublishing

protected Class[] autoDetectClassesForPublishing(Class clazz)
Return an array of classes for the given bean that have been discovered using the autoExportMode.

Parameters:
clazz -
Returns:

registerService

public void registerService()
Publish the given object as an OSGi service. It simply assembles the classes required for publishing and then delegates the actual registration to a dedicated method.

Specified by:
registerService in class org.springframework.osgi.internal.service.exporter.AbstractServiceExporter
Parameters:
beanClass -
serviceProperties -

registerService

protected ServiceRegistration registerService(Class[] classes,
                                              Dictionary serviceProperties)
Registration method.

Parameters:
classes -
serviceProperties -
Returns:
the ServiceRegistration

isBeanBundleScoped

protected boolean isBeanBundleScoped()

setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)
Specified by:
setBeanClassLoader in interface BeanClassLoaderAware

getObject

public Object getObject()
                 throws Exception
Specified by:
getObject in interface FactoryBean
Throws:
Exception

getObjectType

public Class getObjectType()
Specified by:
getObjectType in interface FactoryBean

isSingleton

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

destroy

public void destroy()
Specified by:
destroy in interface DisposableBean

unregisterService

public void unregisterService()
Specified by:
unregisterService in class org.springframework.osgi.internal.service.exporter.AbstractServiceExporter

unregisterService

protected void unregisterService(ServiceRegistration registration)
Unregisters (literally stops) a service.

Parameters:
registration -

setContextClassloader

public void setContextClassloader(String classloaderManagementOption)
Set the context classloader management strategy to use when invoking operations on the exposed target bean

Parameters:
classloaderManagementOption -

setTarget

public void setTarget(Object target)
Export the given object as an OSGi service. Normally used when the exported service is a nested bean or an object not managed by the Spring container.

Parameters:
target - The target to set.

setAutoExportNumber

public void setAutoExportNumber(int autoExportMode)
Set the autoexport mode to use. This allows the exporter to use the target class hierarchy and/or interfaces for registering the OSGi service. By default, autoExport is disabled (@link AUTO_EXPORT_DISABLED

Parameters:
autoExportMode - the auto export mode as an int
See Also:
#setAutoExportName(String), AUTO_EXPORT_DISABLED, AUTO_EXPORT_INTERFACES, AUTO_EXPORT_CLASS_HIERARCHY, AUTO_EXPORT_ALL

setAutoExport

public void setAutoExport(String autoExportMode)
Set the autoexport mode to use.

Parameters:
autoExportMode -
See Also:
setAutoExportNumber(int)

getActivationMethod

public String getActivationMethod()

setActivationMethod

public void setActivationMethod(String activationMethod)

getDeactivationMethod

public String getDeactivationMethod()

setDeactivationMethod

public void setDeactivationMethod(String deactivationMethod)

getServiceProperties

public Map getServiceProperties()

setServiceProperties

public void setServiceProperties(Map serviceProperties)

getRanking

public int getRanking()

setRanking

public void setRanking(int ranking)

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException

setBundleContext

public void setBundleContext(BundleContext context)
Specified by:
setBundleContext in interface BundleContextAware

getResolver

public OsgiServicePropertiesResolver getResolver()
Returns:
Returns the resolver.

setResolver

public void setResolver(OsgiServicePropertiesResolver resolver)
Parameters:
resolver - The resolver to set.

setTargetBeanName

public void setTargetBeanName(String name)

setInterfaces

public void setInterfaces(Class[] serviceInterfaces)

getOrder

public int getOrder()
Specified by:
getOrder in interface Ordered
Returns:
Returns the order.

setOrder

public void setOrder(int order)
Parameters:
order - The order to set.

setBeanName

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


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