java.lang.Object | +--java.util.ResourceBundle
java.util.ResourceBundle | parent The parent bundle. |
ResourceBundle() The constructor. |
static java.util.ResourceBundle | getBundle(java.lang.String baseName) Get the appropriate ResourceBundle for the default locale. |
static java.util.ResourceBundle | getBundle(java.lang.String baseName, java.util.Locale locale) Get the appropriate ResourceBundle for the given locale. |
static synchronized java.util.ResourceBundle | getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader classLoader) Get the appropriate ResourceBundle for the given locale. |
java.util.Enumeration | getKeys() This method should return all keys for which a resource exists; you should include the enumeration of any parent's keys, after filtering out duplicates. |
java.util.Locale | getLocale() Return the actual locale of this bundle. |
java.lang.Object | getObject(java.lang.String key) Get an object from this resource bundle. |
java.lang.String | getString(java.lang.String key) Get a String from this resource bundle. |
java.lang.String[] | getStringArray(java.lang.String key) Get an array of Strings from this resource bundle. |
java.lang.Object | handleGetObject(java.lang.String key) Override this method to provide the resource for a keys. |
void | setParent(java.util.ResourceBundle parent) Set the parent of this bundle. |
protected ResourceBundle parent
public ResourceBundle()
public static final ResourceBundle getBundle(java.lang.String baseName)
getBundle(baseName, Locale.getDefault(),
getClass().getClassLoader()
, except that any security check of
getClassLoader won't fail.
baseName
- the name of the ResourceBundleMissingResourceException
- if the resource bundle can't be foundNullPointerException
- if baseName is nullpublic static final ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale)
getBundle(baseName, locale,
getClass().getClassLoader()
, except that any security check of
getClassLoader won't fail.
baseName
- the name of the ResourceBundlelocale
- A localeMissingResourceException
- if the resource bundle can't be foundNullPointerException
- if baseName or locale is nullpublic static final synchronized ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader classLoader)
A sequence of candidate bundle names are generated, and tested in this order, where the suffix 1 means the string from the specified locale, and the suffix 2 means the string from the default locale:
In the sequence, entries with an empty string are ignored. Next,
getBundle
tries to instantiate the resource bundle:
Next, the parent chain is implemented. The remaining candidate names
in the above sequence are tested in a similar manner, and if any results
in a resource bundle, it is assigned as the parent of the first bundle
using the setParent
method (unless the first bundle already
has a parent).
For example, suppose the following class and property files are provided: MyResources.class, MyResources_fr_CH.properties, MyResources_fr_CH.class, MyResources_fr.properties, MyResources_en.properties, and MyResources_es_ES.class. The contents of all files are valid (that is, public non-abstract subclasses of ResourceBundle with public nullary constructors for the ".class" files, syntactically correct ".properties" files). The default locale is Locale("en", "UK").
Calling getBundle with the shown locale argument values instantiates resource bundles from the following sources:
baseName
- the name of the ResourceBundlelocale
- A localeclassLoader
- a ClassLoaderMissingResourceException
- if the resource bundle can't be foundNullPointerException
- if any argument is nullpublic Enumeration getKeys()
public Locale getLocale()
public final Object getObject(java.lang.String key)
handleGetObject
for this resource and all of its parents,
until it finds a non-null resource.
key
- the name of the resourceMissingResourceException
- if the resource can't be foundNullPointerException
- if key is nullpublic final String getString(java.lang.String key)
key
- the name of the resourceMissingResourceException
- if the resource can't be foundNullPointerException
- if key is nullClassCastException
- if resource is not a stringpublic final String[] getStringArray(java.lang.String key)
key
- the name of the resourceMissingResourceException
- if the resource can't be foundNullPointerException
- if key is nullClassCastException
- if resource is not a stringprotected Object handleGetObject(java.lang.String key)
getObject
. If you don't have a resource
for the given key, you should return null instead throwing a
MissingResourceException. You don't have to ask the parent, getObject()
already does this; nor should you throw a MissingResourceException.
key
- the key of the resourceNullPointerException
- if key is nullprotected void setParent(java.util.ResourceBundle parent)
parent
- the parent of this bundle
getBundle
. Now you can get your object by callinggetObject
orgetString
on that bundle.When a bundle is demanded for a specific locale, the ResourceBundle is searched in following order (def. language stands for the two letter ISO language code of the default locale (see
Locale.getDefault()
).A bundle is backed up by less specific bundles (omitting variant, country or language). But it is not backed up by the default language locale.
If you provide a bundle for a given locale, say
Bundle_en_UK_POSIX
, you must also provide a bundle for all sub locales, ie.Bundle_en_UK
,Bundle_en
, andBundle
.When a bundle is searched, we look first for a class with the given name, then for a file with
.properties
extension in the classpath. The name must be a fully qualified classname (with dots as path separators).(Note: This implementation always backs up the class with a properties file if that is existing, but you shouldn't rely on this, if you want to be compatible to the standard JDK.)