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.FrameworkEvent;
20  import org.osgi.framework.FrameworkListener;
21  
22  public class FrameworkErrorListener implements FrameworkListener {
23  
24      public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>();
25  
26      public void frameworkEvent(FrameworkEvent fe) {
27          if (fe.getType() == FrameworkEvent.ERROR) {
28              errorList.add(fe);
29          }
30      }
31  
32      private void dump(FrameworkEvent fe) {
33          Throwable t = fe.getThrowable();
34          String tString = null;
35          if (t != null) {
36              tString = t.toString();
37          }
38          System.out.println(
39                  "Framework ERROR:" + ", source " + fe.getSource() + ", bundle=" + fe.getBundle() + ", ex=" + tString);
40          if (t != null) {
41              t.printStackTrace();
42          }
43      }
44  
45      public void dumpAll() {
46          for (int i = 0; i < errorList.size(); i++) {
47              FrameworkEvent fe = (FrameworkEvent) errorList.get(i);
48              dump(fe);
49          }
50      }
51  }