com.calitha.resource
Class XMLResourceBundleControl

java.lang.Object
  extended by java.util.ResourceBundle.Control
      extended by com.calitha.resource.XMLResourceBundleControl

public class XMLResourceBundleControl
extends ResourceBundle.Control

The XMLResourceBundleControl is used to support resource bundles in a custom XML format using the new control in Java 1.6. This control can be used when getting a bundle.

Example:

 ResourceBundle.getBundle(baseName,
                          locale,
                          new XMLResourceBundleControl());
 

Author:
Robert van Loenhout
See Also:
XMLResourceBundle

Field Summary
 
Fields inherited from class java.util.ResourceBundle.Control
FORMAT_CLASS, FORMAT_DEFAULT, FORMAT_PROPERTIES, TTL_DONT_CACHE, TTL_NO_EXPIRATION_CONTROL
 
Constructor Summary
XMLResourceBundleControl()
           
 
Method Summary
 Locale getFallbackLocale(String baseName, Locale locale)
          No fallback locale is used, because they are undesired for most application.
 List<String> getFormats(String baseName)
          Returns XML as a supported format.
 ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
          Gets a new XMLResourceBundle objects by parsing the XML file at a location determined by the baseName and locale.
 
Methods inherited from class java.util.ResourceBundle.Control
getCandidateLocales, getControl, getNoFallbackControl, getTimeToLive, needsReload, toBundleName, toResourceName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLResourceBundleControl

public XMLResourceBundleControl()
Method Detail

getFormats

public List<String> getFormats(String baseName)
Returns XML as a supported format.

Overrides:
getFormats in class ResourceBundle.Control
Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
Returns:
list with XML format

newBundle

public ResourceBundle newBundle(String baseName,
                                Locale locale,
                                String format,
                                ClassLoader loader,
                                boolean reload)
                         throws IllegalAccessException,
                                InstantiationException,
                                IOException
Gets a new XMLResourceBundle objects by parsing the XML file at a location determined by the baseName and locale.

Overrides:
newBundle in class ResourceBundle.Control
Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
locale - the locale for which a resource bundle is desired
format - the resource bundle format to be loaded
loader - the ClassLoader to use to load the bundle
reload - the flag to indicate bundle reloading; true if reloading an expired resource bundle, false otherwise
Returns:
XMLResourceBundle instance, or null if none could be found
Throws:
IllegalAccessException - if format is unknown, or if the resource found for the given parameters contains malformed data
InstantiationException - if the instantiation of a class fails for some other reason
IOException - if an error occurred when reading resources using any I/O operations
IllegalArgumentException - if an argument is null

getFallbackLocale

public Locale getFallbackLocale(String baseName,
                                Locale locale)
No fallback locale is used, because they are undesired for most application. Server software should not depend on the locale that has been set on that server.

Overrides:
getFallbackLocale in class ResourceBundle.Control
Parameters:
baseName - the base name of the resource bundle, a fully qualified class name for which ResourceBundle.getBundle has been unable to find any resource bundles (except for the base bundle)
locale - a Locale for the fallback search, or null if no further fallback search is desired.
Returns:
alyways returns null, so that the base bundle is used