KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > event > MessageEvent


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.event;
23
24 /**
25  * An event sent from the server to indicate that a message should be
26  * displayed to the user
27  * @author Robert Greig
28  */

29 public class MessageEvent extends CVSEvent {
30     /**
31      * Holds value of property message.
32      */

33     private String JavaDoc message;
34
35     /**
36      * Whether the message is an error message
37      */

38     private boolean error;
39
40     /** Holds value of property tagged. */
41     private boolean tagged;
42
43     private final byte[] raw;
44
45
46     public MessageEvent(Object JavaDoc source, String JavaDoc message, byte[] raw, boolean isError) {
47         super(source);
48         setMessage(message);
49         setError(isError);
50         setTagged(false);
51         this.raw = raw;
52     }
53
54     /**
55      * Construct a MessageEvent
56      * @param source the source of the event
57      * @param message the message text
58      * @param isError true if the message is an error message (i.e. intended
59      * for stderr rather than stdout), false otherwise
60      */

61     public MessageEvent(Object JavaDoc source, String JavaDoc message, boolean isError) {
62         this(source, message, null, isError);
63     }
64
65     /**
66      * Construct a MessageEvent with no message text
67      * @param source the source of the event
68      */

69     public MessageEvent(Object JavaDoc source) {
70         this(source, null, false);
71     }
72
73     /**
74      * Getter for property message.
75      * @return Value of property message.
76      */

77     public String JavaDoc getMessage() {
78         return message;
79     }
80
81     /** @return bytes from wire or null */
82     public byte[] getRawData() {
83         return raw;
84     }
85
86     /**
87      * Setter for property message.
88      * @param message New value of property message.
89      */

90     public void setMessage(String JavaDoc message) {
91         this.message = message;
92     }
93
94     /**
95      * Get whether the message should be displayed in stderr
96      * @return true if the message should be sent to stderr, false otherwise
97      */

98     public boolean isError() {
99         return error;
100     }
101
102     /**
103      * Set whether the message should go to stderr
104      * @param error true if the message is an error message, false otherwise
105      */

106     public void setError(boolean error) {
107         this.error = error;
108     }
109
110     /**
111      * Fire the event to the event listener. Subclasses should call the
112      * appropriate method on the listener to dispatch this event.
113      * @param listener the event listener
114      */

115     protected void fireEvent(CVSListener listener) {
116         listener.messageSent(this);
117     }
118
119     /** Getter for property tagged.
120      * @return Value of property tagged.
121      */

122     public boolean isTagged() {
123         return tagged;
124     }
125
126     /** Setter for property tagged.
127      * @param tagged New value of property tagged.
128      */

129     public void setTagged(boolean tagged) {
130         this.tagged = tagged;
131     }
132
133     /**
134      * Parses the tagged message using the specified buffer.
135      * @returns != null, if the line is finished and could be processed
136      */

137     public static String JavaDoc parseTaggedMessage(StringBuffer JavaDoc taggedLineBufferNotNull, String JavaDoc taggedMessage) {
138         String JavaDoc line = taggedMessage;
139
140         if (line.charAt(0) == '+' || line.charAt(0) == '-') {
141             return null;
142         }
143
144         String JavaDoc result = null;
145         if (line.equals("newline")) {//NOI18N
146
result = taggedLineBufferNotNull.toString();
147             taggedLineBufferNotNull.setLength(0);
148         }
149         int index = line.indexOf(' ');
150         if (index > 0) {
151             taggedLineBufferNotNull.append(line.substring(index + 1));
152         }
153         return result;
154     }
155 }
Popular Tags