Class ResourceBundleProvider<T>

java.lang.Object
de.aristaflow.adept2.util.i18n.ResourceBundleProvider<T>
Type Parameters:
T - The localising object based on a ResourceBundle.
All Implemented Interfaces:
Function<Locale,T>
Direct Known Subclasses:
MessagesProvider, ResBundleSubclassProvider

public abstract class ResourceBundleProvider<T> extends Object implements Function<Locale,T>
This class provides resource bundles for various locales and caches them (or the corresponding related objects). This is coupled to a loading class providing the base name and the classloader (and usually also the key constants).

This class generalises from the concrete localising object. It loads the appropriate resource bundle, wraps it with the localising object and caches it.

The default function uses no locale fallback for the resource bundle.

  • Field Details

    • cache

      protected final ConcurrentMap<Locale,T> cache
      A cache for retrieved bundles or alike.
    • baseName

      protected final String baseName
      The base name of the resource bundle.
    • classLoader

      protected final ClassLoader classLoader
      The class loader used to retrieve the resource bundles.
    • control

      protected final ResourceBundle.Control control
      The control with which to load the resource bundle.
  • Constructor Details

    • ResourceBundleProvider

      protected ResourceBundleProvider(Class<?> loadingClass, List<String> bundleFormat)
      Constructs a new resource bundle provider for loading resource bundles for a specific locale for the designated class.
      Parameters:
      loadingClass - The class with which to load the resource bundle.
      bundleFormat - A list of bundle formats which to load, usually class and/or properties.
      See Also:
  • Method Details

    • forLocale

      public T forLocale(Locale locale)
      Returns the resource bundle or the related object for the specified locale.

      This method is thread-safe.

      Parameters:
      locale - The desired locale. If this is null, the default locale of the JVM will be used.
      Returns:
      The best-matching resource bundle or the related object for the specified locale.
    • convert

      protected abstract T convert(Locale reqLocale, ResourceBundle bundle)
      Converts the designated resource bundle to the corresponding localising object.
      Parameters:
      reqLocale - The requested locale. This may differ from the locale of the resource bundle.
      bundle - The resource bundle for which to get the corresponding localising object.
      Returns:
      The localising object for the designated resource bundle.
    • apply

      public T apply(Locale l)
      Specified by:
      apply in interface Function<Locale,T>