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 void addServiceListener(org.osgi.framework.BundleContext context, org.osgi.framework.ServiceListener listener, Class clazz, String serviceFilter)
           
static String createFilter(String key, String val)
           
static String createIdFilter(String idPropertyName, String idString, String filter)
           
static
<T> SingleServiceListener<T>
createIdServiceListener(Class<T> clazz, org.osgi.framework.BundleContext context, String idPropertyName, String idString, String filter)
           
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 String formatPropertiesString(org.osgi.framework.ServiceReference ref)
           
static String formatUsingBundlesString(org.osgi.framework.ServiceReference ref)
           
static org.osgi.framework.BundleContext getBundleContext(Class clazz)
          Returns the BundleContext associated with the given Class.
static String getInformationString(org.osgi.framework.ServiceReference ref)
           
static
<T> T
getService(Class<T> clazz, org.osgi.framework.BundleContext context, org.osgi.framework.ServiceReference ref)
           
static org.osgi.framework.ServiceRegistration registerService(org.osgi.framework.BundleContext context, String className, String idPropertyName, String idString, Object service, Properties serviceProperties)
           
static org.osgi.framework.ServiceRegistration registerUniqueService(org.osgi.framework.BundleContext context, String className, String idPropertyName, String idString, Object service, Properties serviceProperties)
          Registers the given service only if a service does not exist with the given id.
static Boolean serviceExists(org.osgi.framework.BundleContext context, Class clazz, String filter)
          Checks the OSGi Service Registry for a Service with the given class and matching the given filter.
static Boolean serviceExists(org.osgi.framework.BundleContext context, String[] 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, Properties props)
           
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.
static Boolean serviceExists(org.osgi.framework.BundleContext context, String clazz, String idPropertyName, String idString, Properties props)
           
static ManagedService startComponent(org.osgi.framework.BundleContext context, String[] classNames, Object service, Properties serviceProperties)
           
static ManagedService startComponent(org.osgi.framework.BundleContext context, String[] classNames, String idPropertyName, String idString, Object service, Properties serviceProperties)
           
static ManagedService startComponent(org.osgi.framework.BundleContext context, String className, String idPropertyName, String idString, Object service, Properties serviceProperties)
           
static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context, String[] classNames, Object service, Properties uniqueProps, Properties serviceProperties)
           
static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context, String[] classNames, String idPropertyName, String idString, Object service, Properties serviceProperties)
           
static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context, String className, String idPropertyName, String idString, Object service, Properties serviceProperties)
           
 
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

createFilter

public static String createFilter(String key,
                                  String val)

createIdFilter

public static String createIdFilter(String idPropertyName,
                                    String idString,
                                    String filter)

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,
                                    String clazz,
                                    Properties props)

serviceExists

public static Boolean serviceExists(org.osgi.framework.BundleContext context,
                                    String clazz,
                                    String idPropertyName,
                                    String idString,
                                    Properties props)

serviceExists

public static Boolean serviceExists(org.osgi.framework.BundleContext context,
                                    Class 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 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,
                                    String[] 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 class names 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

getService

public static <T> T getService(Class<T> clazz,
                               org.osgi.framework.BundleContext context,
                               org.osgi.framework.ServiceReference ref)

getInformationString

public static String getInformationString(org.osgi.framework.ServiceReference ref)

formatPropertiesString

public static String formatPropertiesString(org.osgi.framework.ServiceReference ref)

formatUsingBundlesString

public static String formatUsingBundlesString(org.osgi.framework.ServiceReference ref)

createIdServiceListener

public static <T> SingleServiceListener<T> createIdServiceListener(Class<T> clazz,
                                                                   org.osgi.framework.BundleContext context,
                                                                   String idPropertyName,
                                                                   String idString,
                                                                   String filter)

registerService

public static org.osgi.framework.ServiceRegistration registerService(org.osgi.framework.BundleContext context,
                                                                     String className,
                                                                     String idPropertyName,
                                                                     String idString,
                                                                     Object service,
                                                                     Properties serviceProperties)

startComponent

public static ManagedService startComponent(org.osgi.framework.BundleContext context,
                                            String className,
                                            String idPropertyName,
                                            String idString,
                                            Object service,
                                            Properties serviceProperties)

startComponent

public static ManagedService startComponent(org.osgi.framework.BundleContext context,
                                            String[] classNames,
                                            String idPropertyName,
                                            String idString,
                                            Object service,
                                            Properties serviceProperties)

startComponent

public static ManagedService startComponent(org.osgi.framework.BundleContext context,
                                            String[] classNames,
                                            Object service,
                                            Properties serviceProperties)

registerUniqueService

public static org.osgi.framework.ServiceRegistration registerUniqueService(org.osgi.framework.BundleContext context,
                                                                           String className,
                                                                           String idPropertyName,
                                                                           String idString,
                                                                           Object service,
                                                                           Properties serviceProperties)
Registers the given service only if a service does not exist with the given id. Returns the ServiceRegistration, or null if a service exists.

Parameters:
context -
className -
idPropertyName -
idString -
service -
serviceProperties -
Returns:
the ServiceRegistration, or null if a service exists

startUniqueComponent

public static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context,
                                                  String className,
                                                  String idPropertyName,
                                                  String idString,
                                                  Object service,
                                                  Properties serviceProperties)

startUniqueComponent

public static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context,
                                                  String[] classNames,
                                                  String idPropertyName,
                                                  String idString,
                                                  Object service,
                                                  Properties serviceProperties)

startUniqueComponent

public static ManagedService startUniqueComponent(org.osgi.framework.BundleContext context,
                                                  String[] classNames,
                                                  Object service,
                                                  Properties uniqueProps,
                                                  Properties serviceProperties)

addServiceListener

public static void addServiceListener(org.osgi.framework.BundleContext context,
                                      org.osgi.framework.ServiceListener listener,
                                      Class clazz,
                                      String serviceFilter)
                               throws org.osgi.framework.InvalidSyntaxException
Throws:
org.osgi.framework.InvalidSyntaxException


Copyright © 2011-2013. All Rights Reserved.