Class StoredBundleControl
- All Implemented Interfaces:
DomainContextProvider
newBundle(String, Locale, String, ClassLoader, boolean) loads the StoredBundle for the requested base name and locale and wraps it in a
StoredResourceBundle. If nothing is stored, it falls back to the property file, unless
fallbackToProperties is turned off. A load that fails, because the
backend is unreachable, for example, falls back to the property file as well, but the result is not cached
(see getTimeToLive(String, Locale)).
As long as there is no current Session or loading from the
backend is disabled, the control behaves like the standard ResourceBundle.Control.
The control is handed out by the StoredBundleControlProvider in non-modular applications. StoredBundleFactory does not use it as a control, but reuses createUDK(String, Locale) and
loadStoredBundle(StoredBundle.StoredBundleUDK) to load the bundles of named modules.
- Author:
- harald
-
Field Summary
Fields inherited from class ResourceBundle.Control
FORMAT_CLASS, FORMAT_DEFAULT, FORMAT_PROPERTIES, TTL_DONT_CACHE, TTL_NO_EXPIRATION_CONTROL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StoredBundle.StoredBundleUDKCreates the unique domain key to load a stored bundle.Gets the domain context.getFormats(String baseName) longgetTimeToLive(String baseName, Locale locale) protected booleanReturns whether bundles can be loaded from the backend.static booleanReturns whether the property files are used if a bundle or key is not stored in the database.protected StoredResourceBundleLoads the bundle from storage.newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) static voidsetFallbackToProperties(boolean fallbackToProperties) Sets whether the property files are used if a bundle or key is not stored in the database.Methods inherited from class ResourceBundle.Control
getCandidateLocales, getControl, getFallbackLocale, getNoFallbackControl, needsReload, toBundleName, toResourceNameMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DomainContextProvider
isWithinContext, isWithinContext, on, on, op, op
-
Constructor Details
-
StoredBundleControl
public StoredBundleControl()Creates a stored bundle control object.
-
-
Method Details
-
isFallbackToProperties
public static boolean isFallbackToProperties()Returns whether the property files are used if a bundle or key is not stored in the database.Applies to the bundles loaded by this control as well as to those loaded by
StoredBundleFactory.- Returns:
- true if falling back to the property files (default)
-
setFallbackToProperties
public static void setFallbackToProperties(boolean fallbackToProperties) Sets whether the property files are used if a bundle or key is not stored in the database.- Parameters:
fallbackToProperties- true to fall back to the property files, false to throw aMissingResourceExceptioninstead
-
getDomainContext
Description copied from interface:DomainContextProviderGets the domain context.- Specified by:
getDomainContextin interfaceDomainContextProvider- Returns:
- the domain context
-
getFormats
- Overrides:
getFormatsin classResourceBundle.Control
-
getTimeToLive
- Overrides:
getTimeToLivein classResourceBundle.Control
-
newBundle
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException - Overrides:
newBundlein classResourceBundle.Control- Throws:
IllegalAccessExceptionInstantiationExceptionIOException
-
isBackendLoadable
protected boolean isBackendLoadable()Returns whether bundles can be loaded from the backend.Requires a current session and
StoredBundleFactory.isEnabled(). The latter must be checked here as well, since in non-modular applications, bundles are loaded through this control and never reach the factory's own check.- Returns:
- true if loading from the backend is possible
-
createUDK
Creates the unique domain key to load a stored bundle.The locale suffix is derived from the locale, not by searching the bundle name for an underscore: base names may contain underscores themselves, and
org.myapp.Texts_v2must not be read as the bundleorg.myapp.Textsfor the localev2.- Parameters:
baseName- the base bundle name of the resource bundlelocale- the locale- Returns:
- the unique domain key
-
loadStoredBundle
Loads the bundle from storage.A failure the backend reports as temporary (the modification tracker is not running yet, for example) is treated like a missing bundle, any other exception is thrown.
- Parameters:
key- the unique domain key- Returns:
- the stored resource bundle or null if no such bundle in the database
-