atg.core.i18n
Class LayeredResourceBundle

java.lang.Object
  extended by atg.core.i18n.LayeredResourceBundle

public class LayeredResourceBundle
extends java.lang.Object

A class capable of creating layered resource bundles. Layered resource bundles function similiarly to Nucleus component properties files, where it is possible to override a property definitions by creating a properties file in the same location as the original, but in a different configuration layer.

Layered resource bundles work by layering properties files contained in different class paths. Properties definitions in files that appear earlier in the classpath will override property definitions which appear later in the classpath.

This class attempts to be a drop-in replacement for calls to ResourceBundle.getBundle(). It implements allowing classes earlier in the classpath to override or extend individual property values, but allows values from later in the classpath to "bleed through." Thus it mimics the same behavior that Nucleus properties have.

The known limitations of LayeredResourceBundle are:

ResourceBundle.getBundle() uses a non-public native call to get the ClassLoader of the call of the ResourceBundle.getBundle() method. Since LayeredResourceBundle does not have access to that call, you may need to pass in your ClassLoader explicitly. So, you may need invoke ResourceBundle.getBundle(String pBaseName, Locale pLocale, ClassLoader pLoader) and pass in this.getClass().getClassLoader() for the ClassLoader argument.


Nested Class Summary
static class LayeredResourceBundle.LayeredResourceBundleControl
          A Control subclass that implements layering of resource bundles.
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.util.List<java.lang.String> FORMAT_LAYERED_PROPERTIES
          The layered-properties-only format List containing "layered_java.properties".
static LayeredResourceBundle.LayeredResourceBundleControl sLayeredResourceBundleControl
          The static LayeredResourceBundle control we used.
static java.lang.String STRING_LAYERED_JAVA_PROPERTIES
          The string for the "layered_java.properties" format we support.
 
Constructor Summary
LayeredResourceBundle()
           
 
Method Summary
static java.util.ResourceBundle getBundle(java.lang.String pBaseName)
          Gets a layered resource bundle using the specified base name, the default locale, and the LayeredResourceBundle's class loader.
static java.util.ResourceBundle getBundle(java.lang.String pBaseName, java.util.Locale pLocale)
          Gets a layered resource bundle using the specified base name and locale, and the LayeredResourceBundle's class loader.
static java.util.ResourceBundle getBundle(java.lang.String pBaseName, java.util.Locale pLocale, java.lang.ClassLoader pLoader)
          Gets a resource bundle using the specified base name, locale, and class loader.
static void main(java.lang.String[] pArgs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


sLayeredResourceBundleControl

public static LayeredResourceBundle.LayeredResourceBundleControl sLayeredResourceBundleControl
The static LayeredResourceBundle control we used.


STRING_LAYERED_JAVA_PROPERTIES

public static final java.lang.String STRING_LAYERED_JAVA_PROPERTIES
The string for the "layered_java.properties" format we support.

See Also:
Constant Field Values

FORMAT_LAYERED_PROPERTIES

public static final java.util.List<java.lang.String> FORMAT_LAYERED_PROPERTIES
The layered-properties-only format List containing "layered_java.properties". This List is unmodifiable.

See Also:
#getFormats(String)
Constructor Detail

LayeredResourceBundle

public LayeredResourceBundle()
Method Detail

getBundle

public static final java.util.ResourceBundle getBundle(java.lang.String pBaseName)
Gets a layered resource bundle using the specified base name, the default locale, and the LayeredResourceBundle's class loader. Calling this method is equivalent to calling getBundle(baseName, Locale.getDefault(), Thread.currentThread().getContextClassLoader()). And, if the above returns null, returning the result of: getBundle(baseName, Locale.getDefault(), LayeredResourceBundle.class.getClassLoader()).

Parameters:
pBaseName - the base name of the resource bundle, a fully qualified class name
Returns:
a resource bundle for the given base name and the default locale
Throws:
java.lang.NullPointerException - if baseName is null
java.util.MissingResourceException - if no resource bundle for the specified base name can be found
See Also:
ResourceBundle.getBundle(String)

getBundle

public static final java.util.ResourceBundle getBundle(java.lang.String pBaseName,
                                                       java.util.Locale pLocale)
Gets a layered resource bundle using the specified base name and locale, and the LayeredResourceBundle's class loader. Calling this method is equivalent to calling getBundle(baseName, Locale.getDefault(), Thread.currentThread().getContextClassLoader()). And, if the above returns null, returning the result of: getBundle(baseName, locale, LayeredResourceBundle.class.getClassLoader()).

Parameters:
pBaseName - the base name of the resource bundle, a fully qualified class name
pLocale - the locale for which a resource bundle is desired
Returns:
a resource bundle for the given base name and locale
Throws:
java.lang.NullPointerException - if baseName or locale is null
java.util.MissingResourceException - if no resource bundle for the specified base name can be found
See Also:
ResourceBundle.getBundle(String,Locale)

getBundle

public static java.util.ResourceBundle getBundle(java.lang.String pBaseName,
                                                 java.util.Locale pLocale,
                                                 java.lang.ClassLoader pLoader)
Gets a resource bundle using the specified base name, locale, and class loader. See ResourceBundle.getBundle(String,Locale,ClassLoader) for a full description of the search path used to obtain a resource bundle. This is further augmented by a pre-processing step, where all resource bundle properties files with a given name will be collapsed into a single file. The files will be combine in such a way that entries which come early in the classpath will appear at the end of the input stream. The ResourceBundle code will then create a Properties instance using that composite input stream. Given that later entries in the Properties map will overwrite earlier entries, the result will be a ResourceBundle whose values can be overriden by prepending a sparse properties file, containing only the values to be altered, to the beginning of the class-path.

Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
locale - the locale for which a resource bundle is desired
loader - the class loader from which to load the resource bundle
Returns:
a resource bundle for the given base name and locale
Throws:
java.lang.NullPointerException - if baseName, locale, or loader is null
java.util.MissingResourceException - if no resource bundle for the specified base name can be found
See Also:
ResourceBundle.getBundle(String,Locale,ClassLoader)

main

public static void main(java.lang.String[] pArgs)