wt.util
Class WTMessage

java.lang.Object
  extended bywt.util.WTMessage
All Implemented Interfaces:
LocalizableMessage, Message, Serializable
Direct Known Subclasses:
AbstractJFeedbackMessage

public class WTMessage
extends Object
implements LocalizableMessage, 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

Nested Class Summary
(package private) static class WTMessage.CacheKey
           
 
Field Summary
private static Cache cache
           
private static int cacheHits
           
private static int cacheSummaryInterval
           
private static String CLASSNAME
           
private  String messageKey
           
private static String RESOURCE
           
private  String resourceBundle
           
private static char SUBSTITUTION_CHAR
          unicode FFFF was chosen since unicode.org lists this a Not A Character, and therefore is not used by any language etc.
private  Object[] textInserts
           
 
Constructor Summary
protected WTMessage()
           
  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.
private static Cache getCache()
           
 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.
private static String postFormatMessage(String msg)
          This method will post format a message so that all the escaped ' characters are restored.
private static String preFormatMessage(String msg)
          This method will pre format a message so that all the unescaping ' characters are replaced with the unicode character ￿.
protected static void preProcessArgs(Object[] textInserts, Locale locale)
           
protected  void setLocalizedMessage(String rb, String key, Object[] params)
          Sets the localized message for this WTMessage.
 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
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

cache

private static Cache cache

cacheSummaryInterval

private static int cacheSummaryInterval

cacheHits

private static int cacheHits

SUBSTITUTION_CHAR

private static final char SUBSTITUTION_CHAR
unicode FFFF was chosen since unicode.org lists this a Not A Character, and therefore is not used by any language etc. Tests have shown it to be excepted by MessageFormat

See Also:
Constant Field Values

resourceBundle

private String resourceBundle

messageKey

private String messageKey

textInserts

private Object[] textInserts
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)

WTMessage

protected WTMessage()
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.
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

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:
locale - the locale for which to get the localized message.
See Also:
ResourceBundle, MessageFormat, LocalizableMessage.getLocalizedMessage(java.util.Locale)

preFormatMessage

private static final String preFormatMessage(String msg)
This method will pre format a message so that all the unescaping ' characters are replaced with the unicode character ￿.

Parameters:
msg - The message the pre format.
Returns:
The formatted message.

postFormatMessage

private static final String postFormatMessage(String msg)
This method will post format a message so that all the escaped ' characters are restored.

Parameters:
msg - The message the post format.
Returns:
The restored message.

getMessageIdentifier

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

Supported API: true

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

preProcessArgs

protected static void preProcessArgs(Object[] textInserts,
                                     Locale locale)

setLocalizedMessage

protected void setLocalizedMessage(String rb,
                                   String key,
                                   Object[] params)
Sets the localized message for this WTMessage.

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

Supported API: false

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)

toString

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

Supported API: true


getCache

private static Cache getCache()