diff options
author | John Arthorne | 2010-10-06 20:00:28 +0000 |
---|---|---|
committer | John Arthorne | 2010-10-06 20:00:28 +0000 |
commit | 0bbc72d38d0fe4b1c438d93dbfde91655df6fa09 (patch) | |
tree | f4e9d321197cb4700ad315ec064849bb481426c2 /bundles/org.eclipse.equinox.p2.core | |
parent | fdfa6363a847d135212385970259283890243fd0 (diff) | |
download | rt.equinox.p2-0bbc72d38d0fe4b1c438d93dbfde91655df6fa09.tar.gz rt.equinox.p2-0bbc72d38d0fe4b1c438d93dbfde91655df6fa09.tar.xz rt.equinox.p2-0bbc72d38d0fe4b1c438d93dbfde91655df6fa09.zip |
Fixed compiler warnings
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.core')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java index 762029592..bf06f0c35 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java @@ -8,6 +8,7 @@ ******************************************************************************/ package org.eclipse.equinox.internal.p2.core.helpers; +import java.util.Collection; import org.osgi.framework.*; public class ServiceHelper { @@ -17,6 +18,42 @@ public class ServiceHelper { * system thinks the service is not in use but indeed the caller is about to use the returned * service object. * @param context + * @param clazz the service class + * @return The requested service + */ + public static <T> T getService(BundleContext context, Class<T> clazz) { + if (context == null) + return null; + ServiceReference<T> reference = context.getServiceReference(clazz); + if (reference == null) + return null; + T result = context.getService(reference); + context.ungetService(reference); + return result; + } + + public static <T> T getService(BundleContext context, Class<T> clazz, String filter) { + Collection<ServiceReference<T>> references; + try { + references = context.getServiceReferences(clazz, filter); + } catch (InvalidSyntaxException e) { + // TODO Auto-generated catch block + return null; + } + if (references.isEmpty()) + return null; + final ServiceReference<T> ref = references.iterator().next(); + T result = context.getService(ref); + context.ungetService(ref); + return result; + } + + /** + * Returns the service described by the given arguments. Note that this is a helper class + * that <b>immediately</b> ungets the service reference. This results in a window where the + * system thinks the service is not in use but indeed the caller is about to use the returned + * service object. + * @param context * @param name * @return The requested service */ |