Top Description Methods
javax.money.spi

public Interface MonetaryConversionsSingletonSpi

Imports
java.util.*, javax.money.CurrencyUnit, .MonetaryException, javax.money.convert.*

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.

Authors
Anatole Tresch, Werner Keil

Method Summary

Modifier and TypeMethod and Description
public default CurrencyConversion

Returns:

the corresponding conversion, not null.
getConversion
(ConversionQuery
the javax.money.convert.ConversionQuery determining the type of conversion required, not null.
conversionQuery
)

Access an instance of CurrencyConversion.

public default CurrencyConversion

Returns:

the corresponding conversion, not null.
getConversion
(CurrencyUnit
the terminating/target currency unit, not null.
termCurrency
,
String...
the javax.money.convert.ConversionQuery provider names defines a corresponding provider chain that must be encapsulated by the resulting default-package.money.convert.CurrencyConversion. By default the default provider chain as defined by #getDefaultCurrencyProviderChain will be used.
providers
)

Access an instance of CurrencyConversion.

public List<String>

Returns:

the default provider chain, not null and not empty.
getDefaultProviderChain
()

Get the default provider chain used.

public ExchangeRateProvider

Returns:

an ExchangeRateProvider built up with the given sub providers, never null
getExchangeRateProvider
(ConversionQuery
the javax.money.convert.ConversionQuery determining the type of conversion required, not null.
conversionQuery
)

Access an instance of ExchangeRateProvider.

public default ExchangeRateProvider

Returns:

an ExchangeRateProvider built up with the given sub providers, never null.
getExchangeRateProvider
(String...
the javax.money.convert.ConversionQuery provider names defines a corresponding provider chain that must be encapsulated by the resulting javax.money.convert.ExchangeRateProvider. By default the default provider changes as defined in #getDefaultCurrencyProviderChain will be used.
providers
)

Access a compound instance of an ExchangeRateProvider based on the given provider chain.

public default List<ExchangeRateProvider>

Returns:

the list of providers, in the same order as requested.
getExchangeRateProviders
(String...
the provider names of the providers to be accessed
providers
)

Access the current registered javax.money.convert.ExchangeRateProvider instances.

public Collection<String>

Returns:

all currently registered provider names
getProviderNames
()

Get all currently registered provider names.

public default boolean

Returns:

true, if such a conversion is supported, meaning an according CurrencyConversion can be accessed.
isConversionAvailable
(ConversionQuery
the javax.money.convert.ConversionQuery determining the type of conversion required, not null.
conversionQuery
)

Allows to quickly check, if a javax.money.convert.CurrencyConversion is accessible for the given javax.money.convert.ConversionQuery.

public default boolean

Returns:

true, if such a conversion is supported, meaning an according CurrencyConversion can be accessed.
isConversionAvailable
(CurrencyUnit
the terminating/target currency unit, not null.
termCurrency
,
String...
the provider names defines a corresponding provider chain that must be encapsulated by the resulting default-package.money.convert.CurrencyConversion. By default the provider chain as defined by #getDefaultCurrencyProviderChain will be used.
providers
)

Allows to quickly check, if a javax.money.convert.CurrencyConversion is accessible for the given javax.money.convert.ConversionQuery.

public default boolean

Returns:

true, if such a conversion is supported, meaning an according ExchangeRateProvider can be accessed.
isExchangeRateProviderAvailable
(ConversionQuery
the javax.money.convert.ConversionQuery determining the type of conversion required, not null.
conversionQuery
)

Allows to quickly check, if a javax.money.convert.ExchangeRateProvider is accessible for the given javax.money.convert.ConversionQuery.

Method Detail

getConversionback to summary
public default CurrencyConversion getConversion(ConversionQuery conversionQuery)

Access an instance of CurrencyConversion.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery determining the type of conversion required, not null.

Returns:CurrencyConversion

the corresponding conversion, not null.

Exceptions
MonetaryException:
if no matching conversion could be found.
See Also
isConversionAvailable(javax.money.convert.ConversionQuery)
getConversionback to summary
public default CurrencyConversion getConversion(CurrencyUnit termCurrency, String... providers)

Access an instance of CurrencyConversion.

Parameters
termCurrency:CurrencyUnit

the terminating/target currency unit, not null.

providers:String[]

