1 22 package org.netbeans.lib.cvsclient.response; 23 24 import java.util.*; 25 import java.text.MessageFormat ; 26 27 31 public class ResponseFactory { 32 33 private final Map responseInstancesMap; 34 private String previousResponse = null; 35 36 public ResponseFactory() { 37 responseInstancesMap = new HashMap(); 38 responseInstancesMap.put("E", new ErrorMessageResponse()); responseInstancesMap.put("M", new MessageResponse()); responseInstancesMap.put("Mbinary", new MessageBinaryResponse()); responseInstancesMap.put("MT", new MessageTaggedResponse()); responseInstancesMap.put("Updated", new UpdatedResponse()); responseInstancesMap.put("Update-existing", new UpdatedResponse()); responseInstancesMap.put("Created", new CreatedResponse()); responseInstancesMap.put("Rcs-diff", new RcsDiffResponse()); responseInstancesMap.put("Checked-in", new CheckedInResponse()); responseInstancesMap.put("New-entry", new NewEntryResponse()); responseInstancesMap.put("ok", new OKResponse()); responseInstancesMap.put("error", new ErrorResponse()); responseInstancesMap.put("Set-static-directory", new SetStaticDirectoryResponse()); responseInstancesMap.put("Clear-static-directory", new ClearStaticDirectoryResponse()); responseInstancesMap.put("Set-sticky", new SetStickyResponse()); responseInstancesMap.put("Clear-sticky", new ClearStickyResponse()); responseInstancesMap.put("Valid-requests", new ValidRequestsResponse()); responseInstancesMap.put("Merged", new MergedResponse()); responseInstancesMap.put("Notified", new NotifiedResponse()); responseInstancesMap.put("Removed", new RemovedResponse()); responseInstancesMap.put("Remove-entry", new RemoveEntryResponse()); responseInstancesMap.put("Copy-file", new CopyFileResponse()); responseInstancesMap.put("Mod-time", new ModTimeResponse()); responseInstancesMap.put("Template", new TemplateResponse()); responseInstancesMap.put("Module-expansion", new ModuleExpansionResponse()); responseInstancesMap.put("Wrapper-rcsOption", new WrapperSendResponse()); 65 } 66 67 public Response createResponse(String responseName) { 68 Response response = (Response)responseInstancesMap.get(responseName); 69 if (response != null) { 70 previousResponse = responseName; 71 return response; 72 } 73 if (previousResponse != null && previousResponse.equals("M")) { return new MessageResponse(responseName); 75 } 76 previousResponse = null; 77 IllegalArgumentException2 ex = new IllegalArgumentException2("Unhandled response: " + responseName + "."); 80 82 String cvsServer = System.getenv("CVS_SERVER"); if (cvsServer == null) { 84 cvsServer = ""; } else { 86 cvsServer = "=" + cvsServer; } 88 89 String cvsExe = System.getenv("CVS_EXE"); if (cvsExe == null) { 91 cvsExe = ""; } else { 93 cvsExe = "=" + cvsExe; } 95 96 ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.lib.cvsclient.response.Bundle"); String msg = bundle.getString("BK0001"); 98 msg = MessageFormat.format(msg, new Object [] {responseName, cvsServer, cvsExe}); 99 ex.setLocalizedMessage(msg); 100 throw ex; 101 } 102 103 private static class IllegalArgumentException2 extends IllegalArgumentException { 104 105 private String localizedMessage; 106 107 public IllegalArgumentException2(String s) { 108 super(s); 109 } 110 111 public String getLocalizedMessage() { 112 return localizedMessage; 113 } 114 115 private void setLocalizedMessage(String localizedMessage) { 116 this.localizedMessage = localizedMessage; 117 } 118 119 120 } 121 } 122 | Popular Tags |