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
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
FieldsModifier and TypeFieldDescriptionprotected final StringThe base name of the resource bundle.protected final ConcurrentMap<Locale,T> A cache for retrieved bundles or alike.protected final ClassLoaderThe class loader used to retrieve the resource bundles.protected final ResourceBundle.ControlThe control with which to load the resource bundle. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedResourceBundleProvider(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
Modifier and TypeMethodDescriptionprotected abstract Tconvert(Locale reqLocale, ResourceBundle bundle) Converts the designated resource bundle to the corresponding localising object.Returns the resource bundle or the related object for the specified locale.
-
Field Details
-
cache
A cache for retrieved bundles or alike. -
baseName
The base name of the resource bundle. -
classLoader
The class loader used to retrieve the resource bundles. -
control
The control with which to load the resource bundle.
-
-
Constructor Details
-
ResourceBundleProvider
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
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
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
-