Abstract Class ListResourceBundle in Java

Share and Enjoy !

Abstract Class ListResourceBundle in Java

The ListResourceBundle class is an abstract subclass of ResourceBundle that represents a list of resources for a locale. The resources are listed as a set of key/value pairs. Internally, a Hashtable is used for a quick lookup of values. To subclass ListResourceBundle, all you need to do is override getContents() to return a two-dimensional array of Objects that contains the key/value pairs.

When ResourceBundle.getBundle() is called, it attempts to find a resource bundle that most
closely matches a particular locale. This can be either a ListResourceBundle subclass or a property file, represented by a PropertyResourceBundle. Once the resource bundle has been retrieved, its PropertyResourceBundle inherits a lot of functionality from ResourceBundle; see the class description of ResourceBundle for more information.

This abstract class provides a simple way to define a ResourceBundle. We may find it easier to subclass ListResourceBundle than to subclass ResourceBundle directly.

ListResourceBundle provides implementations for the abstract handleGetObject() and getKeys() methods defined by ResourceBundle, and it adds its own abstract getContents()method that our subclasses must override.

getContents() returns an Object[][]–an array of arrays of objects. This array can have any number of elements. Each element of this array must itself be an array with two elements: the first element of each subarray should be a String that specifies the name of a resource, and the corresponding second element should be the value of that resource–this value can be an Object of any desired type.

READ  All About Class BufferedInputStream in Java

The structure of the abstract class ListResourceBundle is given by

public abstract class java.util.ListResourceBundle extends java.util.ResourceBundle{
// Default Constructor: 
public ListResourceBundle();
// Public Instance Methods
public Enumeration getKeys(); // Defines ResourceBundle
public final Object handleGetObject(String key); // Defines ResourceBundle
// Protected Instance Methods
protected abstract Object[][] getContents();

The details of the class structure are given as follows:

public Enumeration getKeys();

public Enumeration getKeys() method returns an Enumeration that iterates through the keys in this ListResourceBundle.

This method returns the keys in the resource bundle as an Enumeration.

public final Object handleGetObject(String key);

public final Object handleGetObject(String key) method returns the resource that corresponds to the given key. This method should not be called directly by your code. Your code should call ResourceBundle.getObject(), which may call the handleGetObject() objects of multiple subclasses of ResourceBundle looking for a particular resource. Calling handleGetObject() directly only finds resources in the object associated with the method.

This method returns the resource that corresponds to this key.

key – The key of the resource to retrieve.

protected abstract Object[][] getContents();

protected abstract Object[][] getContents() method returns a two-dimensional Object array that contains all the key/value pairs for this ListResourceBundle.

This method returns the key/value pairs that represent the resources as a two-dimensional array.

Apart from these ListResourceBundle class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

ListResourceBundle class also has inherited methods from ResourceBundle. They are as follows:

  • getObject(String)
  • getStringArray(String)
  • setParent(ResourceBundle)
  • getString(String)

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *