KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > status > StatusInformation


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.command.status;
23
24 import java.io.*;
25 import java.util.*;
26
27 import org.netbeans.lib.cvsclient.command.*;
28 import org.netbeans.lib.cvsclient.file.*;
29
30 /**
31  * Describes status information for a file. This is the result of doing a
32  * cvs status command. The fields in instances of this object are populated
33  * by response handlers.
34  * @author Robert Greig
35  */

36 public class StatusInformation extends FileInfoContainer {
37     // Fields =================================================================
38

39     private File file;
40     private FileStatus status;
41     private String JavaDoc workingRevision;
42     private String JavaDoc repositoryRevision;
43     private String JavaDoc repositoryFileName;
44     private String JavaDoc stickyDate;
45     private String JavaDoc stickyOptions;
46     private String JavaDoc stickyTag;
47
48     /**
49      * Hold key pairs of existing tags.
50      */

51     private List tags;
52
53     private StringBuffer JavaDoc symNamesBuffer;
54
55     public StatusInformation() {
56         setAllExistingTags(null);
57     }
58
59     /**
60      * Getter for property file.
61      * @return Value of property file.
62      */

63     public File getFile() {
64         return file;
65     }
66
67     /**
68      * Setter for property file.
69      * @param file New value of property file.
70      */

71     public void setFile(File file) {
72         this.file = file;
73     }
74
75     /**
76      * Getter for property status.
77      * @return Value of property status.
78      */

79     public FileStatus getStatus() {
80         return status;
81     }
82
83     /**
84      * Setter for property status.
85      * @param status New value of property status.
86      */

87     public void setStatus(FileStatus status) {
88         this.status = status;
89     }
90
91     /**
92      * Returns the status as a String.
93      * The String returned are definitely the static-final-instances.
94      */

95     public String JavaDoc getStatusString() {
96         if (status == null) {
97             return null;
98         }
99
100         return status.toString();
101     }
102
103     /**
104      * Sets the status by the specified string.
105      */

106     public void setStatusString(String JavaDoc statusString) {
107         setStatus(FileStatus.getStatusForString(statusString));
108     }
109
110     /**
111      * Getter for property workingRevision.
112      * @return Value of property workingRevision.
113      */

114     public String JavaDoc getWorkingRevision() {
115         return workingRevision;
116     }
117
118     /**
119      * Setter for property workingRevision.
120      * @param workingRevision New value of property workingRevision.
121      */

122     public void setWorkingRevision(String JavaDoc workingRevision) {
123         this.workingRevision = workingRevision;
124     }
125
126     /**
127      * Getter for property repositoryRevision.
128      * @return Value of property repositoryRevision.
129      */

130     public String JavaDoc getRepositoryRevision() {
131         return repositoryRevision;
132     }
133
134     /**
135      * Setter for property repositoryRevision.
136      * @param repositoryRevision New value of property repositoryRevision.
137      */

138     public void setRepositoryRevision(String JavaDoc repositoryRevision) {
139         this.repositoryRevision = repositoryRevision;
140     }
141
142     /**
143      * Getter for property repositoryFileName.
144      * @return Value of property repositoryFileName.
145      */

146     public String JavaDoc getRepositoryFileName() {
147         return repositoryFileName;
148     }
149
150     /**
151      * Setter for property repositoryFileName.
152      * @param repositoryRevision New value of property repositoryFileName.
153      */

154     public void setRepositoryFileName(String JavaDoc repositoryFileName) {
155         this.repositoryFileName = repositoryFileName;
156     }
157
158     /**
159      * Getter for property stickyTag.
160      * @return Value of property stickyTag.
161      */

162     public String JavaDoc getStickyTag() {
163         return stickyTag;
164     }
165
166     /**
167      * Setter for property stickyTag.
168      * @param stickyTag New value of property stickyTag.
169      */

170     public void setStickyTag(String JavaDoc stickyTag) {
171         this.stickyTag = stickyTag;
172     }
173
174     /**
175      * Getter for property stickyDate.
176      * @return Value of property stickyDate.
177      */

178     public String JavaDoc getStickyDate() {
179         return stickyDate;
180     }
181
182     /**
183      * Setter for property stickyDate.
184      * @param stickyDate New value of property stickyDate.
185      */

186     public void setStickyDate(String JavaDoc stickyDate) {
187         this.stickyDate = stickyDate;
188     }
189
190     /**
191      * Getter for property stickyOptions.
192      * @return Value of property stickyOptions.
193      */

194     public String JavaDoc getStickyOptions() {
195         return stickyOptions;
196     }
197
198     /**
199      * Setter for property stickyOptions.
200      * @param stickyOptions New value of property stickyOptions.
201      */

202     public void setStickyOptions(String JavaDoc stickyOptions) {
203         this.stickyOptions = stickyOptions;
204     }
205
206     public void addExistingTag(String JavaDoc tagName, String JavaDoc revisionNumber) {
207         if (symNamesBuffer == null) {
208             symNamesBuffer = new StringBuffer JavaDoc();
209         }
210         symNamesBuffer.append(tagName);
211         symNamesBuffer.append(" "); //NOI18N
212
symNamesBuffer.append(revisionNumber);
213         symNamesBuffer.append("\n"); //NOI18N
214
}
215
216     private void createSymNames() {
217         tags = new LinkedList();
218
219         if (symNamesBuffer == null) {
220             return;
221         }
222
223         int length = 0;
224         int lastLength = 0;
225         while (length < symNamesBuffer.length()) {
226             while (length < symNamesBuffer.length() && symNamesBuffer.charAt(length) != '\n') {
227                 length++;
228             }
229
230             if (length > lastLength) {
231                 String JavaDoc line = symNamesBuffer.substring(lastLength, length);
232                 String JavaDoc symName = line.substring(0, line.indexOf(' '));
233                 String JavaDoc revisionNumber = line.substring(line.indexOf(' ') + 1);
234                 SymName newName = new SymName();
235                 newName.setTag(symName);
236                 newName.setRevision(revisionNumber);
237                 tags.add(newName);
238                 lastLength = length + 1;
239                 length++;
240             }
241         }
242
243         symNamesBuffer = null;
244     }
245
246     public List getAllExistingTags() {
247         if (tags == null) {
248             createSymNames();
249         }
250         return tags;
251     }
252
253     public void setAllExistingTags(List tags) {
254         this.tags = tags;
255     }
256
257     /** Search the symbolic names by number of revision. If not found, return null.
258      */

259     public List getSymNamesForRevision(String JavaDoc revNumber) {
260         if (tags == null) {
261             createSymNames();
262         }
263
264         List list = new LinkedList();
265
266         for (Iterator it = tags.iterator(); it.hasNext();) {
267             StatusInformation.SymName item = (StatusInformation.SymName)it.next();
268             if (item.getRevision().equals(revNumber)) {
269                 list.add(item);
270             }
271         }
272         return list;
273     }
274
275     /**
276      * Search the symbolic names by name of tag (symbolic name).
277      * If not found, return null.
278      */

279     public StatusInformation.SymName getSymNameForTag(String JavaDoc tagName) {
280         if (tags == null) {
281             createSymNames();
282         }
283
284         for (Iterator it = tags.iterator(); it.hasNext();) {
285             StatusInformation.SymName item = (StatusInformation.SymName)it.next();
286             if (item.getTag().equals(tagName)) {
287                 return item;
288             }
289         }
290         return null;
291     }
292
293     /**
294      * Return a string representation of this object. Useful for debugging.
295      */

296     public String JavaDoc toString() {
297         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
298         buf.append("\nFile: "); //NOI18N
299
buf.append((file != null) ? file.getAbsolutePath()
300                    : "null"); //NOI18N
301
buf.append("\nStatus is: "); //NOI18N
302
buf.append(getStatusString());
303         buf.append("\nWorking revision: "); //NOI18N
304
buf.append(workingRevision);
305         buf.append("\nRepository revision: "); //NOI18N
306
buf.append("\nSticky date: "); //NOI18N
307
buf.append(stickyDate);
308         buf.append("\nSticky options: "); //NOI18N
309
buf.append(stickyOptions);
310         buf.append("\nSticky tag: "); //NOI18N
311
buf.append(stickyTag);
312         if (tags != null && tags.size() > 0) {
313             // we are having some tags to print
314
buf.append("\nExisting Tags:"); //NOI18N
315
for (Iterator it = tags.iterator(); it.hasNext();) {
316                 buf.append("\n "); //NOI18N
317
buf.append(it.next().toString());
318             }
319         }
320         return buf.toString();
321     }
322
323     /**
324      * An inner class storing information about a symbolic name.
325      * Consists of a pair of Strings. tag + revision.
326      */

327     public static class SymName {
328         private String JavaDoc tag;
329         private String JavaDoc revision;
330
331         public SymName() {
332         }
333
334         public String JavaDoc getTag() {
335             return tag;
336         }
337
338         public void setTag(String JavaDoc symName) {
339             tag = symName;
340         }
341
342         public void setRevision(String JavaDoc rev) {
343             revision = rev;
344         }
345
346         public String JavaDoc getRevision() {
347             return revision;
348         }
349
350         public String JavaDoc toString() {
351             return getTag() + " : " + getRevision(); //NOI18N
352
}
353     }
354 }
355
Popular Tags