001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package de.mnl.osgi.log4j2osgi;
020
021import java.util.Dictionary;
022import java.util.Hashtable;
023import org.apache.logging.log4j.spi.Provider;
024import org.osgi.framework.BundleActivator;
025import org.osgi.framework.BundleContext;
026import org.osgi.framework.ServiceRegistration;
027
028/**
029 * The activator for this bundle.
030 */
031public class Activator implements BundleActivator {
032
033    private ServiceRegistration<Provider> serviceRegistration;
034
035    /**
036     * Start.
037     *
038     * @param context the context
039     * @throws Exception the exception
040     */
041    @Override
042    public void start(BundleContext context) throws Exception {
043        Dictionary<String, Object> props = new Hashtable<>();
044        props.put("APIVersion", "2.6.0");
045        serviceRegistration = context.registerService(Provider.class,
046            new OsgiProvider(), props);
047    }
048
049    /**
050     * Stop.
051     *
052     * @param context the context
053     * @throws Exception the exception
054     */
055    @Override
056    public void stop(BundleContext context) throws Exception {
057        serviceRegistration.unregister();
058    }
059
060}