View Javadoc

1   /*
2   Karma CLI - Command Line Interface for 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.cli.cmd;
20  
21  import nl.toolforge.karma.console.KarmaConsole;
22  import nl.toolforge.karma.core.cmd.CommandResponseHandler;
23  import nl.toolforge.karma.core.cmd.event.CommandResponseEvent;
24  
25  /***
26   * This class is responsible for handling CommandResponses in an interactive way.
27   * Each time a CommandResponse changes, the changes are logged through the writer.
28   *
29   * @author W.H. Schraal
30   */
31  public class ConsoleCommandResponseHandler implements CommandResponseHandler {
32  
33    private KarmaConsole karmaConsole = null;
34  
35    /***
36     * Creates a handler. This one takes the KarmaConsole as an argument, to which is can write (event-) messages.
37     *
38     * @param karmaConsole A <code>KarmaConsole</code> instance.
39     */
40    public ConsoleCommandResponseHandler(KarmaConsole karmaConsole) {
41      this.karmaConsole = karmaConsole;
42    }
43  
44    /***
45     * Calls {@link #messageLogged}.
46     *
47     * @param event An event.
48     */
49    public void commandStarted(CommandResponseEvent event) {
50      this.messageLogged(event);
51    }
52  
53    /***
54     * Calls {@link #messageLogged}.
55     *
56     * @param event An event.
57     */
58    public void commandFinished(CommandResponseEvent event) {
59      this.messageLogged(event);
60    }
61  
62    /***
63     * Writes the events' message text to the KarmaConsole.
64     *
65     * @param event An event.
66     */
67    public void messageLogged(CommandResponseEvent event) {
68      karmaConsole.writeln(event.getEventMessage().getMessageText());
69    }
70  
71  
72  }