| This class provides a default implementation of the Localizable interface.
You can use it as a base class or as a member field and delegates various
work to it.
For example, to implement Localizable, the following code can be used:
package mypackage;
...
public class MyClass implements Localizable {
// This code fragment requires a file named
// 'mypackage/resources/Messages.properties', or a
// 'mypackage.resources.Messages' class which extends
// java.util.ResourceBundle, accessible using the current
// classpath.
LocalizableSupport localizableSupport =
new LocalizableSupport("mypackage.resources.Messages");
public void setLocale(Locale l) {
localizableSupport.setLocale(l);
}
public Local getLocale() {
return localizableSupport.getLocale();
}
public String formatMessage(String key, Object[] args) {
return localizableSupport.formatMessage(key, args);
}
}
The algorithm for the Locale lookup in a LocalizableSupport object is:
-
if a Locale has been set by a call to setLocale(), use this Locale,
else,
-
if a Locale has been set by a call to the setDefaultLocale() method
of a LocalizableSupport object in the current LocaleGroup, use this
Locale, else,
-
use the object returned by Locale.getDefault() (and set by
Locale.setDefault()).
This offers the possibility to have a different Locale for each object,
a Locale for a group of object and/or a Locale for the JVM instance.
Note: if no group is specified a LocalizableSupport object belongs to a
default group common to each instance of LocalizableSupport.
author: Stephane Hillion version: $Id$ |