KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > response > ResponseFactory


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.response;
23
24 import java.util.*;
25 import java.text.MessageFormat JavaDoc;
26
27 /**
28  * Create response objects appropriate for handling different types of response
29  * @author Robert Greig
30  */

31 public class ResponseFactory {
32
33     private final Map responseInstancesMap;
34     private String JavaDoc previousResponse = null;
35
36     public ResponseFactory() {
37         responseInstancesMap = new HashMap();
38         responseInstancesMap.put("E", new ErrorMessageResponse()); //NOI18N
39
responseInstancesMap.put("M", new MessageResponse()); //NOI18N
40
responseInstancesMap.put("Mbinary", new MessageBinaryResponse()); //NOI18N
41
responseInstancesMap.put("MT", new MessageTaggedResponse()); //NOI18N
42
responseInstancesMap.put("Updated", new UpdatedResponse()); //NOI18N
43
responseInstancesMap.put("Update-existing", new UpdatedResponse()); //NOI18N
44
responseInstancesMap.put("Created", new CreatedResponse()); //NOI18N
45
responseInstancesMap.put("Rcs-diff", new RcsDiffResponse()); //NOI18N
46
responseInstancesMap.put("Checked-in", new CheckedInResponse()); //NOI18N
47
responseInstancesMap.put("New-entry", new NewEntryResponse()); //NOI18N
48
responseInstancesMap.put("ok", new OKResponse()); //NOI18N
49
responseInstancesMap.put("error", new ErrorResponse()); //NOI18N
50
responseInstancesMap.put("Set-static-directory", new SetStaticDirectoryResponse()); //NOI18N
51
responseInstancesMap.put("Clear-static-directory", new ClearStaticDirectoryResponse()); //NOI18N
52
responseInstancesMap.put("Set-sticky", new SetStickyResponse()); //NOI18N
53
responseInstancesMap.put("Clear-sticky", new ClearStickyResponse()); //NOI18N
54
responseInstancesMap.put("Valid-requests", new ValidRequestsResponse()); //NOI18N
55
responseInstancesMap.put("Merged", new MergedResponse()); //NOI18N
56
responseInstancesMap.put("Notified", new NotifiedResponse()); //NOI18N
57
responseInstancesMap.put("Removed", new RemovedResponse()); //NOI18N
58
responseInstancesMap.put("Remove-entry", new RemoveEntryResponse()); //NOI18N
59
responseInstancesMap.put("Copy-file", new CopyFileResponse()); //NOI18N
60
responseInstancesMap.put("Mod-time", new ModTimeResponse()); //NOI18N
61
responseInstancesMap.put("Template", new TemplateResponse()); //NOI18N
62
responseInstancesMap.put("Module-expansion", new ModuleExpansionResponse()); //NOI18N
63
responseInstancesMap.put("Wrapper-rcsOption", new WrapperSendResponse()); //NOI18N
64

65     }
66     
67     public Response createResponse(String JavaDoc 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")) { //NOI18N
74
return new MessageResponse(responseName);
75         }
76         previousResponse = null;
77         IllegalArgumentException2 ex = new IllegalArgumentException2("Unhandled response: " + //NOI18N
78
responseName + "."); //NOI18N
79

80         // assemble reasonable localized message
81

82         String JavaDoc cvsServer = System.getenv("CVS_SERVER"); // NOI18N
83
if (cvsServer == null) {
84             cvsServer = ""; // NOI18N
85
} else {
86             cvsServer = "=" + cvsServer; // NOI18N
87
}
88
89         String JavaDoc cvsExe = System.getenv("CVS_EXE"); // NOI18N
90
if (cvsExe == null) {
91             cvsExe = ""; // NOI18N
92
} else {
93             cvsExe = "=" + cvsExe; // NOI18N
94
}
95
96         ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.lib.cvsclient.response.Bundle"); //NOI18N
97
String JavaDoc msg = bundle.getString("BK0001");
98         msg = MessageFormat.format(msg, new Object JavaDoc[] {responseName, cvsServer, cvsExe});
99         ex.setLocalizedMessage(msg);
100         throw ex;
101     }
102
103     private static class IllegalArgumentException2 extends IllegalArgumentException JavaDoc {
104
105         private String JavaDoc localizedMessage;
106
107         public IllegalArgumentException2(String JavaDoc s) {
108             super(s);
109         }
110
111         public String JavaDoc getLocalizedMessage() {
112             return localizedMessage;
113         }
114
115         private void setLocalizedMessage(String JavaDoc localizedMessage) {
116             this.localizedMessage = localizedMessage;
117         }
118
119
120     }
121 }
122
Popular Tags