wt.util
Class WTMessage

java.lang.Object
  extended by wt.util.WTMessage
All Implemented Interfaces:
Externalizable, Serializable, Evolvable, LocalizableMessage, Message

public class WTMessage
extends Object
implements LocalizableMessage, Evolvable, Serializable

WTMessage is the wrapper class for getting a formatted, localized message, from a resource bundle.

The following are examples of how WTMessage would be used:

    Static usage:
       Object[] textInserts = { getName() };
       System.out.println(
          WTMessage.getLocalizedMessage( RESOURCE, "17", textInserts )
 );
 

Instance usage: Object[] textInserts = { getName() }; WTMessage wtMessage = new WTMessage( RESOURCE, "17", textInserts ); // ... other stuff wtMessage.getLocalizedMessage();

Localization of the WTMessage messages relies on the resource bundle and text formatting features of Java. In the example above, RESOURCE is a string constant that identifies the resource bundle containing the localizable message.

Objects that act as text insert parameters of the message will make use of the getLocalizedMessage(Locale) method, if those insert objects implement the wt.util.LocalizableMessage interface. This enables the message inserts to be localized, along with the message itself, at the time the localized message is requested.

Supported API: true

Extendable: false

See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale), Serialized Form

Constructor Summary
WTMessage(String rb, String key, Object[] params)
          Constructs a Windchill message with a localizable detailed message.
 
Method Summary
static String formatLocalizedMessage(String localizedString, Object[] inserts)
          This method will process an already localized string by escaping any appropriate characters, and then call java.text.MessageFormat on the String to properly insert any inserts.
 String getLocalizedMessage()
          Gets the localized message, for the instance.
 String getLocalizedMessage(Locale locale)
          Obtain a message, localized to the specified locale.
static String getLocalizedMessage(String resourceBundle, String messageKey, Object[] textInserts)
          Gets the localized message, for passed arguments.
static String getLocalizedMessage(String resourceBundle, String messageKey, Object[] textInserts, Locale locale)
          Gets the localized message, for passed arguments.
 String getMessageIdentifier()
          Gets the identity of the message.
static WTMessage[] getMessages(String rb, String key, Object[] params)
          Loops over the arrayed elements of params to generate multiple WTMessages, one for each element.
 String toString()
          Returns the localized message, for the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WTMessage

public WTMessage(String rb,
                 String key,
                 Object[] params)
Constructs a Windchill message with a localizable detailed message.

Param objects of type wt.util.LocalizableMessage will be expanded by invoking getLocalizedMessage(Locale) on them.

Supported API: true

Parameters:
rb - the name of the base resource bundle subclass containing the localizable message.
key - the key associated with the localizable message
params - an optional set of objects to be formatted into the localizable message text.
See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale)
Method Detail

getLocalizedMessage

public String getLocalizedMessage(Locale locale)
Obtain a message, localized to the specified locale.

Supported API: true

Specified by:
getLocalizedMessage in interface LocalizableMessage
Parameters:
locale -
Returns:
String

getMessages

public static WTMessage[] getMessages(String rb,
                                      String key,
                                      Object[] params)
Loops over the arrayed elements of params to generate multiple WTMessages, one for each element.

Param objects of type wt.util.LocalizableMessage will be expanded by invoking getLocalizedMessage(Locale) on them.

Supported API: true

Parameters:
rb - the name of the base resource bundle subclass containing the localizable message.
key - the key associated with the localizable message
params - an optional set of objects to be formatted into the localizable message text. If an element of params is itself an array, loop over those elements to produce multiple WTMessages, one for each element.
params - an optional set of objects to be formatted into the localizable message text.
See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale)

getLocalizedMessage

public String getLocalizedMessage()
Gets the localized message, for the instance.

Supported API: true

See Also:
ResourceBundle, MessageFormat

getLocalizedMessage

public static String getLocalizedMessage(String resourceBundle,
                                         String messageKey,
                                         Object[] textInserts)
Gets the localized message, for passed arguments.

Param objects of type wt.util.LocalizableMessage will be expanded by invoking getLocalizedMessage(Locale) on them.

Supported API: true

Parameters:
rb - the name of the base resource bundle subclass containing the localizable message.
key - the key associated with the localizable message
params - an optional set of objects to be formatted into the localizable message text.
See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale)

formatLocalizedMessage

public static String formatLocalizedMessage(String localizedString,
                                            Object[] inserts)
This method will process an already localized string by escaping any appropriate characters, and then call java.text.MessageFormat on the String to properly insert any inserts. Wherever possible the method getLocalizedMessage( ) should be used, since this allows for caching of resources etc. However in some cases, to avoid rewriting major pieces of code, MessageFormat.format( ) can be directly replaced with WTMessage.formatLocalizedMessage( )

Supported API: true

Parameters:
localizedString - The localized String to format
inserts - The inserts to insert via the MessageFormat
Returns:
The localized String formatted properly.

getLocalizedMessage

public static String getLocalizedMessage(String resourceBundle,
                                         String messageKey,
                                         Object[] textInserts,
                                         Locale locale)
Gets the localized message, for passed arguments.

Param objects of type wt.util.LocalizableMessage will be expanded by invoking getLocalizedMessage(Locale) on them.

Implementation Notes: Any usage of "{" or "}" characters in which there are intended to be used as "{" or "}" (and not inset delimiters) should be enclosed in "'" (apostrophes). For example, if you would like to have a String


Then the resource file should use a ' to escape the curly brakcets, such that the string becomes


For further details please see the javadoc for java.text.MessageFormat.

Supported API: true

Parameters:
rb - the name of the base resource bundle subclass containing the localizable message.
key - the key associated with the localizable message
params - an optional set of objects to be formatted into the localizable message text.
locale - the locale for which to get the localized message.
See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale)

getMessageIdentifier

public String getMessageIdentifier()
Gets the identity of the message.

Supported API: true

Returns:
the identity, as the resource bundle name and the messageKey.

toString

public String toString()
Returns the localized message, for the instance.

Supported API: true

Overrides:
toString in class Object