use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getDefaultProviderChain.
@Override
public List<String> getDefaultProviderChain() {
List<String> provList = new ArrayList<>();
String defaultChain = MonetaryConfig.getConfig().get("conversion.default-chain");
if (defaultChain != null) {
String[] items = defaultChain.split(",");
for (String item : items) {
if (getProviderNames().contains(item.trim())) {
provList.add(item);
} else {
LOG.warning("Ignoring non existing default provider: " + item);
}
}
} else {
for (ExchangeRateProvider p : Bootstrap.getServices(ExchangeRateProvider.class)) {
provList.add(p.getContext().getProviderName());
}
}
return provList;
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getExchangeRateProvider.
@Override
public ExchangeRateProvider getExchangeRateProvider(String... providers) {
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = this.conversionProviders.get(provName);
if (prov == null) {
throw new MonetaryException("Unsupported conversion/rate provider: " + provName);
}
provInstances.add(prov);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method reload.
/**
* Reloads/reinitializes the providers found.
*/
public void reload() {
Map<String, ExchangeRateProvider> newProviders = new ConcurrentHashMap<>();
for (ExchangeRateProvider prov : Bootstrap.getServices(ExchangeRateProvider.class)) {
newProviders.put(prov.getContext().getProviderName(), prov);
}
this.conversionProviders = newProviders;
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsECBHistoricRateProvider.
@Test
public void shouldReturnsECBHistoricRateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB_HIST);
assertTrue(Objects.nonNull(prov));
assertEquals(ECBHistoricRateProvider.class, prov.getClass());
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsECBHistoric90RateProvider.
@Test
public void shouldReturnsECBHistoric90RateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB_HIST90);
assertTrue(Objects.nonNull(prov));
assertEquals(ECBHistoric90RateProvider.class, prov.getClass());
}
Aggregations