Source code: com/synaptics/elvis/ElvisResponse.java
1 /*
2 * The contents of this file are subject to the Mozilla Public License Version
3 * 1.1 (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5 *
6 * Software distributed under the License is distributed on an "AS IS" basis,
7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8 * the specific language governing rights and limitations under the License.
9 *
10 * The Original Code is com.synaptics.elvis code.
11 *
12 * The Initial Developers of the Original Code are Synaptics, Inc. and Christopher Heiny.
13 * Portions created by Synaptics, Inc. and Christopher Heiny are
14 * Copyright (C) 2002 Synaptics, Inc. and Christopher Heiny. All Rights Reserved.
15 *
16 * Contributor(s):
17 * Christopher Heiny <cheiny@synaptics.com>
18 */
19
20 package com.synaptics.elvis;
21
22 /** ElvisResponse implements an enumeration of the responses that an Elvis may send to
23 * its clients in response to ElvisRequests. See the individual responses for details of what they do.
24 * <P>
25 * ElvisResponse implements the <CODE>typesafe enum</code> design pattern, as described
26 * in Joshua Bloch's <I>Effective Java</i>.
27 *
28 * @author cheiny
29 * @version $Id: ElvisResponse.java,v 1.1 2002/05/09 07:17:17 clheiny Exp $
30 */
31
32 public class ElvisResponse {
33
34 private static java.util.Hashtable knownResponse = new java.util.Hashtable();
35
36 /** <CODE>OK</code> indicates that Elvis is happy with the request.
37 */
38 public static final ElvisResponse OK = new ElvisResponse("ok");
39
40 /** <CODE>FAIL</code> indicates that Elvis is <B>not</b> happy with the request.
41 * The data field of the ElvisMessage may (or may not) contain information regarding
42 * the reason Elvis is displeased.
43 */
44 public static final ElvisResponse FAIL = new ElvisResponse("fail");
45
46 String name = "ERROR";
47
48 /** Creates new ElvisResponse */
49 private ElvisResponse(String name) {
50 this.name = name;
51 knownResponse.put ( name, this );
52 }
53
54 /** Return the string value associated with this response. Useful for printing diagnostics
55 * and other feedback.
56 * @return A String
57 */
58 public String toString() {
59 return name;
60 }
61
62 /** @return <CODE>true</code> if this string corresponds to a known response, <CODE>false</code>
63 * otherwise.
64 */
65 public static final boolean valid ( String name ) {
66 return knownResponse.containsKey(name);
67 }
68
69 }