org.opends.messages
Class Message

java.lang.Object
  extended by org.opends.messages.Message
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable<Message>, java.util.Formattable

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=true,
           mayExtend=false,
           mayInvoke=true)
public final class Message
extends java.lang.Object
implements java.lang.CharSequence, java.util.Formattable, java.lang.Comparable<Message>

Renders sensitive textural strings. In most cases message are intended to render textural strings in a locale-sensitive manner although this class defines convenience methods for creating uninternationalized Message objects that render the same text regardless of the requested locale. This class implements CharSequence so that messages can be supplied as arguments to other messages. This way messages can be composed of fragments of other messages if necessary.

See Also:
MessageDescriptor

Field Summary
static Message EMPTY
          Represents an empty message string.
 
Method Summary
 char charAt(int index)
          Returns the char value at the specified index of this message rendered using the default locale.
 char charAt(java.util.Locale locale, int index)
          Returns the char value at the specified index of this message rendered using a specific.
 int compareTo(Message o)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Indicates whether some other message is "equal to" this one.
 void formatTo(java.util.Formatter formatter, int flags, int width, int precision)
          Formats the object using the provided formatter.
static Message fromObject(java.lang.Object object, java.lang.Object... arguments)
          Creates an uninternationalized message from the string representation of an object.
 byte[] getBytes()
          Returns the byte representation of this messages in the default locale.
 MessageDescriptor getDescriptor()
          Gets the descriptor that holds descriptive information about this message.
 int hashCode()
          Returns a hash code value for the object.
 int length()
          Returns the length of this message as rendered using the default locale.
 int length(java.util.Locale locale)
          Returns the length of this message as rendered using a specific locale.
static Message raw(Category category, Severity severity, java.lang.CharSequence formatString, java.lang.Object... args)
          Creates an uninternationalized message that will render itself the same way regardless of the locale requested in toString(Locale).
static Message raw(java.lang.CharSequence formatString, java.lang.Object... args)
          Creates an uninternationalized message that will render itself the same way regardless of the locale requested in toString(Locale).
 java.lang.CharSequence subSequence(int start, int end)
          Returns a new CharSequence that is a subsequence of this message rendered using the default locale.
 java.lang.CharSequence subSequence(java.util.Locale locale, int start, int end)
          Returns a new CharSequence that is a subsequence of this message rendered using a specific locale.
 java.lang.String toString()
          Gets the string representation of this message.
 java.lang.String toString(java.util.Locale locale)
          Gets the string representation of this message appropriate for locale.
static java.lang.String toString(Message message)
          Returns the string representation of the message in the default locale.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final Message EMPTY
Represents an empty message string.

Method Detail

raw

public static Message raw(java.lang.CharSequence formatString,
                          java.lang.Object... args)
Creates an uninternationalized message that will render itself the same way regardless of the locale requested in toString(Locale). The message will have a category of Categore.USER_DEFINED and a severity of Severity.INFORMATION Note that the types for args must be consistent with any argument specifiers appearing in formatString according to the rules of java.util.Formatter. A mismatch in type information will cause this message to render without argument substitution. Before using this method you should be sure that the message you are creating is locale sensitive. If so you should instead create a formal message.

Parameters:
formatString - of the message or the message itself if not arguments are necessary
args - any arguments for the format string
Returns:
a message object that will render the same in all locales; null if formatString is null

raw

public static Message raw(Category category,
                          Severity severity,
                          java.lang.CharSequence formatString,
                          java.lang.Object... args)
Creates an uninternationalized message that will render itself the same way regardless of the locale requested in toString(Locale). Note that the types for args must be consistent with any argument specifiers appearing in formatString according to the rules of java.util.Formatter. A mismatch in type information will cause this message to render without argument substitution. Before using this method you should be sure that the message you are creating is locale sensitive. If so you should instead create a formal message.

Parameters:
category - of this message
severity - of this message
formatString - of the message or the message itself if not arguments are necessary
args - any arguments for the format string
Returns:
a message object that will render the same in all locales; null if formatString is null

fromObject

public static Message fromObject(java.lang.Object object,
                                 java.lang.Object... arguments)
Creates an uninternationalized message from the string representation of an object. Note that the types for args must be consistent with any argument specifiers appearing in formatString according to the rules of java.util.Formatter. A mismatch in type information will cause this message to render without argument substitution.

