org.springframework.osgi.util
Class OsgiServiceReferenceUtils

java.lang.Object
  extended by org.springframework.osgi.util.OsgiServiceReferenceUtils

public abstract class OsgiServiceReferenceUtils
extends Object

Utility class for retrieving OSGi service references. This class offers a unified filter-based access for OSGi services as well as translation of checked exceptions InvalidSyntaxException into unchecked ones.

This classes uses OsgiFilterUtils underneath to allow multiple classnames to be used for service reference lookup.

Author:
Costin Leau
See Also:
OsgiFilterUtils

Constructor Summary
OsgiServiceReferenceUtils()
           
 
Method Summary
static long getServiceId(ServiceReference reference)
           
static Dictionary getServiceProperties(ServiceReference reference)
          Return a dictionary containing the properties available for the given service reference.
static Map getServicePropertiesAsMap(ServiceReference reference)
          Return a map containing the properties for the given service reference.
static Dictionary getServicePropertiesSnapshot(ServiceReference reference)
          Return a dict containing the properties available for the given service reference.
static Map getServicePropertiesSnapshotAsMap(ServiceReference reference)
           
static int getServiceRanking(ServiceReference reference)
           
static ServiceReference getServiceReference(BundleContext bundleContext, String filter)
           
static ServiceReference getServiceReference(BundleContext bundleContext, String[] classes)
           
static ServiceReference getServiceReference(BundleContext bundleContext, String[] classes, String filter)
           
static ServiceReference getServiceReference(BundleContext bundleContext, String clazz, String filter)
           
static ServiceReference[] getServiceReferences(BundleContext bundleContext, String filter)
          Return the service reference that match the given filter.
static ServiceReference[] getServiceReferences(BundleContext bundleContext, String[] classes)
           
static ServiceReference[] getServiceReferences(BundleContext bundleContext, String[] classes, String filter)
           
static ServiceReference[] getServiceReferences(BundleContext bundleContext, String clazz, String filter)
           
static boolean isServicePresent(BundleContext context, String serviceFilter)
          Check if the given serviceFilter returns at least one match or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OsgiServiceReferenceUtils

public OsgiServiceReferenceUtils()
Method Detail

getServiceReference

public static ServiceReference getServiceReference(BundleContext bundleContext,
                                                   String[] classes)

getServiceReference

public static ServiceReference getServiceReference(BundleContext bundleContext,
                                                   String clazz,
                                                   String filter)

getServiceReference

public static ServiceReference getServiceReference(BundleContext bundleContext,
                                                   String[] classes,
                                                   String filter)

getServiceReference

public static ServiceReference getServiceReference(BundleContext bundleContext,
                                                   String filter)

getServiceReferences

public static ServiceReference[] getServiceReferences(BundleContext bundleContext,
                                                      String[] classes)

getServiceReferences

public static ServiceReference[] getServiceReferences(BundleContext bundleContext,
                                                      String clazz,
                                                      String filter)

getServiceReferences

public static ServiceReference[] getServiceReferences(BundleContext bundleContext,
                                                      String[] classes,
                                                      String filter)

getServiceReferences

public static ServiceReference[] getServiceReferences(BundleContext bundleContext,
                                                      String filter)
Return the service reference that match the given filter. This method never return null - if no service is found an empty array will be returned.

Parameters:
bundleContext -
filter -
Returns:
an array of service references that match the given filter.

getServiceId

public static long getServiceId(ServiceReference reference)

getServiceRanking

public static int getServiceRanking(ServiceReference reference)

getServicePropertiesSnapshot

public static Dictionary getServicePropertiesSnapshot(ServiceReference reference)
Return a dict containing the properties available for the given service reference. This method takes a snapshot of the properties; future changes to the service properties will not be reflected in the returned dict.

Note that the returned type implements the Map interface also.

Parameters:
reference - service reference
Returns:
dict containing the service reference properties taken as a snapshot

getServicePropertiesSnapshotAsMap

public static Map getServicePropertiesSnapshotAsMap(ServiceReference reference)

getServiceProperties

public static Dictionary getServiceProperties(ServiceReference reference)
Return a dictionary containing the properties available for the given service reference. The returned object will reflect any updates made to to the ServiceReference through the owning ServiceRegistration.

Note that the returned type implements the Map interface also.

Parameters:
reference - an OSGi service reference
Returns:
dict of properties which will reflect future reference changes

getServicePropertiesAsMap

public static Map getServicePropertiesAsMap(ServiceReference reference)
Return a map containing the properties for the given service reference. Consider using getServiceProperties(ServiceReference) which returns an object that extends Dictionary as well as implements the Map interface.

Parameters:
reference -
Returns:
See Also:
getServiceProperties(ServiceReference)

isServicePresent

public static boolean isServicePresent(BundleContext context,
                                       String serviceFilter)
Check if the given serviceFilter returns at least one match or not.

Parameters:
context -
serviceFilter -
Returns:


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