KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.lib.cvsclient.command.watchers;
20
21 import java.io.*;
22
23 import org.netbeans.lib.cvsclient.*;
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.connection.*;
26 import org.netbeans.lib.cvsclient.event.*;
27 import org.netbeans.lib.cvsclient.request.*;
28
29 /**
30  * The watchers command looks up who is watching this file,
31  * who is interested in it.
32  *
33  * @author Milos Kleint
34  * @author Thomas Singer
35  */

36 public class WatchersCommand extends BasicCommand {
37     /**
38      * Construct a new watchers command.
39      */

40     public WatchersCommand() {
41         resetCVSCommand();
42     }
43
44     /**
45      * Creates and returns the WatchersBuilder.
46      *
47      * @param eventMan the event manager used to receive events.
48      */

49     public Builder createBuilder(EventManager eventManager) {
50         return new WatchersBuilder(eventManager, getLocalDirectory());
51     }
52
53     /**
54      * Executes this command.
55      *
56      * @param client the client services object that provides any necessary
57      * services to this command, including the ability to actually
58      * process all the requests
59      */

60     public void execute(ClientServices client, EventManager eventManager)
61             throws CommandException, AuthenticationException {
62         client.ensureConnection();
63
64         super.execute(client, eventManager);
65
66         try {
67             addRequestForWorkingDirectory(client);
68             addArgumentRequests();
69             addRequest(CommandRequest.WATCHERS);
70
71             client.processRequests(requests);
72         }
73         catch (CommandException ex) {
74             throw ex;
75         }
76         catch (Exception JavaDoc ex) {
77             throw new CommandException(ex, ex.getLocalizedMessage());
78         }
79         finally {
80             requests.clear();
81         }
82     }
83
84     /**
85      * called when server responses with "ok" or "error", (when the command finishes)
86      */

87     public void commandTerminated(TerminationEvent e) {
88         if (builder != null) {
89             builder.outputDone();
90         }
91     }
92
93     /**
94      * This method returns how the command would looklike when typed on the command line.
95      * Each command is responsible for constructing this information.
96      * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
97      */

98     public String JavaDoc getCVSCommand() {
99         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("watchers "); //NOI18N
100
toReturn.append(getCVSArguments());
101         File[] files = getFiles();
102         if (files != null) {
103             for (int index = 0; index < files.length; index++) {
104                 toReturn.append(files[index].getName());
105                 toReturn.append(' ');
106             }
107         }
108         return toReturn.toString();
109     }
110
111     /**
112      * takes the arguments and sets the command. To be mainly
113      * used for automatic settings (like parsing the .cvsrc file)
114      * @return true if the option (switch) was recognized and set
115      */

116     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
117         if (opt == 'R') {
118             setRecursive(true);
119         }
120         else if (opt == 'l') {
121             setRecursive(false);
122         }
123         else {
124             return false;
125         }
126         return true;
127     }
128
129     /**
130      * String returned by this method defines which options are available for this particular command
131      */

132     public String JavaDoc getOptString() {
133         return "Rl"; //NOI18N
134
}
135
136     /**
137      * resets all switches in the command. After calling this method,
138      * the command should have no switches defined and should behave defaultly.
139      */

140     public void resetCVSCommand() {
141         setRecursive(true);
142     }
143
144     /**
145      * Returns the arguments of the command in the command-line style.
146      * Similar to getCVSCommand() however without the files and command's name
147      */

148     public String JavaDoc getCVSArguments() {
149         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc();
150         if (!isRecursive()) {
151             toReturn.append("-l "); //NOI18N
152
}
153         return toReturn.toString();
154     }
155 }
156
Popular Tags