atg.core.i18n
Class LayeredResourceBundle
java.lang.Object
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:
- It only supports properties file format for resources, not XML format
- It does not know the ClassLoader of the calling class.
- LayeredResourceBundle.getBundle() must be called for that bundle
prior to any other calls to ResourceBundle.getBundle() for the same
bundle name. Otherwise, a non-layered bundle will be returned.
- LayeredResourceBundle is not compatible with the "-collapse-class-path"
option of the /bin/runAssembler command.
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.
The LayeredResourceBundle re-uses a maximal amount of ResourceBundle.getBundle()'s
code. Instead of re-implementing all the ResourceBundle logic, it creates a child
ClassLoader that returns a special InputStream for .properties file. That
CompositeInputStream concatenates all the properties files from the classpath so
that the final result of the Properties file allows values to bleed through properly.
Field Summary |
static java.lang.String |
CLASS_VERSION
Class version string |
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 |
CLASS_VERSION
public static java.lang.String CLASS_VERSION
- Class version string
LayeredResourceBundle
public LayeredResourceBundle()
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(), 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
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, LayeredResourceBundle.class.getClassLoader())
.
- Parameters:
pBaseName
- the base name of the resource bundle, a fully qualified class namepLocale
- 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
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 namelocale
- the locale for which a resource bundle is desiredloader
- 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
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)