1 19 package org.netbeans.lib.cvsclient.command.watch; 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 import org.netbeans.lib.cvsclient.util.*; 29 30 33 public class WatchCommand extends BasicCommand { 34 private WatchMode watchMode; 35 36 private Watch watch; 37 38 41 public WatchCommand() { 42 resetCVSCommand(); 43 } 44 45 57 public void execute(ClientServices client, EventManager eventManager) 58 throws CommandException, AuthenticationException { 59 checkState(); 60 61 client.ensureConnection(); 62 63 try { 64 super.execute(client, eventManager); 65 66 if (getWatchMode().isWatchOptionAllowed()) { 67 String [] arguments = getWatchNotNull().getArguments(); 68 for (int i = 0; i < arguments.length; i++) { 69 addRequest(new ArgumentRequest("-a")); addRequest(new ArgumentRequest(arguments[i])); 71 } 72 } 73 74 addRequestForWorkingDirectory(client); 75 addArgumentRequests(); 76 addRequest(getWatchMode().getCommand()); 77 78 client.processRequests(requests); 79 } 80 catch (CommandException ex) { 81 throw ex; 82 } 83 catch (Exception ex) { 84 throw new CommandException(ex, ex.getLocalizedMessage()); 85 } 86 finally { 87 requests.clear(); 88 } 89 } 90 91 96 public void commandTerminated(TerminationEvent e) { 97 if (builder != null) { 98 builder.outputDone(); 99 } 100 } 101 102 108 public boolean setCVSCommand(char opt, String optArg) { 109 if (opt == 'R') { 110 setRecursive(true); 111 } 112 else if (opt == 'l') { 113 setRecursive(false); 114 } 115 else { 116 return false; 117 } 118 return true; 119 } 120 121 125 public String getOptString() { 126 return "Rl"; } 128 129 133 public void resetCVSCommand() { 134 setRecursive(true); 135 setWatch(null); 136 } 137 138 141 public String getCVSCommand() { 142 StringBuffer cvsCommand = new StringBuffer ("watch "); cvsCommand.append(getCVSArguments()); 144 appendFileArguments(cvsCommand); 145 return cvsCommand.toString(); 146 } 147 148 152 public String getCVSArguments() { 153 checkState(); 154 155 StringBuffer cvsArguments = new StringBuffer (); 156 cvsArguments.append(getWatchMode().toString()); 157 cvsArguments.append(' '); 158 159 if (!isRecursive()) { 160 cvsArguments.append("-l "); } 162 163 if (getWatchMode().isWatchOptionAllowed()) { 164 cvsArguments.append("-a "); 165 cvsArguments.append(getWatchNotNull().toString()); 166 } 167 return cvsArguments.toString(); 168 } 169 170 173 public WatchMode getWatchMode() { 174 return watchMode; 175 } 176 177 180 public void setWatchMode(WatchMode watchMode) { 181 this.watchMode = watchMode; 182 } 183 184 187 public Watch getWatch() { 188 return watch; 189 } 190 191 private Watch getWatchNotNull() { 192 if (watch == null) { 193 return Watch.ALL; 194 } 195 return watch; 196 } 197 198 203 public void setWatch(Watch watch) { 204 this.watch = watch; 205 } 206 207 private void checkState() { 208 if (getWatchMode() == null) { 209 throw new IllegalStateException ("Watch mode expected!"); 210 } 211 } 212 } 213 | Popular Tags |