Package com.broadleafcommerce.money
Class SystemCurrencyContextHolder
java.lang.Object
com.broadleafcommerce.money.SystemCurrencyContextHolder
A thread safe, system wide holder object used for obtaining a currency. This defaults to the currency set by the JVM default locale.
This uses the currency as a static global and provides threadsafe access.
- Author:
- Phillip Verheyden (phillipuniverse)
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Deprecated.static void
static javax.money.CurrencyUnit
Obtains the currently-configured system currency.static Optional<CurrencyContext>
Convenience method that returns the context configured by the holder.protected static Optional<javax.money.CurrencyUnit>
static void
setCurrency
(CurrencyContext context) Deprecated.UsesetProcessCurrency(CurrencyUnit)
insteadstatic void
setCurrency
(javax.money.CurrencyUnit currency) Updates this holder with the specified currency.static void
setProcessCurrency
(javax.money.CurrencyUnit currency) Sets the currency on a ThreadLocale object.
-
Method Details
-
setCurrency
Deprecated.UsesetProcessCurrency(CurrencyUnit)
insteadUpdates the holder with a specified context- Parameters:
context
- container for aCurrencyUnit
can be null
-
setProcessCurrency
public static void setProcessCurrency(javax.money.CurrencyUnit currency) Sets the currency on a ThreadLocale object. This will result in any call to obtain the default currency via this objectsgetCurrency()
method to return this value instead of the system default. Callers must ensure thatclearCurrency()
is called in a try / finally block so that default currency is restored after the operation is complete. -
getProcessCurrency
-
clearProcessCurrency
public static void clearProcessCurrency() -
setCurrency
public static void setCurrency(@Nullable javax.money.CurrencyUnit currency) Updates this holder with the specified currency. This should only be called during startup configuration- Parameters:
currency
- the currency to set to this holder, can be null
-
clearCurrency
public static void clearCurrency()Deprecated.Clears out any context associated with this holder -
getCurrency
@NonNull public static javax.money.CurrencyUnit getCurrency()Obtains the currently-configured system currency. If none was set by any other process, this defaults to the currency of the default JVMLocale
.- Returns:
- the currency for this holder
-
getCurrencyContext
Convenience method that returns the context configured by the holder. Most users will not use this method but instead will usegetCurrency()
as that method provides a fallback to a default currency.- Returns:
- the
CurrencyContext
managed by this holder, or null if none is set
-
clearProcessCurrency()