/*
* CREDIT SUISSE IS WILLING TO LICENSE THIS SPECIFICATION TO YOU ONLY UPON THE
* CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS AGREEMENT.
* PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY. BY
* DOWNLOADING THIS SPECIFICATION, YOU ACCEPT THE TERMS AND CONDITIONS OF THE
* AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY IT, SELECT THE "DECLINE"
* BUTTON AT THE BOTTOM OF THIS PAGE.
*
* Specification: JSR-354 Money and Currency API ("Specification")
*
* Copyright (c) 2012-2013, Credit Suisse All rights reserved.
*/
package javax.money;
import javax.money.spi.Bootstrap;
import javax.money.spi.CurrencyProviderSpi;
import javax.money.spi.MonetaryCurrenciesSingletonSpi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Factory singleton for CurrencyUnit
instances as provided by the different registered CurrencyProviderSpi
instances.
This class is thread safe.
Author: Anatole Tresch Version: 0.8
/**
* Factory singleton for {@link CurrencyUnit} instances as provided by the
* different registered {@link javax.money.spi.CurrencyProviderSpi} instances.
* <p/>
* This class is thread safe.
*
* @author Anatole Tresch
* @version 0.8
*/
final class DefaultMonetaryCurrenciesSingletonSpi implements MonetaryCurrenciesSingletonSpi {
@Override
public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) {
Set<CurrencyUnit> result = new HashSet<>();
for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
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;
}
This default implementation simply returns all providers defined in arbitrary order.
Returns: the default provider chain, never null.
/**
* 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> list = new ArrayList<>();
list.addAll(getProviderNames());
Collections.sort(list);
return list;
}
Get the names of the currently loaded providers.
Returns: the names of the currently loaded providers, never null.
/**
* 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;
}
}