Top Description Fields Constructors Methods
org.hsqldb.resources

public final Class ResourceBundleHandler

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.Locale, .MissingResourceException, .ResourceBundle, org.hsqldb.lib.HashMap, .HsqlArrayList

A ResourceBundle helper class.

Allows clients to get/set locale and get at localized resource bundle content in a resource path independent manner, without having to worry about handling exception states or deal directly with ResourceBundle object instances. Instead, clients receive numeric handles to the underlying objects. Rather than causing exception states, missing or inaccessible resources and underlying MissingResource and NullPointer exceptions result in null return values when attempting to retrieve a resource.

Author
Campbell Burnet (campbell-burnet@users dot sourceforge.net)
Since
1.7.2
Version
1.7.2

Field Summary

Modifier and TypeField and Description
private static HashMap<String, Integer>
bundleHandleMap

Map: Integer object handle maps to: ResourceBundle object.

private static HsqlArrayList<ResourceBundle>
bundleList

List whose elements are ResourceBundle objects

private static Locale
locale

The Locale used internally to fetch resource bundles.

private static final Object
mutex

Used to synchronize access

private static final Method
newGetBundleMethod

JDK 1.1 compliance

private static final String
prefix

The resource path prefix of the ResourceBundle objects handled by this class.

Constructor Summary

AccessConstructor and Description
private
ResourceBundleHandler()

Pure utility class: external construction disabled.

Method Summary

Modifier and TypeMethod and Description
public static ResourceBundle
getBundle(String
the base name of the resource bundle, a fully qualified class name
name
,
Locale
the locale for which a resource bundle is desired
locale
,
ClassLoader
the class loader from which to load the resource bundle
cl
)

Retrieves a resource bundle using the specified base name, locale, and class loader.

public static int

Returns:

int handle to the ResourceBundle object corresponding to the specified name and current Locale, or -1 if no such bundle can be found
getBundleHandle
(String
of the desired bundle
name
,
ClassLoader
The ClassLoader to use in the search
cl
)

Retrieves an int handle to the ResourceBundle object corresponding to the specified name and current Locale, using the specified ClassLoader.

public static Locale

Returns:

Value of property locale.
getLocale
()

Getter for property locale.

private static Method
getNewGetBundleMethod()

One-shot initialization of JDK 1.2+ ResourceBundle.getBundle() method having ClassLoader in the signature.

public static String

Returns:

The String value corresponding to the specified handle and key.
getString
(int
an int handle to a ResourceBundle object
handle
,
String
A String key to a String value
key
)

Retrieves, from the ResourceBundle object corresponding to the specified handle, the String value corresponding to the specified key.

public static void
setLocale(Locale
the new locale
l
)

Setter for property locale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bundleHandleMapback to summary
private static HashMap<String, Integer> bundleHandleMap

Map: Integer object handle maps to: ResourceBundle object.

bundleListback to summary
private static HsqlArrayList<ResourceBundle> bundleList

List whose elements are ResourceBundle objects

localeback to summary
private static Locale locale

The Locale used internally to fetch resource bundles.

mutexback to summary
private static final Object mutex

Used to synchronize access

newGetBundleMethodback to summary
private static final Method newGetBundleMethod

JDK 1.1 compliance

prefixback to summary
private static final String prefix

The resource path prefix of the ResourceBundle objects handled by this class.

Constructor Detail

ResourceBundleHandlerback to summary
private ResourceBundleHandler()

Pure utility class: external construction disabled.

Method Detail

getBundleback to summary
public static ResourceBundle getBundle(String name, Locale locale, ClassLoader cl) throws NullPointerException, MissingResourceException

Retrieves a resource bundle using the specified base name, locale, and class loader. This is a JDK 1.1 compliant substitution for the ResourceBundle method with the same name and signature. If there is a problem using the JDK 1.2 functionality (the class loader is specified non-null and the underlying method is not available or there is a security exception, etc.), then the behaviour reverts to that of JDK 1.1.

Parameters
name:String

the base name of the resource bundle, a fully qualified class name

locale:Locale

the locale for which a resource bundle is desired

cl:ClassLoader

the class loader from which to load the resource bundle

getBundleHandleback to summary
public static int getBundleHandle(String name, ClassLoader cl)

Retrieves an int handle to the ResourceBundle object corresponding to the specified name and current Locale, using the specified ClassLoader.

Parameters
name:String

of the desired bundle

cl:ClassLoader

The ClassLoader to use in the search

Returns:int

int handle to the ResourceBundle object corresponding to the specified name and current Locale, or -1 if no such bundle can be found

getLocaleback to summary
public static Locale getLocale()

Getter for property locale.

Returns:Locale

Value of property locale.

getNewGetBundleMethodback to summary
private static Method getNewGetBundleMethod()

One-shot initialization of JDK 1.2+ ResourceBundle.getBundle() method having ClassLoader in the signature.

getStringback to summary
public static String getString(int handle, String key)

Retrieves, from the ResourceBundle object corresponding to the specified handle, the String value corresponding to the specified key. null is retrieved if either there is no ResourceBundle object for the handle or there is no String value for the specified key.

Parameters
handle:int

an int handle to a ResourceBundle object

key:String

A String key to a String value

Returns:String

The String value corresponding to the specified handle and key.

setLocaleback to summary
public static void setLocale(Locale l) throws IllegalArgumentException

Setter for property locale.

Parameters
l:Locale

the new locale

Exceptions
IllegalArgumentException:
when the new locale is null