Source code: com/synaptics/elvis/ElvisRequest.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 /** ElvisRequest implements an enumeration of the requests that a client may send to
23 * Elvis. See the individual requests for details of what they do.
24 * <P>
25 * ElvisRequest 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: ElvisRequest.java,v 1.1 2002/05/09 07:17:17 clheiny Exp $
30 */
31
32 public class ElvisRequest {
33
34 private static java.util.Hashtable knownRequests = new java.util.Hashtable();
35
36 /** <CODE>PING</code> is basically a request to see if the other Elvis is there. If the
37 * receiving Elvis is indeed an Elvis, it will respond with another ElvisMessage. If the
38 * receiving Elvis implements the same program with the same key as this Elvis, the response
39 * message will be ElvisResponse.OK; otherwise the response will be ElvisResponse.FAIL
40 */
41 public static final ElvisRequest PING = new ElvisRequest("ping");
42
43 /** <CODE>PERFORM</code> is a request to invoke the default ElvisHandler for this program.
44 * The data portion of the ElvisMessage will be passed to the ElvisHandler.
45 */
46 public static final ElvisRequest PERFORM = new ElvisRequest("perform");
47
48 String name = "ERROR";
49
50 /** Creates new ElvisRequest */
51 private ElvisRequest( String name ) {
52 this.name = name;
53 knownRequests.put ( name, this );
54 }
55
56 /** Return the String associated with this request. This is useful for printing diagnostics
57 * and feedback.
58 * @Return A String.
59 */
60 public String toString() {
61 return name;
62 }
63
64 /** @return <CODE>true</code> if this string corresponds to a known request, <CODE>false</code>
65 * otherwise.
66 */
67 public static final boolean valid ( String name ) {
68 return knownRequests.containsKey(name);
69 }
70
71 }