001/*
002  Copyright (c) 2012, 2019, Anatole Tresch, Werner Keil and others by the @author tag.
003
004  Licensed under the Apache License, Version 2.0 (the "License"); you may not
005  use this file except in compliance with the License. You may obtain a copy of
006  the License at
007
008  http://www.apache.org/licenses/LICENSE-2.0
009
010  Unless required by applicable law or agreed to in writing, software
011  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013  License for the specific language governing permissions and limitations under
014  the License.
015 */
016package org.javamoney.moneta.convert.ecb;
017
018import org.javamoney.moneta.OSGIServiceHelper;
019import org.osgi.framework.BundleActivator;
020import org.osgi.framework.BundleContext;
021
022import javax.money.convert.ExchangeRateProvider;
023import java.util.logging.Logger;
024
025/**
026 * A bundle activator that registers the OSGI services.
027 */
028public class OSGIActivator implements BundleActivator {
029
030    private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName());
031
032    @Override
033    public void start(BundleContext context) {
034        LOG.info("Registering JavaMoney services...");
035        OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBCurrentRateProvider.class);
036        OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBHistoricRateProvider.class);
037        OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBHistoric90RateProvider.class);
038        LOG.info("Registered JavaMoney services...");
039    }
040
041    @Override
042    public void stop(BundleContext context) {
043        LOG.info("Unregistering JavaMoney services...");
044        OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBCurrentRateProvider.class);
045        OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBHistoricRateProvider.class);
046        OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBHistoric90RateProvider.class);
047    }
048}