net.rim.device.api.i18n
Class MessageFormat

java.lang.Object
  |
  +--net.rim.device.api.i18n.Format
        |
        +--net.rim.device.api.i18n.MessageFormat

public class MessageFormat
extends Format

Formats and parses messages in a locale-sensitive manner.

Locale-specific formatting is passed on to other formatter objects that inserted into this formatter's pattern (this class supports the string, date, and time element formats).

Compatible with java.text.MessageFormat in Java's standard edition.


Constructor Summary
MessageFormat(String pattern)
          Constructs new MessageFormat instance with the given pattern string.
 
Method Summary
 void applyPattern(String newPattern)
          Applies a new pattern string to this formatter.
 StringBuffer format(Object arguments, StringBuffer result, FieldPosition ignored)
          Retrieves formatted string representation of argument list.
static String format(String pattern, Object[] arguments)
          Retrieves formatted string represenation of argument list, with provided pattern string.
 int[] getFields()
          Retrieves ordered list of fields.
 Format[] getFormats()
          Retrieves list of sub-formatters.
 Locale getLocale()
          Retrieves current locale.
 int hashCode()
          Returns a hash code for this object.
 void setFormat(int variable, Format format)
          Assign a single sub-formatter to a particular component in this formatter's pattern string.
 void setFormats(Format[] formats)
          Sets new list of sub-formatters.
 void setLocale(Locale locale)
          Sets the locale.
 
Methods inherited from class net.rim.device.api.i18n.Format
format
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageFormat

public MessageFormat(String pattern)
Constructs new MessageFormat instance with the given pattern string.

Parameters:
pattern - Pattern string for this formatter.
Method Detail

applyPattern

public void applyPattern(String newPattern)
Applies a new pattern string to this formatter.

Parameters:
newPattern - New pattern string to use with this formatter.

format

public final StringBuffer format(Object arguments,
                                 StringBuffer result,
                                 FieldPosition ignored)
Retrieves formatted string representation of argument list.

Overrides:
format in class Format
Parameters:
arguments - Argument list to be formatted. This must always be an array.
result - String buffer to hold the formatted results.
ignored - Ignored parameter.
Returns:
String buffer containing formatted argument list.

format

public static String format(String pattern,
                            Object[] arguments)
Retrieves formatted string represenation of argument list, with provided pattern string.

This method lets you retrieve formatted argument lists without having to instantiate a message formatter.

Parameters:
pattern - Pattern string that formatter should use.
arguments - Argument list to be formatted.
Returns:
Formatted arguments in a string.

getFields

public int[] getFields()
Retrieves ordered list of fields.
Overrides:
getFields in class Format
Returns:
List of field identifiers for the fields in a format string.

getFormats

public Format[] getFormats()
Retrieves list of sub-formatters.

This class uses sub-formatters to assist in locale-specific formatting of message components. This method retrieves this formatter's list of sub-formatters.

Returns:
Current list of sub-formatters.

getLocale

public Locale getLocale()
Retrieves current locale.

Returns:
Current locale.

hashCode

public int hashCode()
Returns a hash code for this object. For pattern hash code request it directly.

Overrides:
hashCode in class Object
Returns:
Hash code of this class.

setFormat

public void setFormat(int variable,
                      Format format)
Assign a single sub-formatter to a particular component in this formatter's pattern string.

Each variable in this formatter's pattern string stands for a particular message component. Treat the pattern string as a zero-based list of variables in order to determine which variable number you should pass to this method.

Parameters:
variable - Offset (past the first variable in the pattern string) of the pattern string variable to be assigned the sub-formatter.
format - Sub-formatter in charge of formatting the message component in question.

setFormats

public void setFormats(Format[] formats)
Sets new list of sub-formatters.

This formatter employs a set of sub-formatters to provide locale-specific formatting of message components. Use this method to provide this formatter with a list of those sub-formatters.

Parameters:
formats - New list of sub-formatters this formatter should employ.

setLocale

public void setLocale(Locale locale)
Sets the locale.

Invoke this method to set this formatter to a locale other than the system default locale.

Parameters:
theLocale - New locale this formatter should use.



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.