com.digi.config.util
Class LocalizableMessage

java.lang.Object
  extended bycom.digi.config.util.LocalizableMessage
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class LocalizableMessage
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Helper class to encapsulate the retrieval and formatting of localizable messages. Instances of this class should be considered immutable. In support of this, copies are made of the substitution objects provided on the construction of instances of this class.

See Also:
Serialized Form

Constructor Summary
LocalizableMessage(java.lang.String rsrcBundleName, java.lang.String key, java.io.Serializable[] rplcTxt, java.util.Locale originalLocale)
          Create a localizable message object.
 
Method Summary
 java.lang.String getFallbackMessage()
          Gets the message text that will be returned in localization of this message fails.
 java.lang.String getLocalizedText(java.util.Locale localeToUse)
          Returns the localized text for this message.
 java.util.Locale getOriginalLocale()
          Gets the original locale used to create this message.
 java.rmi.MarshalledObject[] getReplacementText()
          Gets the replacement text that is used to create the localizable message text.
 java.lang.String getResourceBundleName()
          Gets the name of the resource bundle from where the resource used to create the localizable message text will be retrieved.
 java.lang.String getResourceKey()
          Gets the key to the resource in the resourceBundle that is used to create the localizable message text.
protected  java.lang.String localize(java.lang.String rsrcBundleName, java.lang.String key, java.io.Serializable[] rplcText, java.util.Locale localeToUse)
          Returns the localized text for this message.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalizableMessage

public LocalizableMessage(java.lang.String rsrcBundleName,
                          java.lang.String key,
                          java.io.Serializable[] rplcTxt,
                          java.util.Locale originalLocale)
Create a localizable message object.

Parameters:
rsrcBundleName - is the name of the resource bundle containing the translatable message text. This must be a fully qualified name (e.g. com....xxxResourceBundle). It is a Mandatory parameter and may not be an empty String.
key - is the key into the resourceBundle of the message text to use for this localizable message. The resource associated with this key must either be a String or a MessageFormat. It is a Mandatory parameter and may not be an empty String.
rplcTxt - is the array of objects to be used as replacement text in the text retrieved from the resourceBundle. An array element may not be null
originalLocale - is the Locale to be considered as the Locale of the message origin. It is primarily used for creating the fallbackMsg. If left null, the default Locale of the system will be used.
Throws:
java.lang.IllegalArgumentException - if rsrcBundleName or key is empty string. It may also be thrown if an unexpected error is detected while processing the replacement text.
java.lang.NullPointerException - if rsrcrBundleName or key is null or replacementText array contains a null.
Method Detail

getLocalizedText

public java.lang.String getLocalizedText(java.util.Locale localeToUse)
Returns the localized text for this message. If localization fails, a version of the message localized in the original locale will be returned instead.

Parameters:
localeToUse - is the Locale to be used for localizing the text. If not provided, the default system Locale will be used.
Returns:
Localized text of the message.

getOriginalLocale

public java.util.Locale getOriginalLocale()
Gets the original locale used to create this message. This is the Locale that was used to generate the default message text if there is a problem returning the message text in the current (or provided) Locale.

Returns:
The original Locale for this message

getResourceKey

public java.lang.String getResourceKey()
Gets the key to the resource in the resourceBundle that is used to create the localizable message text.

Returns:
the key to the resourceBundle resource used to create the localizable message

getReplacementText

public java.rmi.MarshalledObject[] getReplacementText()
Gets the replacement text that is used to create the localizable message text.

Returns:
the replacement text that is used to create the localizable message text.

getResourceBundleName

public java.lang.String getResourceBundleName()
Gets the name of the resource bundle from where the resource used to create the localizable message text will be retrieved.

Returns:
the name of the resource bundle

getFallbackMessage

public java.lang.String getFallbackMessage()
Gets the message text that will be returned in localization of this message fails. This fallback text is generated at the time the LocalizableMessage is created and uses the original Locale.

Returns:
the fallback message String

toString

public java.lang.String toString()

localize

protected java.lang.String localize(java.lang.String rsrcBundleName,
                                    java.lang.String key,
                                    java.io.Serializable[] rplcText,
                                    java.util.Locale localeToUse)
                             throws LocalizationException
Returns the localized text for this message.

Parameters:
rsrcBundleName - is the name of the resource bundle containing the translatable message text. This must be a fully qualified name (e.g. com....xxxResourceBundle). It is a Mandatory parameter and may not be an empty String.
key - is the key into the resourceBundle of the message text to use for this localizable message. The key must be associated with either a String or a MessageFormat object. It is a Mandatory parameter and may not be an empty String.
rplcText - is the array of objects to be used as replacement text in the text retrieved from the resourceBundle.
localeToUse - is the Locale in which the message text is to be formatted. It is a Mandatory parameter.
Returns:
Localized text of the message.
Throws:
LocalizationException - is thrown if localization fails. This may be because the retrieval of the resource from the messageBundle failed, the retrieved resource was not a String or MessageFormat object.
java.util.MissingResourceException - is thrown if either the resourceBundle is not found or the key is not valid within the resourceBundle


Copyright © 2001-2002 Digi International. All Rights Reserved.