| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| nl.toolforge.karma.core.cmd.event.SimpleMessage |
|
|
| 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 java.text.MessageFormat; |
|
| 22 | ||
| 23 | ||
| 24 | /** |
|
| 25 | * @author D.A. Smedes |
|
| 26 | * @version $Id: SimpleMessage.java,v 1.2 2004/10/26 22:47:59 hippe Exp $ |
|
| 27 | */ |
|
| 28 | public class SimpleMessage implements Message { |
|
| 29 | ||
| 30 | 0 | private String message = null; |
| 31 | 0 | private Object[] messageArguments = new Object[0]; |
| 32 | ||
| 33 | /** |
|
| 34 | * Constructs a <code>CommandMessage</code> with a (simple) text message. |
|
| 35 | * |
|
| 36 | * @param message The message text for the <code>CommandMessage</code>. |
|
| 37 | */ |
|
| 38 | public SimpleMessage(String message) { |
|
| 39 | 0 | this(message, null); |
| 40 | 0 | } |
| 41 | ||
| 42 | /** |
|
| 43 | * Constructs a <code>CommandMessage</code> with a (simple) text message and message parameters as per the |
|
| 44 | * <code>java.text.MessageFormat</code> manner. |
|
| 45 | * |
|
| 46 | * @param message The message text for the <code>CommandMessage</code>. |
|
| 47 | */ |
|
| 48 | 0 | public SimpleMessage(String message, Object[] messageArguments) { |
| 49 | ||
| 50 | 0 | if (message == null) { |
| 51 | 0 | throw new IllegalArgumentException("Message cannot be null."); |
| 52 | } |
|
| 53 | ||
| 54 | 0 | this.message = message; |
| 55 | 0 | this.messageArguments = messageArguments; |
| 56 | 0 | } |
| 57 | ||
| 58 | /** |
|
| 59 | * The text message for this <code>CommandMessage</code>, with |
|
| 60 | * |
|
| 61 | * @return The text message for this <code>CommandMessage</code>. |
|
| 62 | */ |
|
| 63 | public String getMessageText() { |
|
| 64 | ||
| 65 | 0 | if (messageArguments != null && messageArguments.length != 0) { |
| 66 | 0 | MessageFormat messageFormat = new MessageFormat(message); |
| 67 | 0 | message = messageFormat.format(messageArguments); |
| 68 | } |
|
| 69 | 0 | return message; |
| 70 | } |
|
| 71 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |