com.novell.nds.dirxml.util
Class LocalizedMessageSource

java.lang.Object
  extended by com.novell.nds.dirxml.util.LocalizedMessageSource
All Implemented Interfaces:
MessageSource

public class LocalizedMessageSource
extends Object
implements MessageSource

Class implementing the MessageSource interface for obtaining localized messages for tracing, status messages, etc.

The class is designed such that class hierarchies can use a hierarchy of LocalizedMessageSource instances to obtain localized strings. For example assume com.company.DerivedClass is derived from com.company.BaseClass. BaseClass would contain a member variable of class LocalizedMessageSource that is constructed as follows:

LocalizedMessageSource msgSource = new LocalizedMessageSource("com.company.BaseClass");
DerivedClass would contain a member variable of class LocalizedMessageSource that is constructed as follows:
LocalizedMessageSource msgSource = new LocalizedMessageSource("com.company.DerivedClass",super.msgSource);
DerivedClass can then use message IDs defined in either DerivedClass or BaseClass.

Messages are located in a resource bundle and formatted using java.text.MessageFormat.

See Also:
ResourceBundle, MessageFormat

Field Summary
protected  ResourceBundle bundle
          ResourceBundle from which to obtain message strings.
protected  LocalizedMessageSource parent
          Parent LocalizedMessageSource.
 
Constructor Summary
LocalizedMessageSource(String resourceBundleName)
          Construct a LocalizedMessageSource based on the passed resource name.
LocalizedMessageSource(String resourceBundleName, Locale locale)
          Construct a LocalizedMessageSource based on the passed resource name.
LocalizedMessageSource(String resourceBundleName, LocalizedMessageSource parent)
          Construct a LocalizedMessageSource based on the passed resource name and a parent class's LocalizedMessageSource instance.
LocalizedMessageSource(String resourceBundleName, LocalizedMessageSource parent, Locale locale)
          Construct a LocalizedMessageSource based on the passed resource name and a parent class's LocalizedMessageSource instance.
 
Method Summary
 String getMessage(String msgID, Object[] parms)
          Get a localized message.
 String getMessageString(String msgID)
          Get a message string from this instance's ResourceBundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundle

protected ResourceBundle bundle
ResourceBundle from which to obtain message strings.


parent

protected LocalizedMessageSource parent
Parent LocalizedMessageSource. If a message is not found in bundle then parent.getMessageString() is called.

Constructor Detail

LocalizedMessageSource

public LocalizedMessageSource(String resourceBundleName)
                       throws MissingResourceException
Construct a LocalizedMessageSource based on the passed resource name. The resource name is typically the name of the class that is constructing the instance. Uses default locale.

Parameters:
resourceBundleName - name of resource bundle
Throws:
MissingResourceException

LocalizedMessageSource

public LocalizedMessageSource(String resourceBundleName,
                              Locale locale)
                       throws MissingResourceException
Construct a LocalizedMessageSource based on the passed resource name. The resource name is typically the name of the class that is constructing the instance.

Parameters:
resourceBundleName - name of resource bundle
locale - locale for localized resources.
Throws:
MissingResourceException

LocalizedMessageSource

public LocalizedMessageSource(String resourceBundleName,
                              LocalizedMessageSource parent)
                       throws MissingResourceException
Construct a LocalizedMessageSource based on the passed resource name and a parent class's LocalizedMessageSource instance.

Parameters:
resourceBundleName - name of resource bundle
parent - parent class's LocalizedMessageSource instance.
Throws:
MissingResourceException

LocalizedMessageSource

public LocalizedMessageSource(String resourceBundleName,
                              LocalizedMessageSource parent,
                              Locale locale)
                       throws MissingResourceException
Construct a LocalizedMessageSource based on the passed resource name and a parent class's LocalizedMessageSource instance.

Parameters:
resourceBundleName - name of resource bundle
parent - parent class's LocalizedMessageSource instance.
locale - locale for localized resources.
Throws:
MissingResourceException
Method Detail

getMessage

public String getMessage(String msgID,
                         Object[] parms)
Get a localized message.

Specified by:
getMessage in interface MessageSource
Parameters:
msgID - message key or ID
parms - array of parameters for message (may be null for messages that do not require parameters).

getMessageString

public String getMessageString(String msgID)
Get a message string from this instance's ResourceBundle. If a message corresponding to the passed message ID is not found then the message ID is returned.

Parameters:
msgID - id or key of message string in resource bundle.