/**
* The ResourceBundle for this StringManager.
*/
-
private ResourceBundle bundle;
private Locale locale;
*
* @param packageName Name of package to create StringManager for.
*/
-
private StringManager(String packageName) {
- this( packageName, Locale.getDefault() );
+ this( packageName, Locale.getDefault() );
}
private StringManager(String packageName, Locale loc) {
locale = bundle.getLocale();
}
- private StringManager(ResourceBundle bundle )
- {
- this.bundle=bundle;
+ private StringManager(ResourceBundle bundle ) {
+ this.bundle=bundle;
locale = bundle.getLocale();
}
bundle or null if not found.
@throws IllegalArgumentException if <i>key</i> is null.
*/
-
public String getString(String key) {
if(key == null){
String msg = "key may not have a null value";
String str = null;
- try{
- str = bundle.getString(key);
- }catch(MissingResourceException mre){
+ try {
+ str = bundle.getString(key);
+ } catch(MissingResourceException mre) {
//bad: shouldn't mask an exception the following way:
// str = "[cannot find message associated with key '" + key + "' due to " + mre + "]";
- // because it hides the fact that the String was missing
- // from the calling code.
- //good: could just throw the exception (or wrap it in another)
- // but that would probably cause much havoc on existing
- // code.
- //better: consistent with container pattern to
- // simply return null. Calling code can then do
- // a null check.
- str = null;
+ // because it hides the fact that the String was missing
+ // from the calling code.
+ //good: could just throw the exception (or wrap it in another)
+ // but that would probably cause much havoc on existing
+ // code.
+ //better: consistent with container pattern to
+ // simply return null. Calling code can then do
+ // a null check.
+ str = null;
}
return str;
* @param key
* @param args
*/
-
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
* @param packageName The package name
*/
public synchronized static StringManager getManager(String packageName) {
- StringManager mgr = managers.get(packageName);
- if (mgr == null) {
- mgr = new StringManager(packageName);
- managers.put(packageName, mgr);
- }
- return mgr;
+ StringManager mgr = managers.get(packageName);
+ if (mgr == null) {
+ mgr = new StringManager(packageName);
+ managers.put(packageName, mgr);
+ }
+ return mgr;
}
/**
* @param bundle The resource bundle
*/
public synchronized static StringManager getManager(ResourceBundle bundle) {
- return new StringManager( bundle );
+ return new StringManager( bundle );
}
/**
* @param packageName The package name
* @param loc The locale
*/
-
- public synchronized static StringManager getManager(String packageName,Locale loc) {
- StringManager mgr = managers.get(packageName+"_"+loc.toString());
- if (mgr == null) {
- mgr = new StringManager(packageName,loc);
- managers.put(packageName+"_"+loc.toString(), mgr);
- }
- return mgr;
+ public synchronized static StringManager getManager(String packageName,Locale loc) {
+ StringManager mgr = managers.get(packageName+"_"+loc.toString());
+ if (mgr == null) {
+ mgr = new StringManager(packageName,loc);
+ managers.put(packageName+"_"+loc.toString(), mgr);
+ }
+ return mgr;
}
}