/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ package net.java.sip.communicator.util; import org.osgi.framework.*; /** * Gathers utility functions related to OSGi services such as getting a service * registered in a BundleContext. * * @author Lubomir Marinov */ public class ServiceUtils { /** * Gets an OSGi service registered in a specific BundleContext by * its Class * * @param the very type of the OSGi service to get * @param bundleContext the BundleContext in which the service to * get has been registered * @param serviceClass the Class with which the service to get has * been registered in the bundleContext * @return the OSGi service registered in bundleContext with the * specified serviceClass if such a service exists there; * otherwise, null */ @SuppressWarnings("unchecked") public static T getService( BundleContext bundleContext, Class serviceClass) { ServiceReference serviceReference = bundleContext.getServiceReference(serviceClass.getName()); return (serviceReference == null) ? null : (T) bundleContext.getService(serviceReference); } /** Prevents the creation of ServiceUtils instances. */ private ServiceUtils() { } }