com.ice.util
Class ResourceManager

java.lang.Object
  |
  +--com.ice.util.ResourceManager

public class ResourceManager
extends java.lang.Object

This class attempts to manage a set of ResourceBundles. For example, an application may have one set of resources for the GUI elements in the application, and another set of resources for context help, and yet another set for builtin scripts. Each ResourceManager instance is identified by an id. Class methods provided to allow quick access to any ResourceManager by id. ResourceManager, aside from manager multiple instances by id, also add an additional method beyond that provided by ResourceBundle - getFormat(). This method is like getString() in that is returns a String resource, however, getFormat() formats the resource using arguments passed to the method. This makes it easy to use resources for both constant strings and formatted strings.

Version:
$Revision: 1.1 $
Author:
Timothy Gerard Endres, time@ice.com.

Field Summary
static java.lang.String RCS_ID
           
static java.lang.String RCS_REV
           
 
Constructor Summary
ResourceManager(java.lang.String name, java.util.ResourceBundle rsrc)
          Construct a ResourceManager with the given name and ResourceBundle.
 
Method Summary
static ResourceManager get(java.lang.String id)
          Get a ResourceManager keyed by id.
 java.lang.String getFormat(java.lang.String key, java.lang.Object[] args)
          Format a string resource from the ResourceBundle that this ResourceManager is managing.
 java.lang.String getString(java.lang.String key)
          Get a string resource from the ResourceBundle that this ResourceManager is managing.
static void initialize()
          Initializes the class by instantiating the bundles Hashtable.
static void load(java.lang.String id, java.lang.String name)
          Load a PropertyResourceBundle using the name, and add it to the bundles Hashtable keyed by id.
static ResourceManager put(java.lang.String id, ResourceManager rMgr)
          Put a ResourceManager into the bundles Hashtable, keyed by id.
 void setDebug(boolean debug)
          Set the debugging flag for this ResourceManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RCS_ID

public static final java.lang.String RCS_ID
See Also:
Constant Field Values

RCS_REV

public static final java.lang.String RCS_REV
See Also:
Constant Field Values
Constructor Detail

ResourceManager

public ResourceManager(java.lang.String name,
                       java.util.ResourceBundle rsrc)
                throws java.util.MissingResourceException
Construct a ResourceManager with the given name and ResourceBundle.

Parameters:
name - The (display) name of this resource bundle.
rsrc - The resource bundle to be managed.
Method Detail

initialize

public static void initialize()
Initializes the class by instantiating the bundles Hashtable. Your application must call this class method only once, and before calling any other methods in this class.


load

public static void load(java.lang.String id,
                        java.lang.String name)
Load a PropertyResourceBundle using the name, and add it to the bundles Hashtable keyed by id.

Parameters:
id - The id of the ResourceManager. This is used as the key into the bundles table.
name - The name of the ResourceManager. This is used to load the resource bundle.

get

public static ResourceManager get(java.lang.String id)
Get a ResourceManager keyed by id.

Parameters:
id - The id of the ResourceManager to be returned.
Returns:
The ResourceManager identied by id.

put

public static ResourceManager put(java.lang.String id,
                                  ResourceManager rMgr)
Put a ResourceManager into the bundles Hashtable, keyed by id.

Parameters:
id - The id used to identify this ResourceManager.
rMgr - The resource manager to be managed.
Returns:
The previous ResourceManager identied by id, or null.

setDebug

public void setDebug(boolean debug)
Set the debugging flag for this ResourceManager. If debugging is set to true, debugging will be printed to System.err.

Parameters:
debug - The new debugging setting.

getString

public java.lang.String getString(java.lang.String key)
Get a string resource from the ResourceBundle that this ResourceManager is managing.

Parameters:
key - The key of the resource to retrieve.
Returns:
The resource string.

getFormat

public java.lang.String getFormat(java.lang.String key,
                                  java.lang.Object[] args)
Format a string resource from the ResourceBundle that this ResourceManager is managing. The key is used to retrieve a resource that is the format, which is then formatted using the provided arguments.

Parameters:
key - The key of the resource that is the message format.
args - The arguments to be used to format the message.
Returns:
The formatted resource message.


Copyright © 1997-2003, Timothy G. Endres, All Rights Reserved.