Class StoredBundleFactory
- All Implemented Interfaces:
org.tentackle.common.BundleFactory
Replaces the DefaultBundleFactory. For each bundle registered via BundleSupport, it loads
the StoredBundles of the requested locale and its parent locales, chains them as
StoredResourceBundles and appends the property-file bundle as the last resort, unless
fallbackToProperties is turned off.
The resulting chains are cached until a StoredBundle is modified.
In non-modular applications, all bundles are loaded through the StoredBundleControl handed out by the
StoredBundleControlProvider instead.
Without a current Session, or if disabled, the factory behaves like
the DefaultBundleFactory. Bundles loaded before the first session became available are discarded
as soon as it does, so that the stored bundles take over.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfindBundle(String baseName, Locale locale) findBundle(String baseName, Locale locale, ClassLoader loader) protected ResourceBundlestatic booleanReturns whether loading bundles from the backend is enabled at all.protected StoredResourceBundleloadStoredBundleChain(StoredBundle.StoredBundleUDK topKey, Function<StoredBundle.StoredBundleUDK, StoredResourceBundle> loader) Loads the stored bundle for a key and chains the stored bundles of the parent locales to it.static voidsetEnabled(boolean enabled) Sets whether loading bundles from the backend is enabled at all.Methods inherited from class org.tentackle.common.DefaultBundleFactory
createProviders, getClassLoader, getControl, getProviders, normalizeBasename, setClassLoader
-
Constructor Details
-
StoredBundleFactory
public StoredBundleFactory()Creates the bundle factory.
-
-
Method Details
-
isEnabled
public static boolean isEnabled()Returns whether loading bundles from the backend is enabled at all.- Returns:
- true if enabled (default)
-
setEnabled
public static void setEnabled(boolean enabled) Sets whether loading bundles from the backend is enabled at all.Applies to the bundles loaded by this factory as well as to those loaded by the
StoredBundleControl. Bundles already cached are not affected: set the flag before the first lookup, or invokeBundleFactory.clearCache()afterward.- Parameters:
enabled- true if enabled (default)
-
clearCache
public void clearCache()- Specified by:
clearCachein interfaceorg.tentackle.common.BundleFactory- Overrides:
clearCachein classorg.tentackle.common.DefaultBundleFactory
-
findBundle
- Specified by:
findBundlein interfaceorg.tentackle.common.BundleFactory- Overrides:
findBundlein classorg.tentackle.common.DefaultBundleFactory
-
findBundle
- Specified by:
findBundlein interfaceorg.tentackle.common.BundleFactory- Overrides:
findBundlein classorg.tentackle.common.DefaultBundleFactory
-
getBundle
- Overrides:
getBundlein classorg.tentackle.common.DefaultBundleFactory
-
loadStoredBundleChain
protected StoredResourceBundle loadStoredBundleChain(StoredBundle.StoredBundleUDK topKey, Function<StoredBundle.StoredBundleUDK, StoredResourceBundle> loader) Loads the stored bundle for a key and chains the stored bundles of the parent locales to it.Locales without a stored bundle are skipped, both when looking for the bundle itself and when linking its parents, just as
ResourceBundledoes for its list of candidate locales. A storedTexts_de_DE, for example, gets a storedTextsas its parent if there is noTexts_de.- Parameters:
topKey- the key of the requested bundleloader- loads the stored bundle for a key, returns null if there is no such bundle- Returns:
- the bundle with its parents linked, null if nothing is stored for the key or any of its parent locales
-