KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import org.netbeans.lib.cvsclient.*;
27 import org.netbeans.lib.cvsclient.command.*;
28 import org.netbeans.lib.cvsclient.connection.*;
29 import org.netbeans.lib.cvsclient.event.*;
30 import org.netbeans.lib.cvsclient.request.*;
31
32 /**
33  * The status command looks up the status of files in the repository
34  * @author Robert Greig
35  */

36 public class StatusCommand extends BasicCommand {
37     /**
38      * The event manager to use
39      */

40     private EventManager eventManager;
41
42     /**
43      * Holds value of property includeTags.
44      */

45     private boolean includeTags;
46
47     /**
48      * Construct a new status command
49      */

50     public StatusCommand() {
51     }
52
53     /**
54      * Create a builder for this command.
55      * @param eventMan the event manager used to receive events.
56      */

57     public Builder createBuilder(EventManager eventManager) {
58         return new StatusBuilder(eventManager, this);
59     }
60
61     /**
62      * Execute a command
63      * @param client the client services object that provides any necessary
64      * services to this command, including the ability to actually process
65      * all the requests.
66      */

67     public void execute(ClientServices client, EventManager em)
68             throws CommandException, AuthenticationException {
69         client.ensureConnection();
70
71         eventManager = em;
72
73         super.execute(client, em);
74
75         try {
76             // parameters come now..
77
if (includeTags) {
78                 requests.add(1, new ArgumentRequest("-v")); //NOI18N
79
}
80
81             addRequestForWorkingDirectory(client);
82             addArgumentRequests();
83             addRequest(CommandRequest.STATUS);
84
85             client.processRequests(requests);
86         }
87         catch (CommandException ex) {
88             throw ex;
89         }
90         catch (Exception JavaDoc e) {
91             throw new CommandException(e, e.getLocalizedMessage());
92         }
93         finally {
94             requests.clear();
95         }
96     }
97
98     /**
99      * Getter for property includeTags.
100      * @return Value of property includeTags.
101      */

102     public boolean isIncludeTags() {
103         return includeTags;
104     }
105
106     /**
107      * Setter for property includeTags.
108      * @param includeTags New value of property includeTags.
109      */

110     public void setIncludeTags(boolean inclTags) {
111         includeTags = inclTags;
112     }
113
114     /**
115      * called when server responses with "ok" or "error", (when the command finishes)
116      */

117     public void commandTerminated(TerminationEvent e) {
118         if (builder != null) {
119             builder.outputDone();
120         }
121     }
122
123     /**
124      * This method returns how the command would looklike when typed on the command line.
125      * Each command is responsible for constructing this information.
126      * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
127      */

128     public String JavaDoc getCVSCommand() {
129         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("status "); //NOI18N
130
toReturn.append(getCVSArguments());
131         File[] files = getFiles();
132         if (files != null) {
133             for (int index = 0; index < files.length; index++) {
134                 toReturn.append(files[index].getName());
135                 toReturn.append(' ');
136             }
137         }
138         return toReturn.toString();
139     }
140
141     /**
142      * takes the arguments and sets the command. To be mainly
143      * used for automatic settings (like parsing the .cvsrc file)
144      * @return true if the option (switch) was recognized and set
145      */

146     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
147         if (opt == 'R') {
148             setRecursive(true);
149         }
150         else if (opt == 'l') {
151             setRecursive(false);
152         }
153         else if (opt == 'v') {
154             setIncludeTags(true);
155         }
156         else {
157             return false;
158         }
159         return true;
160     }
161
162     /**
163      * String returned by this method defines which options are available for this particular command
164      */

165     public String JavaDoc getOptString() {
166         return "Rlv"; //NOI18N
167
}
168
169     /**
170      * resets all switches in the command. After calling this method,
171      * the command should have no switches defined and should behave defaultly.
172      */

173     public void resetCVSCommand() {
174         setRecursive(true);
175         setIncludeTags(false);
176     }
177
178     /**
179      * Returns the arguments of the command in the command-line style.
180      * Similar to getCVSCommand() however without the files and command's name
181      */

182     public String JavaDoc getCVSArguments() {
183         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc(""); //NOI18N
184
if (isIncludeTags()) {
185             toReturn.append("-v "); //NOI18N
186
}
187         if (!isRecursive()) {
188             toReturn.append("-l "); //NOI18N
189
}
190         return toReturn.toString();
191     }
192
193 }
194
Popular Tags