KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > response > MessageResponse


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.response;
23
24 import java.io.*;
25
26 import org.netbeans.lib.cvsclient.event.*;
27 import org.netbeans.lib.cvsclient.util.*;
28
29 /**
30  * Handles standard message responses
31  * @author Robert Greig
32  */

33 class MessageResponse implements Response {
34
35     private boolean terminating = false;
36
37     private String JavaDoc firstWord;
38
39     public MessageResponse() {
40         // do nothing
41
}
42     
43     public MessageResponse(String JavaDoc initialWord) {
44         firstWord = initialWord;
45     }
46     
47     /**
48      * Process the data for the response.
49      * @param dis the data inputstream allowing the client to read the server's
50      * response. Note that the actual response name has already been read
51      * and the inputstream is positioned just before the first argument, if any.
52      */

53     public void process(LoggedDataInputStream dis, ResponseServices services)
54             throws ResponseException {
55         try {
56             ByteArray bytes = dis.readLineBytes();
57             String JavaDoc line = bytes.getStringFromBytes();
58             if (firstWord != null) {
59                 line = firstWord + " " + line; //NOI18N
60
}
61             terminating |= line.endsWith(SpecialResponses.SERVER_ABORTED);
62             terminating |= line.endsWith(SpecialResponses.SERVER_ABORTED_2);
63             terminating |= line.endsWith(SpecialResponses.SERVER_ABORTED_3);
64             terminating &= dis.available() == 0; // heuristics to relax SpecialResponses in commit messages...
65
MessageEvent event = new MessageEvent(this, line, bytes.getBytes(), false);
66             services.getEventManager().fireCVSEvent(event);
67         }
68         catch (EOFException ex) {
69             throw new ResponseException(ex, ResponseException.getLocalMessage("CommandException.EndOfFile", null)); //NOI18N
70
}
71         catch (IOException ex) {
72             throw new ResponseException(ex);
73         }
74     }
75
76     /**
77      * Is this a terminal response, i.e. should reading of responses stop
78      * after this response. This is true for responses such as OK or
79      * an error response
80      * <p>
81      * @see SpecialResponses.SERVER_ABORTED
82      */

83     public boolean isTerminalResponse() {
84         return terminating;
85     }
86 }
Popular Tags