ResourceBundleNameResourceBundleSynopsis
DescriptionThe ResourceBundle class is an abstract class that represents a set of localized data. An application retrieves a ResourceBundle based on its locale. A ResourceBundle can contain GUI labels and other locale-specific information that the application needs to run in a specific locale. Conceptually, a resource bundle is a set of related classes that all inherit from a particular subclass of ResourceBundle. The base resource bundle defines all of the resources for a particular application, while each of the subclasses specifies the appropriate values for a particular locale. Each subclass has the same base name, plus a suffix that identifies its locale. A static method, getBundle(), is used to locate a resource bundle for a particular locale. This method searches for resources in two forms. First, it looks for a subclass of ResourceBundle or ListResourceBundle with the appropriate name. If one is found, an instance of the class is created and returned. If no appropriate subclass can be found, getBundle() then searches for a property file with the appropriate name. If one is found, a PropertyResourceBundle is created from the file and returned. The getBundle() method constructs a name from a specified base resource name and the locale. It then searches for either a class or a property file with this name. If the method fails to find an exact match, it tries to find a close match. The method constructs names by dropping to the next name on the list if the current name cannot be found:
For example, if you call getBundle('Labels', new Locale('it', 'IT', 'Be')), the method looks for a class or property file with one of the following names (assuming the default locale is the United States):
A particular ResourceBundle object contains a set of key/value pairs that defines the resources for a particular application. The keys are always String objects that name the resources, while the values can be any sort of object needed for the application. The ResourceBundle class defines convenience methods for retrieving String and String[] objects. If you need to use other kinds of objects, you can use the getObject() method to retrieve them and simply cast the results to the appropriate types. Class Summary
public abstract class java.util.ResourceBundle extends java.lang.Object { // Variables protected ResourceBundle parent; // Class Methods public final static ResourceBundle getBundle(String baseName); public final static ResourceBundle getBundle(String baseName, Locale locale); // Instance Methods public abstract Enumeration getKeys(); public final Object getObject(String key)j; public final String getString(String key); public final String[] getStringArray(String key); // Protected Instance Methods protected abstract Object handleGetObject(String key); protected void setParent(ResourceBundle parent); } Variablesparentprotected ResourceBundle parent
Class MethodsgetBundle
public final static ResourceBundle getBundle(String baseName) throws MissingResourceException
public final static ResourceBundle getBundle(String baseName, Locale locale)
Instance MethodsgetKeyspublic abstract Enumeration getKeys()
getObject
public final Object getObject(String key) throws MissingResourceException
getString
public final String getString(String key) throws MissingResourceException
getStringArray
public final String[] getStringArray(String key) throws MissingResourceException
Protected Instance MethodshandleGetObject
protected abstract Object handleGetObject(String key) throws MissingResourceException
setParentprotected void setParent(ResourceBundle parent)
Inherited Methods
See AlsoEnumeration, ListResourceBundle, Locale, PropertyResourceBundle, String | ||||||||||||||||||||||||||||
|