001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package org.slf4j.test_osgi;
015
016import java.util.ArrayList;
017import java.util.List;
018
019import org.osgi.framework.Bundle;
020import org.osgi.framework.BundleEvent;
021import org.osgi.framework.BundleListener;
022
023public class CheckingBundleListener implements BundleListener {
024
025    List<BundleEvent> eventList = new ArrayList<BundleEvent>();
026
027    public void bundleChanged(BundleEvent be) {
028        eventList.add(be);
029    }
030
031    private void dump(BundleEvent be) {
032        System.out.println("BundleEvent:" + ", source " + be.getSource() + ", bundle=" + be.getBundle() + ", type=" + be.getType());
033
034    }
035
036    public void dumpAll() {
037        for (int i = 0; i < eventList.size(); i++) {
038            BundleEvent fe = (BundleEvent) eventList.get(i);
039            dump(fe);
040        }
041    }
042
043    boolean exists(String bundleName) {
044        for (int i = 0; i < eventList.size(); i++) {
045            BundleEvent fe = (BundleEvent) eventList.get(i);
046            Bundle b = fe.getBundle();
047            System.out.println("===[" + b + "]");
048            if (bundleName.equals(b.getSymbolicName())) {
049                return true;
050            }
051        }
052        return false;
053    }
054
055}