1 19 package org.netbeans.lib.cvsclient.command; 20 21 import java.io.*; 22 import java.util.*; 23 24 import org.netbeans.lib.cvsclient.*; 25 import org.netbeans.lib.cvsclient.admin.*; 26 import org.netbeans.lib.cvsclient.connection.*; 27 import org.netbeans.lib.cvsclient.event.*; 28 import org.netbeans.lib.cvsclient.request.*; 29 30 36 public abstract class RepositoryCommand extends BuildableCommand { 37 40 protected List requests = new LinkedList(); 41 42 45 protected ClientServices clientServices; 46 47 50 private boolean recursive = true; 51 52 56 protected final List modules = new LinkedList(); 57 58 61 protected final List expandedModules = new LinkedList(); 62 63 67 public boolean isRecursive() { 68 return recursive; 69 } 70 71 75 public void setRecursive(boolean recursive) { 76 this.recursive = recursive; 77 } 78 79 83 public void addModule(String module) { 84 modules.add(module); 85 } 86 87 91 public void setModules(String [] modules) { 92 clearModules(); 93 if (modules == null) { 94 return; 95 } 96 for (int i = 0; i < modules.length; i++) { 97 String module = modules[i]; 98 this.modules.add(module); 99 } 100 } 101 102 105 public String [] getModules() { 106 String [] mods = new String [modules.size()]; 107 mods = (String [])modules.toArray(mods); 108 return mods; 109 } 110 111 114 public void clearModules() { 115 this.modules.clear(); 116 } 117 118 124 protected final void addArgumentRequests() { 125 if (expandedModules.size() == 0) { 126 return; 127 } 128 129 for (Iterator it = expandedModules.iterator(); it.hasNext(); ) { 130 final String module = (String ) it.next(); 131 addRequest(new ArgumentRequest(module)); 132 } 133 } 134 135 139 public final void moduleExpanded(ModuleExpansionEvent e) { 140 expandedModules.add(e.getModule()); 141 } 142 143 151 public final void execute(ClientServices client, EventManager em) 152 throws CommandException, AuthenticationException { 153 154 client.ensureConnection(); 155 156 requests.clear(); 157 super.execute(client, em); 158 159 clientServices = client; 160 161 if (client.isFirstCommand()) { 162 requests.add(new RootRequest(client.getRepository())); 163 } 164 for (Iterator it = modules.iterator(); it.hasNext();) { 165 String module = (String )it.next(); 166 requests.add(new ArgumentRequest(module)); 167 } 168 expandedModules.clear(); 169 requests.add(new DirectoryRequest(".", client.getRepository())); requests.add(new ExpandModulesRequest()); 171 try { 172 client.processRequests(requests); 173 } 174 catch (CommandException ex) { 175 throw ex; 176 } 177 catch (Exception ex) { 178 throw new CommandException(ex, ex.getLocalizedMessage()); 179 } 180 requests.clear(); 181 postExpansionExecute(client, em); 182 } 183 184 190 protected abstract void postExpansionExecute(ClientServices client, EventManager em) 191 throws CommandException, AuthenticationException; 192 193 196 protected final void addRequest(Request request) { 197 requests.add(request); 198 } 199 200 203 protected final void addRequestForWorkingDirectory(ClientServices clientServices) 204 throws IOException { 205 addRequest(new DirectoryRequest(".", clientServices.getRepositoryForDirectory(getLocalDirectory()))); 207 } 208 209 213 protected final void addArgumentRequest(boolean value, String argument) { 214 if (!value) { 215 return; 216 } 217 218 addRequest(new ArgumentRequest(argument)); 219 } 220 221 224 protected final void appendModuleArguments(StringBuffer buffer) { 225 if (expandedModules.size() == 0) { 226 return; 227 } 228 229 Iterator it = expandedModules.iterator(); 230 buffer.append((String ) it.next()); 231 while (it.hasNext()) { 232 buffer.append(' '); 233 buffer.append((String ) it.next()); 234 } 235 } 236 } 237 238 | Popular Tags |