1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.internal;
22
23 /**
24 * List of valid services that the test redirectors can perform.
25 *
26 * @version $Id: ServiceEnumeration.java 238991 2004-05-22 11:34:50Z vmassol $
27 */
28 public final class ServiceEnumeration
29 {
30 /**
31 * Call test method Service.
32 */
33 public static final ServiceEnumeration CALL_TEST_SERVICE =
34 new ServiceEnumeration("CALL_TEST");
35
36 /**
37 * Get the previous test results Service.
38 */
39 public static final ServiceEnumeration GET_RESULTS_SERVICE =
40 new ServiceEnumeration("GET_RESULTS");
41
42 /**
43 * Noop service for testing.
44 */
45 public static final ServiceEnumeration RUN_TEST_SERVICE =
46 new ServiceEnumeration("RUN_TEST");
47
48 /**
49 * Service used to create an HTTP session so that it is returned
50 * in a cookie.
51 * @since 1.5
52 */
53 public static final ServiceEnumeration CREATE_SESSION_SERVICE =
54 new ServiceEnumeration("CREATE_SESSION");
55
56 /**
57 * Service that returns a cactus version identifier. This is used
58 * to verify that the server side and client side versions of
59 * Cactus are the same.
60 * @since 1.5
61 */
62 public static final ServiceEnumeration GET_VERSION_SERVICE =
63 new ServiceEnumeration("GET_VERSION");
64
65 /**
66 * The service's name.
67 */
68 private String name;
69
70 /**
71 * Private constructor to only allow the predefined instances of the
72 * enumeration.
73 *
74 * @param theServiceName the name of the service
75 */
76 private ServiceEnumeration(String theServiceName)
77 {
78 this.name = theServiceName;
79 }
80
81 /**
82 * Compares a string representing the name of the service with the service
83 * enumerated type.
84 *
85 * @param theString the string to compare with this Service name
86 * @return true if the string corresponds to the current Service
87 * @deprecated Use {@link ServiceEnumeration#valueOf} and identity
88 * comparison instead of this method
89 */
90 public boolean equals(String theString)
91 {
92 return theString.equals(this.name);
93 }
94
95 /**
96 * Always compares object identity.
97 *
98 * {@inheritDoc}
99 * @see java.lang.Object#equals(Object)
100 * @since 1.5
101 */
102 public boolean equals(Object theObject)
103 {
104 return super.equals(theObject);
105 }
106
107 /**
108 * Delegates to the <code>java.lang.Object</code> implementation.
109 *
110 * {@inheritDoc}
111 * @see java.lang.Object#equals(Object)
112 * @since 1.5
113 */
114 public int hashCode()
115 {
116 return super.hashCode();
117 }
118
119 /**
120 * Returns the string representation of the service.
121 *
122 * @return the service's name
123 * @see java.lang.Object#toString
124 */
125 public String toString()
126 {
127 return this.name;
128 }
129
130 /**
131 * Returns the enumeration instance corresponding to the provided service
132 * name.
133 *
134 * @param theName The name of the service
135 * @return The corresponding service instance
136 * @since 1.5
137 */
138 public static ServiceEnumeration valueOf(String theName)
139 {
140 if (CALL_TEST_SERVICE.name.equals(theName))
141 {
142 return CALL_TEST_SERVICE;
143 }
144 else if (GET_RESULTS_SERVICE.name.equals(theName))
145 {
146 return GET_RESULTS_SERVICE;
147 }
148 else if (RUN_TEST_SERVICE.name.equals(theName))
149 {
150 return RUN_TEST_SERVICE;
151 }
152 else if (CREATE_SESSION_SERVICE.name.equals(theName))
153 {
154 return CREATE_SESSION_SERVICE;
155 }
156 else if (GET_VERSION_SERVICE.name.equals(theName))
157 {
158 return GET_VERSION_SERVICE;
159 }
160 return null;
161 }
162
163 }