|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.util.AbstractResourceBundleFactory
com.taco.util.ResourceBundleFactory
public class ResourceBundleFactory
A concrete implementation of IResourceBundleFactory
. This
implementation supports resource bundles in the form of .class files for
subclasses of AccessibleResourceBundle
and .properties files
which are interpreted by instances of MultiLineProperties
.
Field Summary | |
---|---|
protected static java.util.regex.Pattern |
_BUNDLE_NAME_PATTERN
The regex pattern compiled from _BUNDLE_NAME_REGEX_STRING . |
protected static java.lang.String |
_BUNDLE_NAME_REGEX_STRING
A regex string for a bundle name. |
static ResourceBundleFactory |
DEFAULT_INSTANCE
A well-known instance of this class. |
Constructor Summary | |
---|---|
ResourceBundleFactory()
|
Method Summary | |
---|---|
protected java.util.List |
_computeBundleNameCandidates(java.lang.String baseName,
java.util.Locale locale)
Build a list of candidate bundle names for the given locale, in the following order: baseName + "_" + language baseName + "_" + language + "_" + country baseName + "_" + language + "_" + country + "_" + variant Candidate bundle names where the final component is an empty string are omitted. |
protected java.util.Locale |
_computeLocaleForBundleName(java.lang.String bundleName)
Parse the name of a bundle to get the locale it corresponds to. |
protected AccessibleResourceBundle |
_loadOrphanBundle(java.lang.String bundleName,
java.util.Locale defaultLocale,
java.lang.ClassLoader loader)
This method is called when it has been determined that a resource bundle is not in the cache, and we want to load the bundle from the system. |
protected AccessibleResourceBundle |
_loadOrphanBundleFromClass(java.lang.String bundleName,
java.util.Locale defaultLocale,
java.lang.ClassLoader loader)
Load a bundle from a .class file. |
protected AccessibleResourceBundle |
_loadOrphanBundleFromProperties(java.lang.String bundleName,
java.lang.ClassLoader loader)
Load an instance of MultiLinePropertyResourceBundle based
on a resource with the bundle name as the main part of its filename,
and ".properties" as its extension. |
protected AccessibleResourceBundle |
_loadOrphanBundleFromUIManager(java.lang.String bundleName)
Load a bundle based on the UIManager . |
protected AccessibleResourceBundle |
_lookupBundleInCache(java.lang.String bundleName,
java.util.Locale defaultLocale,
java.lang.ClassLoader loader)
Look in the bundle cache to see if a bundle for the arguments has been cached. |
void |
cleanBundleCache()
To save space, remove entries from the bundle cache whose keys have cleared references to class loaders or whose values are cleared references to resource bundles. |
java.lang.Object |
clone()
Make a clone of this factory. |
java.util.ResourceBundle |
getBundle(java.lang.String baseName,
java.util.Locale locale,
java.lang.ClassLoader loader,
java.util.Locale defaultLocale)
Get the bundle using the argument basename, locale, and class loader. |
void |
invalidateBundles(java.lang.String baseName,
java.util.Locale locale,
java.lang.ClassLoader loader,
java.util.Locale defaultLocale)
If resource bundles are cached, ensure that calls to getBundle() will reload the bundles corresponding to the
argument basename, locale, and class loader. |
static void |
main(java.lang.String[] args)
This simple test program prints all mappings in a resource bundle. |
static void |
usage()
Print usage information for main() . |
Methods inherited from class com.taco.util.AbstractResourceBundleFactory |
---|
getBundle, getBundle, getBundle, getBundle, invalidateBundles, invalidateBundles, invalidateBundles |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String _BUNDLE_NAME_REGEX_STRING
protected static final java.util.regex.Pattern _BUNDLE_NAME_PATTERN
_BUNDLE_NAME_REGEX_STRING
.
public static final ResourceBundleFactory DEFAULT_INSTANCE
Constructor Detail |
---|
public ResourceBundleFactory()
Method Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public final java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader, java.util.Locale defaultLocale) throws java.util.MissingResourceException
IResourceBundleFactory
null
, to indicate the system
class loader is to be used, or the caller may pass
getClass().getClassLoader()
to use the class loader of the
caller's class.
getBundle
in interface IResourceBundleFactory
java.util.MissingResourceException
public void invalidateBundles(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader, java.util.Locale defaultLocale)
IResourceBundleFactory
getBundle()
will reload the bundles corresponding to the
argument basename, locale, and class loader.
invalidateBundles
in interface IResourceBundleFactory
public void cleanBundleCache()
public static void usage()
main()
.
public static void main(java.lang.String[] args)
protected AccessibleResourceBundle _loadOrphanBundle(java.lang.String bundleName, java.util.Locale defaultLocale, java.lang.ClassLoader loader) throws java.util.MissingResourceException
This method is called when it has been determined that a resource
bundle is not in the cache, and we want to load the bundle from the
system. Return an instance of AccessibleResourceBundle
whose parent can be set by this factory.
MissingResourceException
.
This method may use several strategies for loading resource bundles and is intended to be overloaded in the case when a different implementation of resource bundle (particularly those that requiring run-time parsing) is added.
This base implementation tries to load resources bundles using the the following methods, in the order listed:
_loadOrphanBundleFromClass()
_loadOrphanBundleFromProperties()
_loadOrphanBundleFromUIManager()
java.util.MissingResourceException
protected AccessibleResourceBundle _loadOrphanBundleFromClass(java.lang.String bundleName, java.util.Locale defaultLocale, java.lang.ClassLoader loader) throws java.util.MissingResourceException
java.util.MissingResourceException
protected AccessibleResourceBundle _loadOrphanBundleFromProperties(java.lang.String bundleName, java.lang.ClassLoader loader) throws java.util.MissingResourceException
MultiLinePropertyResourceBundle
based
on a resource with the bundle name as the main part of its filename,
and ".properties" as its extension.
java.util.MissingResourceException
protected AccessibleResourceBundle _loadOrphanBundleFromUIManager(java.lang.String bundleName) throws java.util.MissingResourceException
UIManager
.
java.util.MissingResourceException
protected java.util.Locale _computeLocaleForBundleName(java.lang.String bundleName)
protected AccessibleResourceBundle _lookupBundleInCache(java.lang.String bundleName, java.util.Locale defaultLocale, java.lang.ClassLoader loader) throws java.util.MissingResourceException
MissingResourceException
. This method is suitable to be
called by subclasses because it synchronizes with the bundle cache,
which is a private member. It needs to be called whenever there is a
possibility that a recursive call to getBundle()
put a
bundle in the cache that is in the process of being built. For example,
a call to _loadOrphanBundleFromClass()
uses reflection to
instantiate a resource bundle. Since we have no idea what could be
happening in the constructor of the bundle class, it's possible that it
calls getBundle()
, and a bundle was put into the cache.
But we must be sure that every bundle returned by
_loadOrphanBundle()
must either be in the cache already or
is not duplicated in the cache.
java.util.MissingResourceException
protected java.util.List _computeBundleNameCandidates(java.lang.String baseName, java.util.Locale locale)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |