Search in sources :

Example 1 with CurrencyProviderSpi

use of javax.money.spi.CurrencyProviderSpi in project jsr354-ri-bp by JavaMoney.

the class DefaultMonetaryCurrenciesSingletonSpi method getCurrencies.

@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;
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) CurrencyProviderSpi(javax.money.spi.CurrencyProviderSpi) HashSet(java.util.HashSet)

Example 2 with CurrencyProviderSpi

use of javax.money.spi.CurrencyProviderSpi in project jsr354-ri by JavaMoney.

the class DefaultMonetaryCurrenciesSingletonSpi method getCurrencies.

@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;
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) CurrencyProviderSpi(javax.money.spi.CurrencyProviderSpi) HashSet(java.util.HashSet)

Example 3 with CurrencyProviderSpi

use of javax.money.spi.CurrencyProviderSpi in project jsr354-ri-bp by JavaMoney.

the class DefaultMonetaryCurrenciesSingletonSpi method getDefaultProviderChain.

/**
 * 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 {
        for (CurrencyProviderSpi currencyProviderSpi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
            provList.add(currencyProviderSpi.getProviderName());
        }
    }
    return provList;
}
Also used : CurrencyProviderSpi(javax.money.spi.CurrencyProviderSpi) ArrayList(java.util.ArrayList)

Aggregations

CurrencyProviderSpi (javax.money.spi.CurrencyProviderSpi)3 HashSet (java.util.HashSet)2 CurrencyUnit (javax.money.CurrencyUnit)2 ArrayList (java.util.ArrayList)1