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 nl.toolforge.karma.core.cmd.Command;
22
23 /***
24 * An event generated as a result of something ordinary. Commands can generate these events, but
25 *
26 * @author D.A. Smedes
27 * @version $Id: MessageEvent.java,v 1.3 2004/11/02 23:57:06 asmedes Exp $
28 */
29 public final class MessageEvent extends CommandResponseEvent {
30
31 private SimpleMessage message = null;
32
33 /***
34 * Creates a <code>MessageEvent</code> not linked to any command with a priority of <code>priority</code>.
35 *
36 * @param command The command generated this event.
37 * @param priority The priority of the event.
38 */
39 public MessageEvent(Command command, int priority) {
40 super(command, priority);
41 }
42
43 /***
44 * Creates the event for <code>command</code>.
45 *
46 * @param command The command generated this event.
47 * @param priority The priority of the event.
48 * @param message The message for the event.
49 */
50 public MessageEvent(Command command, int priority, SimpleMessage message) {
51 super(command, priority);
52 this.message = message;
53 }
54
55 /***
56 * Creates the event for <code>command</code>.
57 *
58 * @param command The command generated this event.
59 */
60 public MessageEvent(Command command, SimpleMessage message) {
61 super(command);
62 this.message = message;
63 }
64
65 /***
66 * Creates a <code>MessageEvent</code> not linked to any command.
67 *
68 * @param message Some message.
69 */
70 public MessageEvent(SimpleMessage message) {
71 super(null);
72 this.message = message;
73 }
74
75 /***
76 * Returns a <code>SimpleMessage</code> formatted as <code>[ <command-name> ] <message-text></code> if
77 * this message was constructed with a <code>Command</code> object, otherwise it returns the
78 * <code>SimpleMessgae</code> as-is.
79 *
80 * @return A <code>SimpleMessage</code> object optionally prefixed with the <code>Command</code> name.
81 */
82 public Message getEventMessage() {
83 if (getCommand() == null) {
84 return message;
85 } else {
86 return new SimpleMessage(MessageHelper.format(getCommand().getName(), message.getMessageText()));
87 }
88 }
89 }