Package eu.bandm.tools.message
Class MessageFormatter<D>
- Type Parameters:
D
- the type of the document id
- All Implemented Interfaces:
MessageReceiver<SimpleMessage<D>>
Inserts the arguments into the message text, similar to the Java standard
string formatter.
In principle, the insertion happens by
Formatter.format(String, Object...)
.
But before, all arguments of type PreMessage
are
replaced by the string result of formatting them, recursively.
For each received message a new message is constructed with all
fields the same, but with the formatted text, and sent to the
receiver.
The flag stripArgs
decides whether to keep the top-level
arguments of the message,
even though their textual representation is now present in the
generated text.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Whether the args are only entered to formatting, but not propagated.Fields inherited from class eu.bandm.tools.message.SingleSender
drain
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor with no receiver.MessageFormatter
(MessageReceiver<? super SimpleMessage<D>> rec) Constructor with the given receiver. -
Method Summary
Modifier and TypeMethodDescriptionprocess
(PreMessage embed) Service access point to apply the text as a format to the arguments.Service access point to apply the text as a format to the arguments.void
receive
(SimpleMessage<D> m) Applies the message text as a format to the arguments and propagates the new message to the current drain.render
(SimpleMessage<?> msg) Service access point to apply the text as a format to the arguments.setStripArgs
(boolean b) Set whether the arguments shall not be included in the formatted method.Methods inherited from class eu.bandm.tools.message.SingleSender
getDrain, getReceiver, send, setDrain, setReceiver
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
stripArgs
protected boolean stripArgsWhether the args are only entered to formatting, but not propagated. Initially true.
-
-
Constructor Details
-
MessageFormatter
public MessageFormatter()Constructor with no receiver. The receiver must be set before sending messages to it. -
MessageFormatter
Constructor with the given receiver.- Parameters:
rec
- the receiver to which the formatted messages will be sent.
-
-
Method Details
-
setStripArgs
Set whether the arguments shall not be included in the formatted method. They are represented in the text of the formatted method anyhow.- Parameters:
b
- whether to strip the arguments.- Returns:
- this instance, for method chaining.
-
receive
Applies the message text as a format to the arguments and propagates the new message to the current drain.- Specified by:
receive
in interfaceMessageReceiver<D>
- Overrides:
receive
in classMessagePasser<SimpleMessage<D>>
- Parameters:
m
- the message to receive.- See Also:
-
render
Service access point to apply the text as a format to the arguments.String.format(String,Object...)
is called in any case, also with empty arg list, for format codes like "%n
". AnyPreMessage
contained in the arguments is formatted recursively.Any formatting which fails returns for diagnosis the concatenation of the text, an error text and the
Object.toString()
results of the arguments.- Parameters:
msg
- the message to be rendered- Returns:
- a string representation of the message text and the rendered arguments
-
process
Service access point to apply the text as a format to the arguments.- Parameters:
embed
- text and arguments to be rendered- Returns:
- a string representation of the message text and the rendered arguments
- See Also:
-
process
Service access point to apply the text as a format to the arguments.String.format(String,Object...)
is called in any case, also with empty arg list, for format codes like "%n
". AnyPreMessage
contained in the arguments is formatted recursively.Any formatting which fails returns for diagnosis the concatenation of the text, an error text and the
Object.toString()
results of the arguments.- Parameters:
text
- the format text to be renderedargs
- the arguments to be rendered- Returns:
- a string representation of the message text and the rendered
arguments, or
null
iff the text input isnull
.
-