1
2
3
4
5 package gboat2.web.util;
6
7 import gboat2.web.Activator;
8
9 import java.net.URL;
10
11 import org.osgi.framework.Bundle;
12 import org.osgi.framework.BundleContext;
13
14
15
16
17
18
19
20
21
22
23 public abstract class BundleUtil {
24
25 private static BundleContext context = null;
26
27
28
29
30
31 private static BundleContext getBundleContext() {
32 if (null == context) {
33 context = Activator.LOCAL_BUNDLE.getBundleContext();
34 }
35 return context;
36 }
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public static Bundle getBundle(String bundleName) {
61 Bundle[] bs = getBundleContext().getBundles();
62 for (Bundle b : bs) {
63 if (b.getSymbolicName().equals(bundleName)) {
64 return b;
65 }
66 }
67 return null;
68 }
69
70
71
72
73
74
75
76 public static URL getResourceOfBundle(String bundleName, String path) {
77 Bundle bundle = getBundle(bundleName);
78 if (null == bundle) {
79 return null;
80 }
81 return bundle.getResource(path);
82 }
83
84 }