public abstract class BaseMonetaryConversionsSingletonSpi extends Object implements javax.money.spi.MonetaryConversionsSingletonSpi
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
BaseMonetaryConversionsSingletonSpi
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.
Constructor and Description |
---|
BaseMonetaryConversionsSingletonSpi() |
Modifier and Type | Method and Description |
---|---|
javax.money.convert.CurrencyConversion |
getConversion(javax.money.convert.ConversionQuery conversionQuery)
Access an instance of
CurrencyConversion . |
javax.money.convert.CurrencyConversion |
getConversion(javax.money.CurrencyUnit termCurrency,
String... providers)
Access an instance of
CurrencyConversion . |
javax.money.convert.ExchangeRateProvider |
getExchangeRateProvider(String... providers)
Access a compound instance of an
ExchangeRateProvider based on the given provider chain. |
List<javax.money.convert.ExchangeRateProvider> |
getExchangeRateProviders(String... providers)
Access the current registered
ExchangeRateProvider instances. |
boolean |
isConversionAvailable(javax.money.convert.ConversionQuery conversionQuery)
Allows to quickly check, if a
CurrencyConversion is accessible for the given
ConversionQuery . |
boolean |
isConversionAvailable(javax.money.CurrencyUnit termCurrency,
String... providers)
Allows to quickly check, if a
CurrencyConversion is accessible for the given
ConversionQuery . |
boolean |
isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery conversionQuery)
Allows to quickly check, if a
ExchangeRateProvider is accessible for the given
ConversionQuery . |
public BaseMonetaryConversionsSingletonSpi()
public boolean isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery conversionQuery)
ExchangeRateProvider
is accessible for the given
ConversionQuery
.isExchangeRateProviderAvailable
in interface javax.money.spi.MonetaryConversionsSingletonSpi
conversionQuery
- the ConversionQuery
determining the type of conversion
required, not null.true
, if such a conversion is supported, meaning an according
ExchangeRateProvider
can be
accessed.MonetaryConversionsSingletonSpi.getExchangeRateProvider(javax.money.convert.ConversionQuery)
,
getExchangeRateProvider(String...)}
public boolean isConversionAvailable(javax.money.convert.ConversionQuery conversionQuery)
CurrencyConversion
is accessible for the given
ConversionQuery
.isConversionAvailable
in interface javax.money.spi.MonetaryConversionsSingletonSpi
conversionQuery
- the ConversionQuery
determining the type of conversion
required, not null.true
, if such a conversion is supported, meaning an according
CurrencyConversion
can be
accessed.getConversion(javax.money.convert.ConversionQuery)
,
getConversion(javax.money.CurrencyUnit, String...)}
public boolean isConversionAvailable(javax.money.CurrencyUnit termCurrency, String... providers)
CurrencyConversion
is accessible for the given
ConversionQuery
.isConversionAvailable
in interface javax.money.spi.MonetaryConversionsSingletonSpi
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 #getDefaultRoundingProviderChain will be used.true
, if such a conversion is supported, meaning an according
CurrencyConversion
can be
accessed.getConversion(javax.money.convert.ConversionQuery)
,
getConversion(javax.money.CurrencyUnit, String...)}
public List<javax.money.convert.ExchangeRateProvider> getExchangeRateProviders(String... providers)
ExchangeRateProvider
instances. If no provider
names are passed ALL current registered providers are returned in undefined order.getExchangeRateProviders
in interface javax.money.spi.MonetaryConversionsSingletonSpi
providers
- the provider names of hte providers to be accessedjavax.money.MonetaryException
- if a provider could not be resolved.public javax.money.convert.ExchangeRateProvider getExchangeRateProvider(String... providers)
ExchangeRateProvider
based on the given provider chain.getExchangeRateProvider
in interface javax.money.spi.MonetaryConversionsSingletonSpi
providers
- the ConversionQuery
provider names defines a corresponding
provider chain that must be
encapsulated by the resulting ExchangeRateProvider
. By default
the default
provider changes as defined in #getDefaultRoundingProviderChain will be used.ExchangeRateProvider
built up with the given sub
providers, never null
.javax.money.MonetaryException
- if a provider listed could not be found.MonetaryConversionsSingletonSpi.getProviderNames()
,
isExchangeRateProviderAvailable(javax.money.convert.ConversionQuery)
public javax.money.convert.CurrencyConversion getConversion(javax.money.convert.ConversionQuery conversionQuery)
CurrencyConversion
.getConversion
in interface javax.money.spi.MonetaryConversionsSingletonSpi
conversionQuery
- the ConversionQuery
determining the type of conversion
required, not null.javax.money.MonetaryException
- if no matching conversion could be found.isConversionAvailable(javax.money.convert.ConversionQuery)
public javax.money.convert.CurrencyConversion getConversion(javax.money.CurrencyUnit termCurrency, String... providers)
CurrencyConversion
.getConversion
in interface javax.money.spi.MonetaryConversionsSingletonSpi
termCurrency
- the terminating/target currency unit, not null.providers
- the ConversionQuery
provider 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 #getDefaultRoundingProviderChain will be used.javax.money.MonetaryException
- if no matching conversion could be found.isConversionAvailable(javax.money.convert.ConversionQuery)
Copyright © 2012-2015 JavaMoney. All Rights Reserved.