javax.microedition.global
Class ResourceManager

java.lang.Object
  extended by javax.microedition.global.ResourceManager

public class ResourceManager
extends Object

Since:
BlackBerry API 4.3.0

Field Summary
static String DEVICE
          Constant to indicate device resources.
 
Method Summary
 String getBaseName()
          Gets the base name of this resource manager.
 byte[] getData(int id)
          Gets a resource with the specified resource ID as a byte array containing arbitrary binary data.
 String getLocale()
          Gets the locale of this resource manager.
static ResourceManager getManager(String baseName)
          Gets a resource manager for the specified base name and the system's default locale.
static ResourceManager getManager(String baseName, String locale)
          Gets a resource manager for the specified base name and locale.
static ResourceManager getManager(String baseName, String[] locales)
          Gets a resource manager for the specified base name and the first matching locale in the supplied array.
 Object getResource(int id)
          Gets a resource with the specified ID.
 String getString(int id)
          Gets a string with the specified resource ID.
static String[] getSupportedLocales(String baseName)
          Gets the locales supported by this resource manager for the given base name.
 boolean isCaching()
          Returns the caching status of this resource manager.
 boolean isValidResourceID(int id)
          Determines if the given resource ID is valid in this implementation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

DEVICE

public static final String DEVICE
Constant to indicate device resources.

See Also:
Constant Field Values
Since:
BlackBerry API 4.3.0


Method Detail

getManager

public static final ResourceManager getManager(String baseName)
                                        throws ResourceException,
                                               UnsupportedLocaleException
Gets a resource manager for the specified base name and the system's default locale. If the base name is DEVICE, the resource manager can only retrieve device-specific resources. Other base names retrieve application-specific resources. The base name must not be null. If the system's default locale is null, a ResourceException is thrown. If it is non-null but no resources are found, this method performs the hierarchical matching of locales. If no resources are found for the combination of base name and locale, a ResourceException is thrown with the appropriate error code and detail message.

Parameters:
baseName - the base name, DEVICE to retrieve device-specific resources
Returns:
the manager instance for the specified base name
Throws:
NullPointerException - if the base name is null
ResourceException - if the system default locale is null, or the resource file is invalid
UnsupportedLocaleException - if the system's default locale (when non-null) is not listed in the meta-information file of this base name (for application resources only), or when device resources are not supported for the system's default locale
Since:
BlackBerry API 4.3.0

getManager

public static final ResourceManager getManager(String baseName,
                                               String locale)
                                        throws ResourceException,
                                               UnsupportedLocaleException
Gets a resource manager for the specified base name and locale. If the base name is DEVICE (the empty string), the resource manager can only retrieve device resources. Other base names retrieve application resources. The base name must not be null. If resources for the specified locale are not found, this method attempts to find resources by hierarchical matching. The matching proceeds from language-country-variant to language-country, then on to language, and finally to the empty string. An empty string can also be used as the locale. It is a shortcut to using common resources without going through the matching process. If resources for the combination of the base name and the matching locale are found, this method returns a manager for those resources. If no resources are found for the combination, a ResourceException is thrown.

Parameters:
baseName - the base name, non-empty for application resources, DEVICE (the empty string) for device resources
locale - the locale to use either as is or as a starting point for hierarchical matching
Returns:
the manager instance for the base name and the specified or matched locale
Throws:
NullPointerException - if the base name is null or if the locale is null
IllegalArgumentException - if the locale identifier is not valid according to the MIDP 2.0 specification
ResourceException - if no resources for the combination of base name and locale are found, or the resource file is invalid
UnsupportedLocaleException - if locale is not listed in the meta-information file of this base name (application resources only)
Since:
BlackBerry API 4.3.0

getManager

public static final ResourceManager getManager(String baseName,
                                               String[] locales)
                                        throws ResourceException,
                                               UnsupportedLocaleException
Gets a resource manager for the specified base name and the first matching locale in the supplied array. If the base name is "DEVICE" (the empty string), the resource manager can only retrieve device resources. Other base names retrieve application resources. The base name MUST NOT be null. This method attempts to get a resource manager for a combination of the base name and one of the locales in the array. The locales are tried successively, stopping at the first match. This method MUST NOT perform hierarchical matching. If none of the locales in the array result in a match, a ResourceException MUST be thrown with the appropriate error code. For example, if the array of locales contains { "de-DE", "fr", "en" }, and resources are not found for "de-DE" or "fr", but are found for "en", then this method gets a manager for "en". However, if resources are not found for "de-DE", but are found for "fr", then this method gets a manager for "fr" and disregards the "en" locale. In this case if resources are not found for "de-DE", the locale "de" MUST NOT be tried; instead the matching proceeds to the next locale in the array. The locales array MUST NOT be null or empty. Each of the locale identifiers in the array MUST be a valid locale identifier, otherwise an IllegalArgumentException is thrown. As an extension, the empty string can be used to use resources common to all locales.

