1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.event;
20
21 import java.text.MessageFormat;
22
23 /***
24 * Base implementation of a {@link Message}. Provides standard implementations for methods handling messages.
25 *
26 * @author D.A. Smedes
27 * @version $Id: AbstractMessage.java,v 1.2 2004/11/02 23:57:06 asmedes Exp $
28 */
29 public class AbstractMessage implements Message {
30
31 private String message = null;
32
33 public AbstractMessage(String message) {
34 this.message = message;
35 }
36
37 /***
38 * Constructs a message. {@link java.text.MessageFormat} is used to convert parameters in the <code>message</code>
39 * text.
40 *
41 * @param message The message string (with optional parameters).
42 * @param messageParameters An object array with parameter values.
43 */
44 public AbstractMessage(String message, Object[] messageParameters) {
45
46 if (messageParameters != null && messageParameters.length != 0) {
47 MessageFormat messageFormat = new MessageFormat(message);
48 this.message = messageFormat.format(messageParameters);
49 } else {
50 this.message = message;
51 }
52 }
53
54 /***
55 * Returns the message as a String, having replaced all parameters with the actual content.
56 *
57 * @return The message text.
58 */
59 public String getMessageText() {
60 return message;
61 }
62
63 }