1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.slf4j.test_osgi;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.osgi.framework.Bundle;
31 import org.osgi.framework.BundleEvent;
32 import org.osgi.framework.BundleListener;
33
34 public class CheckingBundleListener implements BundleListener {
35
36 List<BundleEvent> eventList = new ArrayList<BundleEvent>();
37
38 public void bundleChanged(BundleEvent be) {
39 eventList.add(be);
40 }
41
42 private void dump(BundleEvent be) {
43 System.out.println("BE:" + ", source " + be.getSource() + ", bundle=" + be.getBundle() + ", type=" + be.getType());
44
45 }
46
47 public void dumpAll() {
48 for (int i = 0; i < eventList.size(); i++) {
49 BundleEvent fe = (BundleEvent) eventList.get(i);
50 dump(fe);
51 }
52 }
53
54 boolean exists(String bundleName) {
55 for (int i = 0; i < eventList.size(); i++) {
56 BundleEvent fe = (BundleEvent) eventList.get(i);
57 Bundle b = fe.getBundle();
58 System.out.println("===[" + b + "]");
59 if (bundleName.equals(b.getSymbolicName())) {
60 return true;
61 }
62 }
63 return false;
64 }
65
66 }