the javax.money.convert.ConversionQuery provider names defines a corresponding provider chain that must be encapsulated by the resulting default-package.money.convert.CurrencyConversion. By default the default provider chain as defined by #getDefaultCurrencyProviderChain will be used.

Returns:CurrencyConversion

the corresponding conversion, not null.

Exceptions
MonetaryException:
if no matching conversion could be found.
See Also
isConversionAvailable(javax.money.convert.ConversionQuery)
getDefaultProviderChainback to summary
public List<String> getDefaultProviderChain()

Get the default provider chain used. The ordering of the items is the access order/precedence of the providers.

Returns:List<String>

the default provider chain, not null and not empty.

getExchangeRateProviderback to summary
public ExchangeRateProvider getExchangeRateProvider(ConversionQuery conversionQuery)

Access an instance of ExchangeRateProvider. 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 default-package.money.convert.ConversionQuery.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery determining the type of conversion required, not null.

Returns:ExchangeRateProvider

an ExchangeRateProvider built up with the given sub providers, never null

Exceptions
MonetaryException:
if a provider could not be found.
See Also
isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery)
getExchangeRateProviderback to summary
public default ExchangeRateProvider getExchangeRateProvider(String... providers)

Access a compound instance of an ExchangeRateProvider based on the given provider chain.

Parameters
providers:String[]

the javax.money.convert.ConversionQuery provider names defines a corresponding provider chain that must be encapsulated by the resulting javax.money.convert.ExchangeRateProvider. By default the default provider changes as defined in #getDefaultCurrencyProviderChain will be used.

Returns:ExchangeRateProvider

an ExchangeRateProvider built up with the given sub providers, never null.

Exceptions
MonetaryException:
if a provider listed could not be found.
See Also
getProviderNames(), isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery)
getExchangeRateProvidersback to summary
public default List<ExchangeRateProvider> getExchangeRateProviders(String... providers)

Access the current registered javax.money.convert.ExchangeRateProvider instances. If no provider names are passed ALL current registered providers are returned in undefined order.

Parameters
providers:String[]

the provider names of the providers to be accessed

Returns:List<ExchangeRateProvider>

the list of providers, in the same order as requested.

Exceptions
MonetaryException:
if a provider could not be resolved.
getProviderNamesback to summary
public Collection<String> getProviderNames()

Get all currently registered provider names.

Returns:Collection<String>

all currently registered provider names

See Also
ProviderContext#getProviderName()
isConversionAvailableback to summary
public default boolean isConversionAvailable(ConversionQuery conversionQuery)

Allows to quickly check, if a javax.money.convert.CurrencyConversion is accessible for the given javax.money.convert.ConversionQuery.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery determining the type of conversion required, not null.

Returns:boolean

true, if such a conversion is supported, meaning an according CurrencyConversion can be accessed.

See Also
getConversion(javax.money.convert.ConversionQuery), getConversion(CurrencyUnit, String...)
isConversionAvailableback to summary
public default boolean isConversionAvailable(CurrencyUnit termCurrency, String... providers)

Allows to quickly check, if a javax.money.convert.CurrencyConversion is accessible for the given javax.money.convert.ConversionQuery.

Parameters
termCurrency:CurrencyUnit

the terminating/target currency unit, not null.

providers:String[]

the provider names defines a corresponding provider chain that must be encapsulated by the resulting default-package.money.convert.CurrencyConversion. By default the provider chain as defined by #getDefaultCurrencyProviderChain will be used.

Returns:boolean

true, if such a conversion is supported, meaning an according CurrencyConversion can be accessed.

See Also
getConversion(javax.money.convert.ConversionQuery), getConversion(CurrencyUnit, String...)
isExchangeRateProviderAvailableback to summary
public default boolean isExchangeRateProviderAvailable(ConversionQuery conversionQuery)

Allows to quickly check, if a javax.money.convert.ExchangeRateProvider is accessible for the given javax.money.convert.ConversionQuery.

Parameters
conversionQuery:ConversionQuery

the javax.money.convert.ConversionQuery determining the type of conversion required, not null.

Returns:boolean

true, if such a conversion is supported, meaning an according ExchangeRateProvider can be accessed.

See Also
getExchangeRateProvider(ConversionQuery), getExchangeRateProvider(String...)