KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > commandLine > BasicListener


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Robert Greig.
17  * Portions created by Robert Greig are Copyright (C) 2000.
18  * All Rights Reserved.
19
20  * Contributor(s): Robert Greig.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.commandLine;
23
24 import java.io.*;
25
26 import org.netbeans.lib.cvsclient.command.*;
27 import org.netbeans.lib.cvsclient.event.*;
28
29 /**
30  * A basic implementation of a CVS listener. Is really only interested in
31  * message events. This listener is suitable for command line clients and
32  * clients that don't "persist".
33  * @author Robert Greig
34  */

35 public class BasicListener extends CVSAdapter {
36     private final StringBuffer JavaDoc taggedLine = new StringBuffer JavaDoc();
37     private PrintStream stdout;
38     private PrintStream stderr;
39     
40     public BasicListener() {
41         this(System.out, System.err);
42     }
43     
44     public BasicListener(PrintStream stdout, PrintStream stderr) {
45         this.stdout = stdout;
46         this.stderr = stderr;
47     }
48
49     /**
50      * Called when the server wants to send a message to be displayed to
51      * the user. The message is only for information purposes and clients
52      * can choose to ignore these messages if they wish.
53      * @param e the event
54      */

55     public void messageSent(MessageEvent e) {
56         String JavaDoc line = e.getMessage();
57         if (e instanceof EnhancedMessageEvent) {
58             return ;
59         }
60         PrintStream stream = e.isError() ? stderr : stdout;
61
62         if (e.isTagged()) {
63             String JavaDoc message = MessageEvent.parseTaggedMessage(taggedLine, e.getMessage());
64             if (message != null) {
65                 stream.println(message);
66             }
67         }
68         else {
69             stream.println(line);
70         }
71     }
72
73     /**
74      * Called when the server wants to send a binary message to be displayed to
75      * the user. The message is only for information purposes and clients
76      * can choose to ignore these messages if they wish.
77      * @param e the event
78      */

79     public void messageSent(BinaryMessageEvent e) {
80         byte[] bytes = e.getMessage();
81         int len = e.getMessageLength();
82         stdout.write(bytes, 0, len);
83     }
84
85     /**
86      * Called when file status information has been received
87      */

88     public void fileInfoGenerated(FileInfoEvent e) {
89 // FileInfoContainer fileInfo = e.getInfoContainer();
90
// if (fileInfo.getClass().equals(StatusInformation.class)) {
91
// System.err.println("A file status event was received.");
92
// System.err.println("The status information object is: " +
93
// fileInfo);
94
// }
95
}
96 }
Popular Tags