net.rim.device.api.i18n
Class ResourceBundle

java.lang.Object
  extended by net.rim.device.api.i18n.ResourceBundle
Direct Known Subclasses:
CompiledResourceBundle, HashResourceBundle, ResourceBundleFamily

public abstract class ResourceBundle
extends Object

Defines base functionality for bundles of locale-specific resources.

Compatible with java.util.ResourceBundle in Java's standard edition.


Constructor Summary
protected ResourceBundle(Locale locale)
          Constructs a new ResourceBundle instance.
 
Method Summary
static ResourceBundleFamily getBundle(String name)
          Retrieves resource bundle family by name.
static ResourceBundleFamily getBundle(long bundle, String name)
          Retrieves resource bundle family by ID.
static ResourceBundleFamily getBundle(long bundle, String name, CodeSigningKey key)
          Retrieves resource bundle family by ID.
 ResourceBundleFamily getFamily()
          Retrieves this bundle's family.
 Locale getLocale()
          Retrieves this bundle's locale.
 Object getObject(int key)
          Retrieves resource object by key (will chain through parent bundles).
 Object getObject(int key, boolean searchParent)
          Retrieves resource object by key.
 String getString(int key)
          Retrieves string form of resource object by key.
 String[] getStringArray(int key)
          Retrieves string array form of resource object by key.
protected abstract  Object handleGetObject(int key)
          Retrieves resource object handle by integer key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

ResourceBundle

protected ResourceBundle(Locale locale)
Constructs a new ResourceBundle instance.

Parameters:
locale - Locale for this resource bundle.


Method Detail

getBundle

public static final ResourceBundleFamily getBundle(String name)
Retrieves resource bundle family by name.

Parameters:
name - Name for the resource bundle family.
Returns:
Resource bundle family of provided name (if it doesn't already exist, this method creates it for you).

getBundle

public static final ResourceBundleFamily getBundle(long bundle,
                                                   String name)
                                            throws IllegalArgumentException
Retrieves resource bundle family by ID.

Invoke this method to retrieve the resource bundle family with the provided bundle ID. If this bundle family doesn't exist, then this method creates a new resource bundle family with your provided ID and name, and returns that.

Parameters:
bundle - Bundle ID.
name - Name for the resource bundle family.
Returns:
Resource bundle family of provided ID (if it doesn't already exist, this method creates it for you).
Throws:
IllegalArgumentException - If the name or its hash is not valid.

getBundle

public static final ResourceBundleFamily getBundle(long bundle,
                                                   String name,
                                                   CodeSigningKey key)
                                            throws IllegalArgumentException
Retrieves resource bundle family by ID.

Invoke this method to retrieve the resource bundle family with the provided bundle ID. If this bundle family doesn't exist, then this method creates a new resource bundle family with your provided ID and name, and returns that.

Parameters:
bundle - Bundle ID.
name - Name for the resource bundle family.
Returns:
Resource bundle family of provided ID (if it doesn't already exist, this method creates it for you).
Throws:
IllegalArgumentException - If the name or its hash is not valid.
Since:
BlackBerry API 4.0.0

getFamily

public final ResourceBundleFamily getFamily()
Retrieves this bundle's family.

Returns:
Resource bundle family containing this bundle.

getLocale

public final Locale getLocale()
Retrieves this bundle's locale.

Returns:
Should return this bundle's locale; if this bundle is in fact a bundle family, this method should return null.

getObject

public final Object getObject(int key)
                       throws MissingResourceException
Retrieves resource object by key (will chain through parent bundles).

This method simply invokes getObject(key,true). Thus, invoking this method on a derived class prompts the method to invoke this method on the enclosing bundle parent if the object is not found in this bundle. If the object is never found through the entire chain of calls on parent objects, then this method throws an exception.

Parameters:
key - Key for searched-for resource object.
Returns:
Resource object associated with key.
Throws:
MissingResourceException - If neither this bundle (nor any enclosing parent bundle) contains the resource associated with provided key.

getObject

public final Object getObject(int key,
                              boolean searchParent)
Retrieves resource object by key.

Parameters:
key - Key for searched-for resource object.
searchParent - If true, and if this bundle does not contain the resource object, this method will look in the enclosing bundle parent for the object, and will chain outwards through enclosing bundles until either the object is found, or the outmost bundle is reached. If False, this method stops looking after searching this bundle.
Returns:
Resource object associated with key; or null if this bundle does not contain the object, and searchParent was specified as true, then null gets returned only if this method cannot find the object in this bundle, nor any enclosing parent bundle.

getString

public final String getString(int key)
                       throws MissingResourceException
Retrieves string form of resource object by key.

This method merely casts the return value of ResourceBundle.getObject(int) as a String.

Parameters:
key - Key for searched-for resource object.
Returns:
String form of resource object.
Throws:
MissingResourceException - If neither this bundle (nor any enclosing parent bundle) contains the resource associated with provided key.

getStringArray

public final String[] getStringArray(int key)
                              throws MissingResourceException
Retrieves string array form of resource object by key.

This method merely casts the return value of ResourceBundle.getObject(int) as a String array.

Parameters:
key - Key for searched-for resource object.
Returns:
String array form of research object.
Throws:
MissingResourceException - If neither this bundle (nor any enclosing parent bundle) contains the resource associated with provided key.

handleGetObject

protected abstract Object handleGetObject(int key)
                                   throws MissingResourceException
Retrieves resource object handle by integer key.

Subclasses must implement this to return the appropriate resource object for a given key.

Parameters:
key - Integer key associated with resource object.
Returns:
Resource object associated with integer key.
Throws:
MissingResourceException - If the object associated with key not found.





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal