Package de.aristaflow.adept2.util.i18n
Class ResourceBundleProvider<T>
- java.lang.Object
-
- de.aristaflow.adept2.util.i18n.ResourceBundleProvider<T>
-
- Type Parameters:
T
- The localising object based on aResourceBundle
.
- 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 Summary
Fields Modifier and Type Field Description protected String
baseName
The base name of the resource bundle.protected ConcurrentMap<Locale,T>
cache
A cache for retrieved bundles or alike.protected ClassLoader
classLoader
The class loader used to retrieve the resource bundles.protected ResourceBundle.Control
control
The control with which to load the resource bundle.
-
Constructor Summary
Constructors Modifier Constructor Description 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.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
apply(Locale l)
protected abstract T
convert(Locale reqLocale, ResourceBundle bundle)
Converts the designated resource bundle to the corresponding localising object.T
forLocale(Locale locale)
Returns the resource bundle or the related object for the specified locale.
-
-
-
Field Detail
-
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 Detail
-
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:
ResourceBundle.Control.getFormats(String)
-
-
Method Detail
-
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 isnull
, 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.
-
-