javax.money.spi.CurrencyProviderSpi Java Examples
The following examples show how to use
javax.money.spi.CurrencyProviderSpi.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 6 votes |
/** * This default implementation simply returns all providers defined in arbitrary order. * * @return the default provider chain, never null. */ @Override public List<String> getDefaultProviderChain() { List<String> provList = new ArrayList<>(); String defaultChain = MonetaryConfig.getConfig().get("currencies.default-chain"); if(defaultChain!=null) { String[] items = defaultChain.split(","); for (String item : items) { if (getProviderNames().contains(item.trim())) { provList.add(item); } else { Logger.getLogger(getClass().getName()) .warning("Ignoring non existing default provider: " + item); } } } else{ Bootstrap.getServices(CurrencyProviderSpi.class).forEach( p -> provList.add(p.getProviderName()) ); } return provList; }
Example #2
Source File: OSGIActivator.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Override public void start(BundleContext context) { // Register marker service this.serviceProvider = new OSGIServiceProvider(context); LOG.info("Registered OSGI ServiceProvider..."); Bootstrap.init(this.serviceProvider); LOG.info("Registering JavaMoney services..."); OSGIServiceHelper.registerService(context.getBundle(), CurrencyProviderSpi.class, JDKCurrencyProvider.class); OSGIServiceHelper.registerService(context.getBundle(), CurrencyProviderSpi.class, ConfigurableCurrencyUnitProvider.class); OSGIServiceHelper.registerService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, FastMoneyAmountFactoryProvider.class); OSGIServiceHelper.registerService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, MoneyAmountFactoryProvider.class); OSGIServiceHelper.registerService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, RoundedMoneyAmountFactoryProvider.class); OSGIServiceHelper.registerService(context.getBundle(), MonetaryAmountFormatProviderSpi.class, DefaultAmountFormatProviderSpi.class); OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonQuerySpi.class, DefaultMonetaryAmountsSingletonQuerySpi.class); OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonQuerySpi.class, DefaultMonetaryAmountsSingletonQuerySpi.class); OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonSpi.class, DefaultMonetaryAmountsSingletonSpi.class); OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryCurrenciesSingletonSpi.class, DefaultMonetaryCurrenciesSingletonSpi.class); OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.RoundingProviderSpi.class, DefaultRoundingProvider.class); OSGIServiceHelper.registerService(context.getBundle(), LoaderService.class, DefaultLoaderService.class); LOG.info("Registered JavaMoney services..."); }
Example #3
Source File: OSGIActivator.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Override public void stop(BundleContext context) { if(serviceProvider!=null) { LOG.info("Unregistering JavaMoney services..."); OSGIServiceHelper.unregisterService(context.getBundle(), CurrencyProviderSpi.class, JDKCurrencyProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), CurrencyProviderSpi.class, ConfigurableCurrencyUnitProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, FastMoneyAmountFactoryProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, MoneyAmountFactoryProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), MonetaryAmountFactoryProviderSpi.class, RoundedMoneyAmountFactoryProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), MonetaryAmountFormatProviderSpi.class, DefaultAmountFormatProviderSpi.class); OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonQuerySpi.class, DefaultMonetaryAmountsSingletonQuerySpi.class); OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonQuerySpi.class, DefaultMonetaryAmountsSingletonQuerySpi.class); OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryAmountsSingletonSpi.class, DefaultMonetaryAmountsSingletonSpi.class); OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryCurrenciesSingletonSpi.class, DefaultMonetaryCurrenciesSingletonSpi.class); OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.RoundingProviderSpi.class, DefaultRoundingProvider.class); OSGIServiceHelper.unregisterService(context.getBundle(), LoaderService.class, DefaultLoaderService.class); } }
Example #4
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) { Set<CurrencyUnit> result = new HashSet<>(); List<CurrencyProviderSpi> providers = collectProviders(query); for (CurrencyProviderSpi spi : providers) { try { result.addAll(spi.getCurrencies(query)); } catch (Exception e) { Logger.getLogger(DefaultMonetaryCurrenciesSingletonSpi.class.getName()) .log(Level.SEVERE, "Error loading currency provider names for " + spi.getClass().getName(), e); } } return result; }
Example #5
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
private boolean isCurrencyAvailable(CurrencyQuery query) { for (CurrencyProviderSpi provider : collectProviders(query)) { if (provider.isCurrencyAvailable(query)) { return true; } } return false; }
Example #6
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
private CurrencyProviderSpi getProvider(String providerName) { for(CurrencyProviderSpi provider:Bootstrap.getServices(CurrencyProviderSpi.class)){ if(provider.getProviderName().equals(providerName)){ return provider; } } return null; }
Example #7
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * Get the names of the currently loaded providers. * * @return the names of the currently loaded providers, never null. */ @Override public Set<String> getProviderNames() { Set<String> result = new HashSet<>(); for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) { try { result.add(spi.getProviderName()); } catch (Exception e) { Logger.getLogger(DefaultMonetaryCurrenciesSingletonSpi.class.getName()) .log(Level.SEVERE, "Error loading currency provider names for " + spi.getClass().getName(), e); } } return result; }