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.internal; 017 018import org.javamoney.moneta.OSGIServiceHelper; 019import org.javamoney.moneta.convert.IdentityRateProvider; 020import org.javamoney.moneta.spi.convert.DefaultMonetaryConversionsSingletonSpi; 021import org.osgi.framework.BundleActivator; 022import org.osgi.framework.BundleContext; 023 024import javax.money.convert.ExchangeRateProvider; 025import java.util.logging.Logger; 026 027/** 028 * A bundle activator that registers the OSGI services. 029 */ 030public class OSGIActivator implements BundleActivator { 031 032 private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName()); 033 034 @Override 035 public void start(BundleContext context) { 036 LOG.info("Registering JavaMoney services..."); 037 OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, IdentityRateProvider.class); 038 OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryConversionsSingletonSpi.class, DefaultMonetaryConversionsSingletonSpi.class); 039 LOG.info("Registered JavaMoney services..."); 040 } 041 042 @Override 043 public void stop(BundleContext context) { 044 LOG.info("Unregistering JavaMoney services..."); 045 OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, IdentityRateProvider.class); 046 OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryConversionsSingletonSpi.class, DefaultMonetaryConversionsSingletonSpi.class); 047 } 048}