com.buck.commons.i18n
Class ResourceBundle

java.lang.Object
  extended by com.buck.commons.i18n.ResourceBundle

public final class ResourceBundle
extends Object

Class to hide details of getting a resource bundle, properly; the class also provides facilities to format resource bundle messages.

The general form to format resource bundle messages is:

  try {
    // ...
  } catch (Exception e) {
      Object[] fmtargs = {yourValue};
      String message = ResourceBundle.formatResourceBundleMessage(
                         YourLexicallyEnclosingClassName.class,
                         "YOUR_RESOURCE_BUNDLE_MESSAGE_MNEMONIC", fmtargs);
      throw new Exception(message, e);
  }
 

In the package containing YourLexicallyEnclosingClassName.class you would add a file named resource.properties, which may have the following content, where CAFEBABE is a Hex error code:

 YOUR_RESOURCE_BUNDLE_MESSAGE_MNEMONIC=(ERROR:CAFEBABE) An error occurred
 processing ({0}).
 

Author:
Robert J. Buck

Constructor Summary
ResourceBundle()
           
 
Method Summary
static String formatResourceBundleMessage(Class c, String mnemonic, Object[] arguments)
          A helper function to format a message using a resource identified by its mnemonic, located in a resource bundle located in the package of the given class.
static ResourceBundle getResourceBundle(Class c)
          Get the resource bundle in the package of the specified class.
static ResourceBundle getResourceBundle(String baseName)
          Get a resource bundle using the context class loader and default locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBundle

public ResourceBundle()
Method Detail

getResourceBundle

public static ResourceBundle getResourceBundle(String baseName)
Get a resource bundle using the context class loader and default locale.

Parameters:
baseName - the name of the resource bundle
Returns:
the resource bundle for baseName

getResourceBundle

public static ResourceBundle getResourceBundle(Class c)
Get the resource bundle in the package of the specified class. The name for this resource bundle in the package must be "resource.properties".

Parameters:
c - the class in whose package a resource.properties file exists.
Returns:
the resource bundle

formatResourceBundleMessage

public static String formatResourceBundleMessage(Class c,
                                                 String mnemonic,
                                                 Object[] arguments)
A helper function to format a message using a resource identified by its mnemonic, located in a resource bundle located in the package of the given class.

Parameters:
c - the class in whose package we will load a resource bundle
mnemonic - the message mnemonic to load from the bundle
arguments - formatting arguments
Returns:
the formatted message


Copyright © 2013. All Rights Reserved.