View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package org.slf4j.test_osgi;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import org.osgi.framework.Bundle;
20  import org.osgi.framework.BundleEvent;
21  import org.osgi.framework.BundleListener;
22  
23  public class CheckingBundleListener implements BundleListener {
24  
25      List<BundleEvent> eventList = new ArrayList<BundleEvent>();
26  
27      public void bundleChanged(BundleEvent be) {
28          eventList.add(be);
29      }
30  
31      private void dump(BundleEvent be) {
32          System.out.println("BundleEvent:" + ", source " + be.getSource() + ", bundle=" + be.getBundle() + ", type=" + be.getType());
33  
34      }
35  
36      public void dumpAll() {
37          for (int i = 0; i < eventList.size(); i++) {
38              BundleEvent fe = (BundleEvent) eventList.get(i);
39              dump(fe);
40          }
41      }
42  
43      boolean exists(String bundleName) {
44          for (int i = 0; i < eventList.size(); i++) {
45              BundleEvent fe = (BundleEvent) eventList.get(i);
46              Bundle b = fe.getBundle();
47              System.out.println("===[" + b + "]");
48              if (bundleName.equals(b.getSymbolicName())) {
49                  return true;
50              }
51          }
52          return false;
53      }
54  
55  }