public class MessageBuilder
extends java.lang.Object
MessageResolver
objects programmatically. Often used by model code such as
validation logic to conveniently record validation messages. Supports the production of message resolvers that
hard-code their message text, as well as message resolvers that retrieve their text from a message resource bundle
.
Usage example:
new MessageBuilder().error().source("field").code("mycode").arg(arg1).arg(arg2).defaultText("text").build();
Constructor and Description |
---|
MessageBuilder() |
Modifier and Type | Method and Description |
---|---|
MessageBuilder |
arg(java.lang.Object arg)
Records that the message being built has a variable argument.
|
MessageBuilder |
args(java.lang.Object[] args)
Records that the message being built has variable arguments.
|
MessageResolver |
build()
Builds the message that will be resolved.
|
MessageBuilder |
code(java.lang.String code)
Records that the message being built should try and resolve its text using the code provided.
|
MessageBuilder |
codes(java.lang.String[] codes)
Records that the message being built should try and resolve its text using the codes provided.
|
MessageBuilder |
defaultText(java.lang.String text)
Records the fallback text of the message being built.
|
MessageBuilder |
error()
Records that the message being built is an error message.
|
MessageBuilder |
fatal()
Records that the message being built is a fatal message.
|
MessageBuilder |
info()
Records that the message being built is an informational message.
|
MessageBuilder |
resolvableArg(java.lang.Object arg)
Records that the message being built has a variable argument, whose display value is also
MessageSourceResolvable . |
MessageBuilder |
resolvableArgs(java.lang.Object[] args)
Records that the message being built has variable arguments, whose display values are also
MessageSourceResolvable instances. |
MessageBuilder |
source(java.lang.Object source)
Records that the message being built is against the provided source.
|
MessageBuilder |
warning()
Records that the message being built is a warning message.
|
public MessageBuilder info()
public MessageBuilder warning()
public MessageBuilder error()
public MessageBuilder fatal()
public MessageBuilder source(java.lang.Object source)
source
- the source to associate the message withpublic MessageBuilder code(java.lang.String code)
code
- the message codepublic MessageBuilder codes(java.lang.String[] codes)
codes
- the message codes; if null, no changes will be madepublic MessageBuilder arg(java.lang.Object arg)
arg
- the message argument valuepublic MessageBuilder args(java.lang.Object[] args)
args
- the message argument values, if null no changes will be madepublic MessageBuilder resolvableArg(java.lang.Object arg)
MessageSourceResolvable
. Adds the arg to the args list. Successive calls to this method add additional
resolvable args. Args are applied in the order they are added.arg
- the resolvable message argumentpublic MessageBuilder resolvableArgs(java.lang.Object[] args)
MessageSourceResolvable
instances. Adds the args to the args list. Successive calls to this method add
additional resolvable args. Args are applied in the order they are added.args
- the resolvable message argumentspublic MessageBuilder defaultText(java.lang.String text)
text
- the default textpublic MessageResolver build()