FileDocCategorySizeDatePackage
ProjectResourceBundle.javaAPI DocApache Axis 1.418047Sat Apr 22 18:57:28 BST 2006org.apache.axis.i18n

ProjectResourceBundle

public class ProjectResourceBundle extends ResourceBundle

Wrapper class for resource bundles. Property files are used to store resource strings, which are the only types of resources available. Property files can inherit properties from other files so that a base property file can be used and a small number of properties can be over-ridden by another property file. For example you may create an english version of a resource file named "resource.properties". You then decide that the British English version of all of the properties except one are the same, so there is no need to redefine all of the properties in "resource_en_GB", just the one that is different.

The basename is the name of the property file without the ".properties" extension.

Properties will be cached for performance.

Property values stored in the property files can also contain dynamic variables. Any dynamic variable defined in PropertiesUtil.getVariableValue() can be used (such as {date}), as well as arguments in the form {0}, {1}, etc. Argument values are specified in the various overloaded getString() methods.

author
Richard A. Sitze (rsitze@us.ibm.com)
author
Karl Moss (kmoss@macromedia.com)
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
protected static Log
log
private static final Hashtable
bundleCache
private static final Locale
defaultLocale
private final ResourceBundle
resourceBundle
private final String
resourceName
Constructors Summary
private ProjectResourceBundle(String name, ResourceBundle bundle)
Construct a new ProjectResourceBundle

        this.resourceBundle = bundle;
        this.resourceName = name;
    
Methods Summary
public static voidclearCache()
Clears the internal cache

        bundleCache.clear();
    
public static org.apache.axis.i18n.ProjectResourceBundlegetBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName)
Construct a new ProjectResourceBundle

param
projectName The name of the project to which the class belongs. It must be a proper prefix of the caller's package.
param
caller The calling class. This is used to get the package name to further construct the basename as well as to get the proper ClassLoader.
param
resourceName The name of the resource without the ".properties" extension
throws
MissingResourceException if projectName is not a prefix of the caller's package name, or if the resource could not be found/loaded.

        return getBundle(projectName, packageName, resourceName, null, null, null);
    
public static org.apache.axis.i18n.ProjectResourceBundlegetBundle(java.lang.String projectName, java.lang.Class caller, java.lang.String resourceName, java.util.Locale locale)
Construct a new ProjectResourceBundle

param
projectName The name of the project to which the class belongs. It must be a proper prefix of the caller's package.
param
caller The calling class. This is used to get the package name to further construct the basename as well as to get the proper ClassLoader.
param
resourceName The name of the resource without the ".properties" extension
throws
MissingResourceException if projectName is not a prefix of the caller's package name, or if the resource could not be found/loaded.

        return getBundle(projectName,
                         caller,
                         resourceName,
                         locale,
                         null);
    
public static org.apache.axis.i18n.ProjectResourceBundlegetBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName, java.util.Locale locale, java.lang.ClassLoader loader)
Construct a new ProjectResourceBundle

param
projectName The name of the project to which the class belongs. It must be a proper prefix of the caller's package.
param
caller The calling class. This is used to get the package name to further construct the basename as well as to get the proper ClassLoader.
param
resourceName The name of the resource without the ".properties" extension
param
locale The locale
throws
MissingResourceException if projectName is not a prefix of the caller's package name, or if the resource could not be found/loaded.

        return getBundle(projectName, packageName, resourceName, locale, loader, null);
    
public static org.apache.axis.i18n.ProjectResourceBundlegetBundle(java.lang.String projectName, java.lang.Class caller, java.lang.String resourceName, java.util.Locale locale, java.util.ResourceBundle extendsBundle)
Construct a new ProjectResourceBundle

param
projectName The name of the project to which the class belongs. It must be a proper prefix of the caller's package.
param
caller The calling class. This is used to get the package name to further construct the basename as well as to get the proper ClassLoader.
param
resourceName The name of the resource without the ".properties" extension
param
locale The locale
param
extendsBundle If non-null, then this ExtendMessages will default to extendsBundle.
throws
MissingResourceException if projectName is not a prefix of the caller's package name, or if the resource could not be found/loaded.

        return getBundle(projectName,
                         getPackage(caller.getClass().getName()),
                         resourceName,
                         locale,
                         caller.getClass().getClassLoader(),
                         extendsBundle);
    
public static org.apache.axis.i18n.ProjectResourceBundlegetBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName, java.util.Locale locale, java.lang.ClassLoader loader, java.util.ResourceBundle extendsBundle)
Construct a new ProjectResourceBundle

param
projectName The name of the project to which the class belongs. It must be a proper prefix of the caller's package.
param
caller The calling class. This is used to get the package name to further construct the basename as well as to get the proper ClassLoader.
param
resourceName The name of the resource without the ".properties" extension
param
locale The locale
param
extendsBundle If non-null, then this ExtendMessages will default to extendsBundle.
throws
MissingResourceException if projectName is not a prefix of the caller's package name, or if the resource could not be found/loaded.

        if (log.isDebugEnabled()) {
            log.debug("getBundle(" + projectName + ","
                                   + packageName + ","
                                   + resourceName + ","
                                   + String.valueOf(locale) + ",...)");
        }
        
        Context context = new Context();
        context.setLocale(locale);
        context.setLoader(loader);
        context.setProjectName(projectName);
        context.setResourceName(resourceName);
        context.setParentBundle(extendsBundle);

        packageName = context.validate(packageName);

        ProjectResourceBundle bundle = null;
        try {
            bundle = getBundle(context, packageName);
        } catch (RuntimeException e) {
            log.debug("Exception: ", e);
            throw e;
        }
        
        if (bundle == null) {
            throw new MissingResourceException("Cannot find resource '" +
                                               packageName + '." + resourceName + "'",
                                               resourceName, "");
        }
        
        return bundle;
    
private static synchronized org.apache.axis.i18n.ProjectResourceBundlegetBundle(org.apache.axis.i18n.ProjectResourceBundle$Context context, java.lang.String packageName)
get bundle... - check cache - try up hierarchy - if at top of hierarchy, use (link to) context.getParentBundle()

        String cacheKey = context.getCacheKey(packageName);
        
        ProjectResourceBundle prb = (ProjectResourceBundle)bundleCache.get(cacheKey);

        if (prb == null) {
            String name = packageName + '." + context.getResourceName();
            ResourceBundle rb = context.loadBundle(packageName);
            ResourceBundle parent = context.getParentBundle(packageName);
            
            if (rb != null) {
                prb = new ProjectResourceBundle(name, rb);
                prb.setParent(parent);
                if (log.isDebugEnabled()) {
                    log.debug("Created " + prb + ", linked to parent " + String.valueOf(parent));
                }
            } else {
                if (parent != null) {
                    if (parent instanceof ProjectResourceBundle) {
                        prb = (ProjectResourceBundle)parent;
                    } else {
                        prb = new ProjectResourceBundle(name, parent);
                    }
                    if (log.isDebugEnabled()) {
                        log.debug("Root package not found, cross link to " + parent);
                    }
                }
            }

            if (prb != null) {
                // Cache the resource
                bundleCache.put(cacheKey, prb);
            }
        }

        return prb;
    
public java.util.EnumerationgetKeys()

        Enumeration myKeys = resourceBundle.getKeys();
        if (parent == null) {
            return myKeys;
        } else {
            final HashSet set = new HashSet();
            while (myKeys.hasMoreElements()) {
                set.add(myKeys.nextElement());
            }
            
            Enumeration pKeys = parent.getKeys();
            while (pKeys.hasMoreElements()) {
                set.add(pKeys.nextElement());
            }
            
            return new Enumeration() {
                    private Iterator it = set.iterator();
                    public boolean hasMoreElements() { return it.hasNext(); }
                    public Object nextElement() { return it.next(); }
                };
        }
    
private static final java.lang.StringgetPackage(java.lang.String name)

        return name.substring(0, name.lastIndexOf('.")).intern();
    
public java.lang.StringgetResourceName()

        return resourceName;
    
protected java.lang.ObjecthandleGetObject(java.lang.String key)


    
       
         
    
        if (log.isDebugEnabled()) {
            log.debug(this.toString() + "::handleGetObject(" + key + ")");
        }
//            return resourceBundle.handleGetObject(key);
        Object obj;
        try {
            obj = resourceBundle.getObject(key);
        } catch (MissingResourceException e) {
            /* catch missing resource, ignore, & return null
             * if this method doesn't return null, then parents
             * are not searched
             */
            obj = null;
        }
        return obj;
    
public java.lang.StringtoString()

        return resourceName;