FileDocCategorySizeDatePackage
SOMLocalStringsManager.javaAPI DocGlassfish v2 API8239Fri May 04 22:34:10 BST 2007com.sun.enterprise.admin.util

SOMLocalStringsManager

public class SOMLocalStringsManager extends LocalStringsManager
Implementation of a SOM local string manager as SOM-specific wrapper around LocalStringsManager; Provides access to i18n messages for classes that need them. This particular implementation presents the following resources organization:
  • 1. Resource files share locations with sources (same directories);
  • 2. Base directory is "com.sun.enterprise.admin";
  • 3. Search ONLY in first resource bundle, which found on the way up to basePackage( No additional hiearchical search of value if it is not found in that file)

Fields Summary
private static final String
DEFAULT_PROPERTY_FILE_NAME
private static final String
DEFAULT_PACKAGE_NAME
private static Hashtable
managers
cache for all the local string managers (per pkg)
Constructors Summary
public SOMLocalStringsManager(String packageName)


      
    
        super(packageName, DEFAULT_PROPERTY_FILE_NAME);
        setFixedResourceBundle(packageName);
    
Methods Summary
public static synchronized com.sun.enterprise.admin.util.SOMLocalStringsManagergetManager(java.lang.String packageName)
Returns a local string manager for the given package name.

param
packageName name of the package of the src
return
a local string manager for the given package name


        SOMLocalStringsManager mgr = (SOMLocalStringsManager) managers.get(packageName);

        if (mgr == null) {
            mgr = new SOMLocalStringsManager(packageName);
            try {
                managers.put(packageName, mgr);
            } catch (Exception e) {
                // do nothing
            }
        }
        return mgr;
    
public static synchronized com.sun.enterprise.admin.util.SOMLocalStringsManagergetManager(java.lang.Class callerClass)
Returns a local string manager for the given package name.

param
callerClass the object making the call
return
a local string manager for the given package name

    
        try {
            int dotIdx = callerClass.getName().lastIndexOf(".");
            if (dotIdx != -1) {
                String pkgName = callerClass.getName().substring(0, dotIdx);
                return getManager(pkgName);
            } else {
                // class does not belong to any pkg
                String pkgName = callerClass.getName();
                return getManager(pkgName);
            }
        } catch (Exception e) {
            // Return default manager, and not null, so as to avoid 
            // null pointer exception in the calling method.
            return getManager(DEFAULT_PACKAGE_NAME);
        }
    
public java.lang.StringgetString(java.lang.String key, java.lang.String defaultFormat, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
Convenience method - getString() overriding for fixed number of formatting arguments.

param
key The key to the local format string
param
defaultFormat The default format if not found in the resources
param
arg1 The first argument to provide to the formatter
param
arg2 The second argument to provide to the formatter
param
arg3 The third argument to provide to the formatter
return
A formatted localized string

        return  getString(key, defaultFormat, (new Object[]{arg1, arg2, arg3}));
    
public java.lang.StringgetString(java.lang.String key)
Get a localized string.

param
key The name of the resource to fetch
return
The localized string

        return  super.getString(key, key); // key itself will act as default value, 
                                           //instead of some string like "No local strings found"
    
public java.lang.StringgetString(java.lang.String key, java.lang.String defaultValue)
Get a localized string.

param
key The name of the resource to fetch
param
args The default return value if not found
return
The localized string

        return  super.getString(key, defaultValue);
    
public java.lang.StringgetString(java.lang.String key, java.lang.Object[] args)
Get a local string and format the arguments accordingly.

param
key The key to the local format string
param
arguments The set of arguments to provide to the formatter
return
A formatted localized string

        return  super.getString(key, key, args);
    
public java.lang.StringgetString(java.lang.String key, java.lang.String defaultFormat, java.lang.Object[] args)
Get a local string and format the arguments accordingly.

param
key The key to the local format string
param
defaultFormat The default format if not found in the resources
param
arguments The set of arguments to provide to the formatter
return
A formatted localized string

        return  super.getString(key, defaultFormat, args);
    
public java.lang.StringgetString(java.lang.String key, java.lang.String defaultFormat, java.lang.Object arg1)
Convenience method - getString() overriding for fixed number of formatting arguments.

param
key The key to the local format string
param
defaultFormat The default format if not found in the resources
param
arg1 The first argument to provide to the formatter
return
A formatted localized string

        return  getString(key, defaultFormat, (new Object[]{arg1}));
    
public java.lang.StringgetString(java.lang.String key, java.lang.String defaultFormat, java.lang.Object arg1, java.lang.Object arg2)
Convenience method - getString() overriding for fixed number of formatting arguments.

param
key The key to the local format string
param
defaultFormat The default format if not found in the resources
param
arg1 The first argument to provide to the formatter
param
arg1 The second argument to provide to the formatter
return
A formatted localized string

        return  getString(key, defaultFormat, (new Object[]{arg1, arg2}));