|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opends.messages.MessageBuilder
@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayExtend=false, mayInvoke=true) public final class MessageBuilder
A builder used specifically for messages. As messages are appended they are translated to their string representation for storage using the locale specified in the constructor. Note that before you use this class you should consider whether it is appropriate. In general composing messages by appending message to each other may not produce a message that is formatted appropriately for all locales. It is usually better to create messages by composition. In other words you should create a base message that contains one or more string argument specifiers (%s) and define other message objects to use as replacement variables. In this way language translators have a change to reformat the message for a particular locale if necessary.
Constructor Summary | |
---|---|
MessageBuilder()
Constructs an instance that will build messages in the default locale. |
|
MessageBuilder(java.util.Locale locale)
Constructs an instance that will build messages in a specified locale. |
|
MessageBuilder(Message message)
Constructs an instance that will build messages in the default locale having an initial message. |
|
MessageBuilder(MessageBuilder mb)
Constructs an instance from another MessageBuilder . |
|
MessageBuilder(java.lang.String message)
Constructs an instance that will build messages in the default locale having an initial message. |
Method Summary | |
---|---|
MessageBuilder |
append(char c)
Appends the specified character to this Appendable. |
MessageBuilder |
append(java.lang.CharSequence cs)
Append a string to this builder. |
MessageBuilder |
append(java.lang.CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence to this Appendable. |
MessageBuilder |
append(int number)
Append an integer to this builder. |
MessageBuilder |
append(Message message)
Append a message to this builder. |
MessageBuilder |
append(java.lang.Object object)
Append an object to this builder. |
char |
charAt(int index)
Returns the char value at the specified index of
the string representation of this builder using the default locale. |
char |
charAt(java.util.Locale locale,
int index)
Returns the char value at the specified index of
the string representation of this builder using a specific locale. |
int |
length()
Returns the length of the string representation of this builder using the default locale. |
int |
length(java.util.Locale locale)
Returns the length of the string representation of this builder using a specific locale. |
java.lang.CharSequence |
subSequence(int start,
int end)
Returns a new CharSequence that is a subsequence of
the string representation of this builder 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
the string representation of this builder using a specific locale. |
Message |
toMessage()
Returns a raw message representation of the appended content. |
java.lang.String |
toString()
Returns a string containing the characters in this sequence in the same order as this sequence. |
java.lang.String |
toString(java.util.Locale locale)
Returns a string representation of the appended content in the specific locale. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MessageBuilder()
public MessageBuilder(Message message)
message
- initial messagepublic MessageBuilder(java.lang.String message)
message
- initial messagepublic MessageBuilder(MessageBuilder mb)
MessageBuilder
.
mb
- from which to construct a new message builderpublic MessageBuilder(java.util.Locale locale)
locale
- used for translating appended messagesMethod Detail |
---|
public MessageBuilder append(Message message)
message
- to be appended
public MessageBuilder append(int number)
number
- to append
public MessageBuilder append(java.lang.Object object)
object
- to append
public MessageBuilder append(java.lang.CharSequence cs)
append
in interface java.lang.Appendable
cs
- to append
public MessageBuilder append(java.lang.CharSequence csq, int start, int end) throws java.lang.IndexOutOfBoundsException
An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation
out.append(csq.subSequence(start, end))
append
in interface java.lang.Appendable
csq
- The character sequence from which a subsequence will be
appended. If csq is null, then characters
will be appended as if csq contained the four
characters "null".start
- The index of the first character in the subsequenceend
- The index of the character following the last character in the
subsequence
java.lang.IndexOutOfBoundsException
- If start or end are negative, start
is greater than end, or end is greater than
csq.length()public MessageBuilder append(char c)
append
in interface java.lang.Appendable
c
- The character to append
public java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public java.lang.String toString(java.util.Locale locale)
Message
s
appended to this builder are rendered in the requested
locale. Raw strings appended to this buffer are not
translated to different locale.
locale
- requested
public Message toMessage()
If the first object appended to this MessageBuilder
was a Message
then the returned message will
inherit its category and severity. Otherwise the returned message
will have category Category.USER_DEFINED
and severity Severity.INFORMATION
.
public int length()
length
in interface java.lang.CharSequence
char
s in this messagepublic char charAt(int index) throws java.lang.IndexOutOfBoundsException
char
value at the specified index of
the string representation of this builder using the default locale.
charAt
in interface java.lang.CharSequence
index
- the index of the char
value to be returned
char
value
java.lang.IndexOutOfBoundsException
- if the index argument is negative or not less than
length()public java.lang.CharSequence subSequence(int start, int end) throws java.lang.IndexOutOfBoundsException
CharSequence
that is a subsequence of
the string representation of this builder 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 char
s)
of the returned sequence is end - start, so if
start == end then an empty sequence is returned.
subSequence
in interface java.lang.CharSequence
start
- the start index, inclusiveend
- the end index, exclusive
java.lang.IndexOutOfBoundsException
- if start or end are negative,
if end is greater than length(),
or if start is greater than endpublic int length(java.util.Locale locale)
locale
- for which the rendering of this message will be
used in determining the length
char
s in this messagepublic char charAt(java.util.Locale locale, int index) throws java.lang.IndexOutOfBoundsException
char
value at the specified index of
the string representation of this builder using a specific locale.
locale
- for which the rendering of this message will be
used in determining the characterindex
- the index of the char
value to be returned
char
value
java.lang.IndexOutOfBoundsException
- if the index argument is negative or not less than
length()public java.lang.CharSequence subSequence(java.util.Locale locale, int start, int end) throws java.lang.IndexOutOfBoundsException
CharSequence
that is a subsequence of
the string representation of this builder 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 char
s)
of the returned sequence is end - start, so if
start == end then an empty sequence is returned.
locale
- for which the rendering of this message will be
used in determining the characterstart
- the start index, inclusiveend
- the end index, exclusive
java.lang.IndexOutOfBoundsException
- if start or end are negative,
if end is greater than length(),
or if start is greater than end
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |