%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
nl.toolforge.karma.core.cmd.event.MessageEvent |
|
|
1 | /* |
|
2 | Karma core - Core of the Karma application |
|
3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, write to the Free Software |
|
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
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 | 0 | 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 | 0 | super(command, priority); |
41 | 0 | } |
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 | 0 | super(command, priority); |
52 | 0 | this.message = message; |
53 | 0 | } |
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 | 0 | super(command); |
62 | 0 | this.message = message; |
63 | 0 | } |
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 | 0 | super(null); |
72 | 0 | this.message = message; |
73 | 0 | } |
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 | 0 | if (getCommand() == null) { |
84 | 0 | return message; |
85 | } else { |
|
86 | 0 | return new SimpleMessage(MessageHelper.format(getCommand().getName(), message.getMessageText())); |
87 | } |
|
88 | } |
|
89 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |