public interface MonetaryConversionsSingletonSpi
SPI (conversion) that implements the functionality provided by the
MonetaryConversions singleton accessor. It should be registered as a
service using the JDK ServiceLoader. Hereby only one instance can be
registered at a time.
This interface is designed to support also contextual behaviour, e.g. in Java
EE containers each application may provide its own
ExchangeRateProvider instances, e.g. by registering them as CDI
beans. An EE container can register an according
MonetaryConversionsSingletonSpi that manages the different application
contexts transparently. In a SE environment this class is expected to behave
like an ordinary singleton, loading its SPIs from the ServiceLoader.
Instances of this class must be thread safe. It is not a requirement that they are serializable.
Only one instance can be registered using the ServiceLoader. When
registering multiple instances the MonetaryConversions accessor will
not work.
- Author:
- Anatole Tresch, Werner Keil
-
Method Summary
Modifier and Type Method Description default CurrencyConversiongetConversion(ConversionQuery conversionQuery)Access an instance ofCurrencyConversion.default CurrencyConversiongetConversion(CurrencyUnit termCurrency, java.lang.String... providers)Access an instance ofCurrencyConversion.java.util.List<java.lang.String>getDefaultProviderChain()Get the default provider chain used.default ExchangeRateProvidergetExchangeRateProvider(java.lang.String... providers)Access a compound instance of anExchangeRateProviderbased on the given provider chain.ExchangeRateProvidergetExchangeRateProvider(ConversionQuery conversionQuery)Access an instance ofExchangeRateProvider.default java.util.List<ExchangeRateProvider>getExchangeRateProviders(java.lang.String... providers)Access the current registeredExchangeRateProviderinstances.java.util.Collection<java.lang.String>getProviderNames()Get all currently registered provider names.default booleanisConversionAvailable(ConversionQuery conversionQuery)Allows to quickly check, if aCurrencyConversionis accessible for the givenConversionQuery.default booleanisConversionAvailable(CurrencyUnit termCurrency, java.lang.String... providers)Allows to quickly check, if aCurrencyConversionis accessible for the givenConversionQuery.default booleanisExchangeRateProviderAvailable(ConversionQuery conversionQuery)Allows to quickly check, if aExchangeRateProvideris accessible for the givenConversionQuery.
-
Method Details
-
getProviderNames
java.util.Collection<java.lang.String> getProviderNames()Get all currently registered provider names.- Returns:
- all currently registered provider names
- See Also:
AbstractContext.getProviderName()
-
getDefaultProviderChain
java.util.List<java.lang.String> getDefaultProviderChain()Get the default provider chain used. The ordering of the items is the access order/precedence of the providers.- Returns:
- the default provider chain, not
nulland not empty.
-
getExchangeRateProvider
Access an instance ofExchangeRateProvider. By setting.ConversionQuery#getCurrencyProviderNames()multiple providers can be selected, that will be included into a compound instance, with the same order as returned by the.money.convert.ConversionQuery.- Parameters:
conversionQuery- theConversionQuerydetermining the type of conversion required, not null.- Returns:
- an
ExchangeRateProviderbuilt up with the given sub providers, nevernull - Throws:
MonetaryException- if a provider could not be found.- See Also:
isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery)
-
isExchangeRateProviderAvailable
Allows to quickly check, if aExchangeRateProvideris accessible for the givenConversionQuery.- Parameters:
conversionQuery- theConversionQuerydetermining the type of conversion required, not null.- Returns:
true, if such a conversion is supported, meaning an accordingExchangeRateProvidercan be accessed.- See Also:
getExchangeRateProvider(ConversionQuery),getExchangeRateProvider(String...)
-
isConversionAvailable
Allows to quickly check, if aCurrencyConversionis accessible for the givenConversionQuery.- Parameters:
conversionQuery- theConversionQuerydetermining the type of conversion required, not null.- Returns:
true, if such a conversion is supported, meaning an accordingCurrencyConversioncan be accessed.- See Also:
getConversion(javax.money.convert.ConversionQuery),getConversion(CurrencyUnit, String...)
-
isConversionAvailable
Allows to quickly check, if aCurrencyConversionis accessible for the givenConversionQuery.- Parameters:
termCurrency- the terminating/target currency unit, not null.providers- the provider names defines a corresponding provider chain that must be encapsulated by the resulting.money.convert.CurrencyConversion. By default the provider chain as defined by #getDefaultCurrencyProviderChain will be used.- Returns:
true, if such a conversion is supported, meaning an accordingCurrencyConversioncan be accessed.- See Also:
getConversion(javax.money.convert.ConversionQuery),getConversion(CurrencyUnit, String...)
-
getExchangeRateProviders
default java.util.List<ExchangeRateProvider> getExchangeRateProviders(java.lang.String... providers)Access the current registeredExchangeRateProviderinstances. If no provider names are passed ALL current registered providers are returned in undefined order.- Parameters:
providers- the provider names of the providers to be accessed- Returns:
- the list of providers, in the same order as requested.
- Throws:
MonetaryException- if a provider could not be resolved.
-
getExchangeRateProvider
Access a compound instance of anExchangeRateProviderbased on the given provider chain.- Parameters:
providers- theConversionQueryprovider names defines a corresponding provider chain that must be encapsulated by the resultingExchangeRateProvider. By default the default provider changes as defined in #getDefaultCurrencyProviderChain will be used.- Returns:
- an
ExchangeRateProviderbuilt up with the given sub providers, nevernull. - Throws:
MonetaryException- if a provider listed could not be found.- See Also:
getProviderNames(),isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery)
-
getConversion
Access an instance ofCurrencyConversion.- Parameters:
conversionQuery- theConversionQuerydetermining the type of conversion required, not null.- Returns:
- the corresponding conversion, not null.
- Throws:
MonetaryException- if no matching conversion could be found.- See Also:
isConversionAvailable(javax.money.convert.ConversionQuery)
-
getConversion
Access an instance ofCurrencyConversion.- Parameters:
termCurrency- the terminating/target currency unit, not null.providers- theConversionQueryprovider names defines a corresponding provider chain that must be encapsulated by the resulting.money.convert.CurrencyConversion. By default the default provider chain as defined by #getDefaultCurrencyProviderChain will be used.- Returns:
- the corresponding conversion, not null.
- Throws:
MonetaryException- if no matching conversion could be found.- See Also:
isConversionAvailable(javax.money.convert.ConversionQuery)
-