1
2
3
4
5 package gboat2.base.core.web;
6
7 import gboat2.base.core.Activator;
8
9 import org.osgi.framework.BundleContext;
10 import org.osgi.util.tracker.ServiceTracker;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14
15
16
17
18
19
20
21
22
23 public abstract class SystemButtonProviderTracker {
24
25 @SuppressWarnings("rawtypes")
26 private static ServiceTracker tracker = null;
27
28 protected static Logger logger = LoggerFactory.getLogger(SystemButtonProviderTracker.class);
29
30 private static byte[] lock = new byte[0];
31
32
33
34
35
36 @SuppressWarnings({ "rawtypes", "unchecked" })
37 public static void open(BundleContext context) {
38 if (null != tracker) {
39 tracker.close();
40 }
41 tracker = new ServiceTracker(context, SystemButtonProvider.class.getName(), null);
42 tracker.open();
43 }
44
45
46
47
48 public static void close() {
49 if (null != tracker) {
50 tracker.close();
51 tracker = null;
52 }
53 }
54
55
56
57
58
59 public static SystemButtonProvider[] getProviders() {
60 synchronized (lock) {
61 if (null == tracker) {
62 open(Activator.LOCAL_BUNDLE.getBundleContext());
63 }
64 }
65
66 Object[] objs = tracker.getServices();
67 if (null != objs) {
68 SystemButtonProvider[] services = new SystemButtonProvider[objs.length];
69 int i;
70 for (i = 0; i < objs.length; i++) {
71 services[i] = (SystemButtonProvider) objs[i];
72 }
73 return services;
74 }
75
76 return null;
77 }
78 }