KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > watchers > WatchersInformation


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.lib.cvsclient.command.watchers;
21
22 import java.io.*;
23 import java.util.*;
24
25 import org.netbeans.lib.cvsclient.command.*;
26 import org.netbeans.lib.cvsclient.util.*;
27
28 /**
29  * Describes "cvs watchers" commands' parsed information for a file.
30  * The fields in instances of this object are populated
31  * by response handlers.
32  *
33  * @author Milos Kleint
34  */

35 public class WatchersInformation extends FileInfoContainer {
36
37     public static final String JavaDoc WATCH_EDIT = "edit"; //NOI18N
38
public static final String JavaDoc WATCH_UNEDIT = "unedit"; //NOI18N
39
public static final String JavaDoc WATCH_COMMIT = "commit"; //NOI18N
40
public static final String JavaDoc WATCH_TEMP_EDIT = "tedit"; //NOI18N
41
public static final String JavaDoc WATCH_TEMP_UNEDIT = "tunedit"; //NOI18N
42
public static final String JavaDoc WATCH_TEMP_COMMIT = "tcommit"; //NOI18N
43

44     /**
45      * Holds the file that this info belongs to.
46      */

47     private final File file;
48
49     /**
50      * List of users (Watchers instances) that are listening
51      * on events for this file.
52      */

53     private final List userList = new LinkedList();
54
55     /**
56      * Creates new istance of the WatchersInformation class.
57      */

58     public WatchersInformation(File file) {
59         this.file = file;
60     }
61
62     /**
63      * Getter for file concerned in this instance.
64      */

65     public File getFile() {
66         return file;
67     }
68
69     /**
70      * Adds a watcher to the watchers list.
71      * @param watchingInfo a String that's first word is a user name and the
72      * rest are watching types.
73      */

74     void addWatcher(String JavaDoc watchingInfo) {
75         String JavaDoc temp = watchingInfo.trim();
76         temp = temp.replace('\t', ' ');
77         int spaceIndex = temp.indexOf(' ');
78         if (spaceIndex < 0) {
79             //BUGLOG assert.
80
}
81         else {
82             String JavaDoc user = temp.substring(0, spaceIndex);
83             String JavaDoc watches = temp.substring(spaceIndex + 1);
84             this.userList.add(new WatchersInformation.Watcher(user, watches));
85         }
86     }
87
88     /**
89      * Returns the Iterator with WatchersInformation.Watcher instances.
90      * Never returns null.
91      */

92     public Iterator getWatchersIterator() {
93         return this.userList.iterator();
94     }
95
96     /**
97      * Inner class that holds information about single user and his watches
98      * on the file.
99      */

100     public static class Watcher {
101
102         private final String JavaDoc userName;
103         private final String JavaDoc watches;
104         private boolean watchingEdit;
105         private boolean watchingUnedit;
106         private boolean watchingCommit;
107         private boolean temporaryEdit;
108         private boolean temporaryUnedit;
109         private boolean temporaryCommit;
110
111         /**
112          * Package private constuctor that creates a new instance of the Watcher.
113          * To Be called from outerclass only.
114          */

115         Watcher(String JavaDoc userName, String JavaDoc watches) {
116             this.userName = userName;
117             this.watches = watches;
118
119             final StringTokenizer tok = new StringTokenizer(watches, " ", false);
120             while (tok.hasMoreTokens()) {
121                 String JavaDoc token = tok.nextToken();
122                 if (WATCH_EDIT.equals(token)) {
123                     watchingEdit = true;
124                 }
125                 else if (WATCH_UNEDIT.equals(token)) {
126                     watchingUnedit = true;
127                 }
128                 else if (WATCH_COMMIT.equals(token)) {
129                     watchingCommit = true;
130                 }
131                 else if (WATCH_TEMP_COMMIT.equals(token)) {
132                     temporaryCommit = true;
133                 }
134                 else if (WATCH_TEMP_EDIT.equals(token)) {
135                     temporaryEdit = true;
136                 }
137                 else if (WATCH_TEMP_UNEDIT.equals(token)) {
138                     temporaryUnedit = true;
139                 }
140                 else {
141                     BugLog.getInstance().bug("unknown = " + token);
142                 }
143             }
144         }
145
146         /**
147          * Gets the user that is watching the file.
148          */

149         public String JavaDoc getUserName() {
150             return userName;
151         }
152
153         /**
154          * Returns all the watches defined on the file.
155          */

156         public String JavaDoc getWatches() {
157             return watches;
158         }
159
160         /**
161          * User is/isn't watching commit opration.
162          */

163         public boolean isWatchingCommit() {
164             return watchingCommit;
165         }
166
167         /**
168          * User is/isn't watching edit opration.
169          */

170         public boolean isWatchingEdit() {
171             return watchingEdit;
172         }
173
174         /**
175          * User is/isn't watching unedit opration.
176          */

177         public boolean isWatchingUnedit() {
178             return watchingUnedit;
179         }
180
181         /**
182          * User is/isn't temporary watching commit opration.
183          */

184         public boolean isTempWatchingCommit() {
185             return temporaryCommit;
186         }
187
188         /**
189          * User is/isn't temporary watching edit opration.
190          */

191         public boolean isTempWatchingEdit() {
192             return temporaryEdit;
193         }
194
195         /**
196          * User is/isn't temporary watching unedit opration.
197          */

198         public boolean isTempWatchingUnedit() {
199             return temporaryUnedit;
200         }
201     }
202 }
203
Popular Tags