ch.dueni.util
Class MultiplePropertiesResourceBundle

java.lang.Object
  extended by java.util.ResourceBundle
      extended by ch.dueni.util.MultiplePropertiesResourceBundle

public abstract class MultiplePropertiesResourceBundle
extends java.util.ResourceBundle

MultiplePropertiesResourceBundle is an abstract base implementation to allow to combine a ResourceBundle from multiple properties files whereas these properties files must end with the same name - the base-name for these combined ResourceBundle.

A concrete implementation must subclass this class and provide a default constructor in which super("base-name"); or super("package.name","base-name"); must be called depending on if your properties files are located in default or a specific package.

 public class ExampleResourceBundle extends MultiplePropertiesResourceBundle {
        public ExampleResourceBundle() {
                super("example");
        }
 }
 
 or 
 
 public class ExampleResourceBundle extends MultiplePropertiesResourceBundle {
        public ExampleResourceBundle() {
                super("my.package", "example");
        }
 }
 

For each Locale that you need to support you also must provide Locale variants of your java ResourceBindle class as shown below. Creating an empty subclass of the above class does the job - the separate class is needed to let ResourceBundle.getBundle(String, Locale) find and cache your bundle with the right Locale.

 public class ExampleResourceBundle_de extends ExampleResourceBundle {
 }
 

File name rules

To allow automatic detection of the multiple properties files, for each filename you must provide a general properties file without any Locale extension in the name (e.g. additional-example.properties as a variant to examples.properties) - otherwise that properties file name will not be used to load as PropertyResourceBundle. Let's assume we used the base-name "example" and the following list of properties files are reachable:

Only example and additional-example will be used as base-names to load this MultiplePropertiesResourceBundle - another-example.properties is missing and therefore another-example is not detected as a valid base-name.

It is also supported to provide additional properties files with a jar file. To make sure that jar file is recognized as properties file provider it must contain a file "base-name".properties (e.g. example.properties). This marker file may be empty and is only used to find all resource paths containing properties files of interest (with matching base-name). In fact, every path location containing properties files to be combined into one MultiplePropertiesResourceBundle must contain that "base-name".properties file.

Author:
Hanspeter Dünnenberger

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.ResourceBundle
java.util.ResourceBundle.Control
 
Method Summary
 java.util.Enumeration<java.lang.String> getKeys()
           
 java.lang.Object handleGetObject(java.lang.String key)
           
 
Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, keySet
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

handleGetObject

public java.lang.Object handleGetObject(java.lang.String key)
Specified by:
handleGetObject in class java.util.ResourceBundle

getKeys

public java.util.Enumeration<java.lang.String> getKeys()
Specified by:
getKeys in class java.util.ResourceBundle