public class LayeredResourceBundle
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
LayeredResourceBundle.LayeredResourceBundleControl
A Control subclass that implements layering of resource bundles.
|
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
LayeredResourceBundle() |
Modifier and Type | Method and Description |
---|---|
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) |
public static java.lang.String CLASS_VERSION
public static LayeredResourceBundle.LayeredResourceBundleControl sLayeredResourceBundleControl
public static final java.lang.String STRING_LAYERED_JAVA_PROPERTIES
public static final java.util.List<java.lang.String> FORMAT_LAYERED_PROPERTIES
List
containing
"layered_java.properties"
. This List
is
unmodifiable.#getFormats(String)
public static final java.util.ResourceBundle getBundle(java.lang.String pBaseName)
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())
.
pBaseName
- the base name of the resource bundle, a fully qualified class namejava.lang.NullPointerException
- if baseName
is null
java.util.MissingResourceException
- if no resource bundle for the specified base name can be foundResourceBundle.getBundle(String)
public static final java.util.ResourceBundle getBundle(java.lang.String pBaseName, java.util.Locale pLocale)
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())
.
pBaseName
- the base name of the resource bundle, a fully qualified class namepLocale
- the locale for which a resource bundle is desiredjava.lang.NullPointerException
- if baseName
or locale
is null
java.util.MissingResourceException
- if no resource bundle for the specified base name can be foundResourceBundle.getBundle(String,Locale)
public static java.util.ResourceBundle getBundle(java.lang.String pBaseName, java.util.Locale pLocale, java.lang.ClassLoader pLoader)
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.
baseName
- the base name of the resource bundle, a fully qualified class namelocale
- the locale for which a resource bundle is desiredloader
- the class loader from which to load the resource bundlejava.lang.NullPointerException
- if baseName
, locale
, or loader
is null
java.util.MissingResourceException
- if no resource bundle for the specified base name can be foundResourceBundle.getBundle(String,Locale,ClassLoader)
public static void main(java.lang.String[] pArgs)