KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > FileInformation


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 NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss;
21
22 import org.netbeans.lib.cvsclient.admin.Entry;
23 import org.openide.util.NbBundle;
24
25 import java.util.*;
26 import java.io.Serializable JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 /**
31  * Immutable class encapsulating status of a file.
32  *
33  * @author Maros Sandor
34  */

35 public class FileInformation implements Serializable JavaDoc {
36
37     private static final long serialVersionUID = 1L;
38
39     /**
40      * There is nothing known about the file, it may not even exist.
41      */

42     public static final int STATUS_UNKNOWN = 0;
43
44     /**
45      * The file is not managed by the module, i.e. the user does not wish it to be under control of this
46      * versioning system module. All files except files under versioned roots have this status.
47      */

48     public static final int STATUS_NOTVERSIONED_NOTMANAGED = 1;
49     
50     /**
51      * The file exists locally but is NOT under version control because it should not be (i.e. is listed
52      * in .cvsignore or resides under an excluded folder). The file itself IS under a versioned root.
53      */

54     public static final int STATUS_NOTVERSIONED_EXCLUDED = 2;
55
56     /**
57      * The file exists locally but is NOT under version control, mostly because it has not been added
58      * to the repository yet.
59      */

60     public static final int STATUS_NOTVERSIONED_NEWLOCALLY = 4;
61         
62     /**
63      * The file is under version control and is in sync with repository.
64      */

65     public static final int STATUS_VERSIONED_UPTODATE = 8;
66     
67     /**
68      * The file is modified locally and was not yet modified in repository.
69      */

70     public static final int STATUS_VERSIONED_MODIFIEDLOCALLY = 16;
71     
72     /**
73      * The file was not modified locally but an updated version exists in repository.
74      */

75     public static final int STATUS_VERSIONED_MODIFIEDINREPOSITORY = 32;
76     
77     /**
78      * Merging during update resulted in merge conflict. Conflicts in the local copy must be resolved before
79      * the file can be commited.
80      */

81     public static final int STATUS_VERSIONED_CONFLICT = 64;
82
83     /**
84      * The file was modified both locally and remotely and these changes may or may not result in
85      * merge conflict.
86      */

87     public static final int STATUS_VERSIONED_MERGE = 128;
88     
89     /**
90      * The file does NOT exist locally and exists in repository, it has beed removed locally, waits
91      * for commit.
92      */

93     public static final int STATUS_VERSIONED_REMOVEDLOCALLY = 256;
94     
95     /**
96      * The file does NOT exist locally but exists in repository and has not yet been downloaded.
97      */

98     public static final int STATUS_VERSIONED_NEWINREPOSITORY = 512;
99
100     /**
101      * The file has been removed from repository.
102      */

103     public static final int STATUS_VERSIONED_REMOVEDINREPOSITORY = 1024;
104
105     /**
106      * The file does NOT exist locally and exists in repository, it has beed removed locally.
107      */

108     public static final int STATUS_VERSIONED_DELETEDLOCALLY = 2048;
109     
110     /**
111      * The file exists locally and has beed scheduled for addition to repository. This status represents
112      * state after the CVS 'add' command.
113      */

114     public static final int STATUS_VERSIONED_ADDEDLOCALLY = 4096;
115
116     public static final int STATUS_ALL = ~0;
117
118     public static final int STATUS_MANAGED = STATUS_ALL & ~STATUS_NOTVERSIONED_NOTMANAGED;
119     
120     public static final int STATUS_IN_REPOSITORY = STATUS_VERSIONED_UPTODATE | STATUS_VERSIONED_MODIFIEDLOCALLY |
121             STATUS_VERSIONED_MODIFIEDINREPOSITORY | STATUS_VERSIONED_CONFLICT | STATUS_VERSIONED_MERGE |
122             STATUS_VERSIONED_REMOVEDLOCALLY | STATUS_VERSIONED_NEWINREPOSITORY | STATUS_VERSIONED_REMOVEDINREPOSITORY |
123             STATUS_VERSIONED_DELETEDLOCALLY;
124             
125     public static final int STATUS_LOCAL_CHANGE =
126             FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY |
127             FileInformation.STATUS_VERSIONED_ADDEDLOCALLY |
128             FileInformation.STATUS_VERSIONED_CONFLICT |
129             FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
130             FileInformation.STATUS_VERSIONED_MERGE |
131             FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
132             FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY;
133
134     public static final int STATUS_REMOTE_CHANGE =
135             FileInformation.STATUS_VERSIONED_MERGE |
136             FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY |
137             FileInformation.STATUS_VERSIONED_NEWINREPOSITORY |
138             FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY;
139     
140     
141     /**
142      * Status constant.
143      */

144     private final int status;
145
146     /**
147      * Directory indicator.
148      */

149     private final boolean isDirectory;
150     
151     /**
152      * Entry from the CVS directory, if it exists and has been read.
153      */

154     private transient Entry cvsEntry;
155
156     /**
157      * For deserialization purposes only.
158      */

159     public FileInformation() {
160         status = 0;
161         isDirectory = false;
162     }
163
164     FileInformation(int status, Entry cvsEntry, boolean isDirectory) {
165         this.status = status;
166         this.cvsEntry = cvsEntry;
167         this.isDirectory = isDirectory;
168     }
169
170     FileInformation(int status, boolean isDirectory) {
171         this(status, null, isDirectory);
172     }
173
174     /**
175      * Retrieves the status constant representing status of the file.
176      *
177      * @return one of status constants
178      */

179     public int getStatus() {
180         return status;
181     }
182
183     public boolean isDirectory() {
184         return isDirectory;
185     }
186
187     /**
188      * Retrieves file's CVS Entry.
189      *
190      * @param file file this information belongs to or null if you do not want the entry to be read from disk
191      * in case it is not loaded yet
192      * @return Entry parsed entry form the CVS/Entries file or null if the file does not exist,
193      * is not versioned or its Entry is invalid
194      */

195     public Entry getEntry(File JavaDoc file) {
196         if (cvsEntry == null && file != null) readEntry(file);
197         return cvsEntry;
198     }
199     
200     private void readEntry(File JavaDoc file) {
201         try {
202             cvsEntry = CvsVersioningSystem.getInstance().getAdminHandler().getEntry(file);
203         } catch (IOException JavaDoc e) {
204             // no entry for this file, ignore
205
}
206     }
207
208     /**
209      * Returns localized text representation of status.
210      *
211      * @return
212      */

213     public String JavaDoc getStatusText() {
214         ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
215         if (status == FileInformation.STATUS_UNKNOWN) {
216             return loc.getString("CTL_FileInfoStatus_Unknown");
217         } else if (status == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
218             return loc.getString("CTL_FileInfoStatus_Excluded");
219         } else if (status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) {
220             return loc.getString("CTL_FileInfoStatus_NewLocally");
221         } else if (status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY) {
222             return loc.getString("CTL_FileInfoStatus_AddedLocally");
223         } else if (status == FileInformation.STATUS_VERSIONED_UPTODATE) {
224             return loc.getString("CTL_FileInfoStatus_UpToDate");
225         } else if (status == FileInformation.STATUS_VERSIONED_NEWINREPOSITORY) {
226             return loc.getString("CTL_FileInfoStatus_NewInRepository");
227         } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
228             return loc.getString("CTL_FileInfoStatus_RemovedLocally");
229         } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY) {
230             return loc.getString("CTL_FileInfoStatus_DeletedLocally");
231         } else if (status == FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY) {
232             return loc.getString("CTL_FileInfoStatus_ModifiedLocally");
233         } else if (status == FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY) {
234             return loc.getString("CTL_FileInfoStatus_ModifiedInRepository");
235         } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY) {
236             return loc.getString("CTL_FileInfoStatus_RemovedInRepository");
237         } else if (status == FileInformation.STATUS_VERSIONED_CONFLICT) {
238             return loc.getString("CTL_FileInfoStatus_Conflict");
239         } else if (status == FileInformation.STATUS_VERSIONED_MERGE) {
240             return loc.getString("CTL_FileInfoStatus_Merge");
241         } else {
242             return ""; // NOI18N
243
}
244     }
245
246     public String JavaDoc getShortStatusText() {
247         ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
248         if (status == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
249             return loc.getString("CTL_FileInfoStatus_Excluded_Short");
250         } else if (status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) {
251             return loc.getString("CTL_FileInfoStatus_NewLocally_Short");
252         } else if (status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY) {
253             return loc.getString("CTL_FileInfoStatus_AddedLocally_Short");
254         } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
255             return loc.getString("CTL_FileInfoStatus_RemovedLocally_Short");
256         } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY) {
257             return loc.getString("CTL_FileInfoStatus_DeletedLocally_Short");
258         } else if (status == FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY) {
259             return loc.getString("CTL_FileInfoStatus_ModifiedLocally_Short");
260         } else if (status == FileInformation.STATUS_VERSIONED_CONFLICT) {
261             return loc.getString("CTL_FileInfoStatus_Conflict_Short");
262         } else if (status == FileInformation.STATUS_VERSIONED_MERGE) {
263             return loc.getString("CTL_FileInfoStatus_ModifiedLocally_Short");
264         } else {
265             return ""; // NOI18N
266
}
267     }
268 }
269
270
Popular Tags