Parameters:
object - from which the message will be created
arguments - for message
Returns:
a message object that will render the same in all locales; null if object is null

toString

public static java.lang.String toString(Message message)
Returns the string representation of the message in the default locale.

Parameters:
message - to stringify
Returns:
String representation of of message of null if message is null

toString

public java.lang.String toString()
Gets the string representation of this message.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object
Returns:
String representation of this message

toString

public java.lang.String toString(java.util.Locale locale)
Gets the string representation of this message appropriate for locale.

Parameters:
locale - for which the string representation will be returned
Returns:
String representation of this message

getDescriptor

public MessageDescriptor getDescriptor()
Gets the descriptor that holds descriptive information about this message.

Returns:
MessageDescriptor information

length

public int length()
Returns the length of this message as rendered using the default locale.

Specified by:
length in interface java.lang.CharSequence
Returns:
the number of chars in this message

getBytes

public byte[] getBytes()
Returns the byte representation of this messages in the default locale.

Returns:
bytes for this message

charAt

public char charAt(int index)
            throws java.lang.IndexOutOfBoundsException
Returns the char value at the specified index of this message rendered using the default locale.

Specified by:
charAt in interface java.lang.CharSequence
Parameters:
index - the index of the char value to be returned
Returns:
the specified char value
Throws:
java.lang.IndexOutOfBoundsException - if the index argument is negative or not less than length()

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
                                   throws java.lang.IndexOutOfBoundsException
Returns a new CharSequence that is a subsequence of this message rendered using the default locale. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Specified by:
subSequence in interface java.lang.CharSequence
Parameters:
start - the start index, inclusive
end - the end index, exclusive
Returns:
the specified subsequence
Throws:
java.lang.IndexOutOfBoundsException - if start or end are negative, if end is greater than length(), or if start is greater than end

length

public int length(java.util.Locale locale)
Returns the length of this message as rendered using a specific locale.

Parameters:
locale - for which the rendering of this message will be used in determining the length
Returns:
the number of chars in this message

charAt

public char charAt(java.util.Locale locale,
                   int index)
            throws java.lang.IndexOutOfBoundsException
Returns the char value at the specified index of this message rendered using a specific.

Parameters:
locale - for which the rendering of this message will be used in determining the character
index - the index of the char value to be returned
Returns:
the specified char value
Throws:
java.lang.IndexOutOfBoundsException - if the index argument is negative or not less than length()

subSequence

public java.lang.CharSequence subSequence(java.util.Locale locale,
                                          int start,
                                          int end)
                                   throws java.lang.IndexOutOfBoundsException
Returns a new CharSequence that is a subsequence of this message rendered using a specific locale. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters:
locale - for which the rendering of this message will be used in determining the character
start - the start index, inclusive
end - the end index, exclusive
Returns:
the specified subsequence
Throws:
java.lang.IndexOutOfBoundsException - if start or end are negative, if end is greater than length(), or if start is greater than end

formatTo

public void formatTo(java.util.Formatter formatter,
                     int flags,
                     int width,
                     int precision)
              throws java.util.IllegalFormatException
Formats the object using the provided formatter.

Specified by:
formatTo in interface java.util.Formattable
Parameters:
formatter - The formatter.
flags - The flags modify the output format. The value is interpreted as a bitmask. Any combination of the following flags may be set: FormattableFlags.LEFT_JUSTIFY, FormattableFlags.UPPERCASE, and FormattableFlags.ALTERNATE. If no flags are set, the default formatting of the implementing class will apply.
width - The minimum number of characters to be written to the output. If the length of the converted value is less than the width then the output will be padded by '  ' until the total number of characters equals width. The padding is at the beginning by default. If the FormattableFlags.LEFT_JUSTIFY flag is set then the padding will be at the end. If width is -1 then there is no minimum.
precision - The maximum number of characters to be written to the output. The precision is applied before the width, thus the output will be truncated to precision characters even if the width is greater than the precision. If precision is -1 then there is no explicit limit on the number of characters.
Throws:
java.util.IllegalFormatException - If any of the parameters are invalid. For specification of all possible formatting errors, see the Details section of the formatter class specification.

compareTo

public int compareTo(Message o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable<Message>
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other message is "equal to" this one. Messages are considered equal if their string representation in the default locale are equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
hashCode(), Hashtable

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable