org.robokind.api.common.osgi
Class OSGiUtils

java.lang.Object
  extended by org.robokind.api.common.osgi.OSGiUtils

public class OSGiUtils
extends Object

Utility methods for working with OSGi.

Author:
Matthew Stevenson

Constructor Summary
OSGiUtils()
           
 
Method Summary
static String createServiceFilter(Properties props)
          Creates a filter string which matches all of the properties given.
static String createServiceFilter(String key, String val)
          Creates a filter string which matches the key and value given
static org.osgi.framework.BundleContext getBundleContext(Class clazz)
          Returns the BundleContext associated with the given Class.
static Boolean serviceExists(org.osgi.framework.BundleContext context, Class[] classes, String filter)
          Checks the OSGi Service Registry for an existing Service matching the given filter String and one or more of the given Class names.
static Boolean serviceExists(org.osgi.framework.BundleContext context, String clazz, String filter)
          Checks the OSGi Service Registry for a Service with the given class and matching the given filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSGiUtils

public OSGiUtils()
Method Detail

getBundleContext

public static org.osgi.framework.BundleContext getBundleContext(Class clazz)
Returns the BundleContext associated with the given Class.

Parameters:
clazz - Class associated with a Bundle
Returns:
the BundleContext associated with the given Class, if no Bundle is found for the Class null is returned

createServiceFilter

public static String createServiceFilter(Properties props)
Creates a filter string which matches all of the properties given.

Parameters:
props - Properties to match
Returns:
OSGi filter string, null if props is null or empty

createServiceFilter

public static String createServiceFilter(String key,
                                         String val)
Creates a filter string which matches the key and value given

Parameters:
key - key
val - value
Returns:
OSGi filter string, null if props is null or empty

serviceExists

public static Boolean serviceExists(org.osgi.framework.BundleContext context,
                                    String clazz,
                                    String filter)
Checks the OSGi Service Registry for a Service with the given class and matching the given filter. Returns true if a matching ServiceReference is found, return null if there is an InvalidSyntaxException.

Parameters:
context - BundleContext to use
clazz - Class name to match
filter - OSGi Service filter String
Returns:
true if a matching ServiceReference is found, returns null if there is an InvalidSyntaxException

serviceExists

public static Boolean serviceExists(org.osgi.framework.BundleContext context,
                                    Class[] classes,
                                    String filter)
Checks the OSGi Service Registry for an existing Service matching the given filter String and one or more of the given Class names.

Parameters:
context - BundleContext to use
classes - one or more of the classes must be matched
filter - OSGi Service filter String to match
Returns:
true if a ServiceReference is found matching one or more of the given classes and the filter String, return null if there is an InvalidSyntaxException


Copyright © 2011. All Rights Reserved.