Parameters:
baseName - the base name, non-empty for application resources, or DEVICE (the empty string) for device resources
locales - the array of locale identifiers to try
Returns:
the manager instance for the base name and the matched locale
Throws:
NullPointerException - if the locales array is null, or if any of the locales in the array is null, or the base name is null
IllegalArgumentException - if any of the locale identifiers in the array is invalid according to the MIDP 2.0 specification, or if the array is empty
ResourceException - if no resources for the base name and any of the locales in the array are found
UnsupportedLocaleException - if none of the locales in the array are listed in the meta-information file of this base name (for application resources), or when device resources are not supported for any of the locales
Since:
BlackBerry API 4.3.0

getBaseName

public String getBaseName()
Gets the base name of this resource manager.

Returns:
the base name (DEVICE if this resource manager is retrieving device-specific resources)
Since:
BlackBerry API 4.3.0

getLocale

public String getLocale()
Gets the locale of this resource manager.

Returns:
the locale identifier
Since:
BlackBerry API 4.3.0

isValidResourceID

public boolean isValidResourceID(int id)
Determines if the given resource ID is valid in this implementation. In this context "valid" means that a resource exists with the given resource ID, and calling getResource with that ID returns a non-null object instance. The method does not discriminate between application and device resources, since one resource manager can only handle one type of resource.

Parameters:
id - the resource ID
Returns:
true if the resource ID is valid, false if not
Throws:
IllegalArgumentException - if the resource ID is not in the defined range
Since:
BlackBerry API 4.3.0

getData

public byte[] getData(int id)
               throws ResourceException
Gets a resource with the specified resource ID as a byte array containing arbitrary binary data. If the resource with the specified ID is not binary data, or the resource does not exist, a ResourceException is thrown with the appropriate error code. This method performs a hierarchical lookup of the resource.

Parameters:
id - the resource ID
Returns:
byte array containing the data
Throws:
ResourceException - if the resource does not exist, or if the resource is not the correct type
IllegalArgumentException - if the resource ID is invalid
Since:
BlackBerry API 4.3.0

getResource

public Object getResource(int id)
                   throws ResourceException
Gets a resource with the specified ID. The resource is either an application-specific resource or a device resource, depending on the base name of the resource manager. This method performs a hierarchical lookup of the resource.

Parameters:
id - the resource ID
Returns:
the resource object
Throws:
ResourceException - if the resource is not found, or if an application resource has an unknown type
IllegalArgumentException - if the resource ID is invalid
Since:
BlackBerry API 4.3.0

getString

public String getString(int id)
                 throws ResourceException
Gets a string with the specified resource ID. This is a convenience method to avoid typecasting in applications. If the resource with the specified ID is not a string, or the resource does not exist, a ResourceException is thrown with the appropriate error code. This method performs a hierarchical lookup of the resource.

Parameters:
id - the resource ID
Returns:
the string
Throws:
ResourceException - if the resource is not found, or if an application resource has an unknown type
IllegalArgumentException - if the resource ID is invalid
Since:
BlackBerry API 4.3.0

getSupportedLocales

public static String[] getSupportedLocales(String baseName)
Gets the locales supported by this resource manager for the given base name. Returns an array of valid microedition.locale values. If there are no supported locales, returns an empty array (not null). The base name is used to distinguish between application and device resources. If the base name is non-empty, this method returns the list of locales for which application-specific resources are defined. If the base name is "DEVICE" (the empty string), the set of supported device locales is returned instead. The returned array MAY be empty if no locales are supported for the specified base name. It MUST NOT be null. Values in the array MUST be unique. The value null MUST NOT appear in the returned array. However, if there are resources for this base name which are common to all locales, the array MUST contain the empty string. It SHOULD be first element in the array. The supported locales for an application resource manager require a base name specific meta-information file described in the "Enumerating supported locales" section of the specification overview. If the meta-information file is not found, this method MUST throw a ResourceException with the error code METAFILE_NOT_FOUND. If the content of the meta-information file is not syntactically valid, this method MUST throw a ResourceException with the error code DATA_ERROR. The list of locales supported by a resource manager for a base name MAY be different than in a formatter, i.e. the implementation MAY support formatting rules for a certain set of locales, but an application can supply resources for an entirely different (or overlapping) set of locales.

Parameters:
baseName - the base name, non-empty for application resources, DEVICE (the empty string) for device resources
Returns:
the list of supported locales for the specified base name, possibly empty
Throws:
NullPointerException - if the base name is null
ResourceException - if the meta-information file is not found or it is not of the specified format
Since:
BlackBerry API 4.3.0

isCaching

public boolean isCaching()
Returns the caching status of this resource manager.

Returns:
true if caching, false if not
Since:
BlackBerry API 4.3.0





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