Class SystemCurrencyContextHolder

java.lang.Object
com.broadleafcommerce.money.SystemCurrencyContextHolder

public class SystemCurrencyContextHolder extends Object

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 Details

    • setCurrency

      public static void setCurrency(@Nullable CurrencyContext context)
      Deprecated.
      Updates the holder with a specified context
      Parameters:
      context - container for a CurrencyUnit 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 objects getCurrency() method to return this value instead of the system default. Callers must ensure that clearCurrency() is called in a try / finally block so that default currency is restored after the operation is complete.
    • getProcessCurrency

      protected static Optional<javax.money.CurrencyUnit> 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 JVM Locale.
      Returns:
      the currency for this holder
    • getCurrencyContext

      public static Optional<CurrencyContext> getCurrencyContext()
      Convenience method that returns the context configured by the holder. Most users will not use this method but instead will use getCurrency() as that method provides a fallback to a default currency.
      Returns:
      the CurrencyContext managed by this holder, or null if none is set