001: /*****************************************************************************
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is the CVS Client Library.
027: * The Initial Developer of the Original Software is Robert Greig.
028: * Portions created by Robert Greig are Copyright (C) 2000.
029: * All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041: *
042: * Contributor(s): Robert Greig.
043: *****************************************************************************/package org.netbeans.lib.cvsclient.response;
044:
045: import java.util.*;
046: import java.text.MessageFormat;
047:
048: /**
049: * Create response objects appropriate for handling different types of response
050: * @author Robert Greig
051: */
052: public class ResponseFactory {
053:
054: private final Map responseInstancesMap;
055: private String previousResponse = null;
056:
057: public ResponseFactory() {
058: responseInstancesMap = new HashMap();
059: responseInstancesMap.put("E", new ErrorMessageResponse()); //NOI18N
060: responseInstancesMap.put("M", new MessageResponse()); //NOI18N
061: responseInstancesMap
062: .put("Mbinary", new MessageBinaryResponse()); //NOI18N
063: responseInstancesMap.put("MT", new MessageTaggedResponse()); //NOI18N
064: responseInstancesMap.put("Updated", new UpdatedResponse()); //NOI18N
065: responseInstancesMap.put("Update-existing",
066: new UpdatedResponse()); //NOI18N
067: responseInstancesMap.put("Created", new CreatedResponse()); //NOI18N
068: responseInstancesMap.put("Rcs-diff", new RcsDiffResponse()); //NOI18N
069: responseInstancesMap.put("Checked-in", new CheckedInResponse()); //NOI18N
070: responseInstancesMap.put("New-entry", new NewEntryResponse()); //NOI18N
071: responseInstancesMap.put("ok", new OKResponse()); //NOI18N
072: responseInstancesMap.put("error", new ErrorResponse()); //NOI18N
073: responseInstancesMap.put("Set-static-directory",
074: new SetStaticDirectoryResponse()); //NOI18N
075: responseInstancesMap.put("Clear-static-directory",
076: new ClearStaticDirectoryResponse()); //NOI18N
077: responseInstancesMap.put("Set-sticky", new SetStickyResponse()); //NOI18N
078: responseInstancesMap.put("Clear-sticky",
079: new ClearStickyResponse()); //NOI18N
080: responseInstancesMap.put("Valid-requests",
081: new ValidRequestsResponse()); //NOI18N
082: responseInstancesMap.put("Merged", new MergedResponse()); //NOI18N
083: responseInstancesMap.put("Notified", new NotifiedResponse()); //NOI18N
084: responseInstancesMap.put("Removed", new RemovedResponse()); //NOI18N
085: responseInstancesMap.put("Remove-entry",
086: new RemoveEntryResponse()); //NOI18N
087: responseInstancesMap.put("Copy-file", new CopyFileResponse()); //NOI18N
088: responseInstancesMap.put("Mod-time", new ModTimeResponse()); //NOI18N
089: responseInstancesMap.put("Template", new TemplateResponse()); //NOI18N
090: responseInstancesMap.put("Module-expansion",
091: new ModuleExpansionResponse()); //NOI18N
092: responseInstancesMap.put("Wrapper-rcsOption",
093: new WrapperSendResponse()); //NOI18N
094:
095: }
096:
097: public Response createResponse(String responseName) {
098: Response response = (Response) responseInstancesMap
099: .get(responseName);
100: if (response != null) {
101: previousResponse = responseName;
102: return response;
103: }
104: if (previousResponse != null && previousResponse.equals("M")) { //NOI18N
105: return new MessageResponse(responseName);
106: }
107: previousResponse = null;
108: IllegalArgumentException2 ex = new IllegalArgumentException2(
109: "Unhandled response: " + //NOI18N
110: responseName + "."); //NOI18N
111:
112: // assemble reasonable localized message
113:
114: String cvsServer = System.getenv("CVS_SERVER"); // NOI18N
115: if (cvsServer == null) {
116: cvsServer = ""; // NOI18N
117: } else {
118: cvsServer = "=" + cvsServer; // NOI18N
119: }
120:
121: String cvsExe = System.getenv("CVS_EXE"); // NOI18N
122: if (cvsExe == null) {
123: cvsExe = ""; // NOI18N
124: } else {
125: cvsExe = "=" + cvsExe; // NOI18N
126: }
127:
128: ResourceBundle bundle = ResourceBundle
129: .getBundle("org.netbeans.lib.cvsclient.response.Bundle"); //NOI18N
130: String msg = bundle.getString("BK0001");
131: msg = MessageFormat.format(msg, new Object[] { responseName,
132: cvsServer, cvsExe });
133: ex.setLocalizedMessage(msg);
134: throw ex;
135: }
136:
137: private static class IllegalArgumentException2 extends
138: IllegalArgumentException {
139:
140: private String localizedMessage;
141:
142: public IllegalArgumentException2(String s) {
143: super (s);
144: }
145:
146: public String getLocalizedMessage() {
147: return localizedMessage;
148: }
149:
150: private void setLocalizedMessage(String localizedMessage) {
151: this.localizedMessage = localizedMessage;
152: }
153:
154: }
155: }
|