001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2004 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.internal;
021:
022: /**
023: * List of valid services that the test redirectors can perform.
024: *
025: * @version $Id: ServiceEnumeration.java 238991 2004-05-22 11:34:50Z vmassol $
026: */
027: public final class ServiceEnumeration {
028: /**
029: * Call test method Service.
030: */
031: public static final ServiceEnumeration CALL_TEST_SERVICE = new ServiceEnumeration(
032: "CALL_TEST");
033:
034: /**
035: * Get the previous test results Service.
036: */
037: public static final ServiceEnumeration GET_RESULTS_SERVICE = new ServiceEnumeration(
038: "GET_RESULTS");
039:
040: /**
041: * Noop service for testing.
042: */
043: public static final ServiceEnumeration RUN_TEST_SERVICE = new ServiceEnumeration(
044: "RUN_TEST");
045:
046: /**
047: * Service used to create an HTTP session so that it is returned
048: * in a cookie.
049: * @since 1.5
050: */
051: public static final ServiceEnumeration CREATE_SESSION_SERVICE = new ServiceEnumeration(
052: "CREATE_SESSION");
053:
054: /**
055: * Service that returns a cactus version identifier. This is used
056: * to verify that the server side and client side versions of
057: * Cactus are the same.
058: * @since 1.5
059: */
060: public static final ServiceEnumeration GET_VERSION_SERVICE = new ServiceEnumeration(
061: "GET_VERSION");
062:
063: /**
064: * The service's name
065: */
066: private String name;
067:
068: /**
069: * Private constructor to only allow the predefined instances of the
070: * enumeration.
071: *
072: * @param theServiceName the name of the service
073: */
074: private ServiceEnumeration(String theServiceName) {
075: this .name = theServiceName;
076: }
077:
078: /**
079: * Compares a string representing the name of the service with the service
080: * enumerated type.
081: *
082: * @param theString the string to compare with this Service name
083: * @return true if the string corresponds to the current Service
084: * @deprecated Use {@link ServiceEnumeration#valueOf} and identity
085: * comparison instead of this method
086: */
087: public boolean equals(String theString) {
088: return theString.equals(this .name);
089: }
090:
091: /**
092: * Always compares object identity.
093: *
094: * @see java.lang.Object#equals(Object)
095: * @since 1.5
096: */
097: public boolean equals(Object theObject) {
098: return super .equals(theObject);
099: }
100:
101: /**
102: * Delegates to the <code>java.lang.Object</code> implementation.
103: *
104: * @see java.lang.Object#equals(Object)
105: * @since 1.5
106: */
107: public int hashCode() {
108: return super .hashCode();
109: }
110:
111: /**
112: * Returns the string representation of the service.
113: *
114: * @return the service's name
115: * @see java.lang.Object#toString
116: */
117: public String toString() {
118: return this .name;
119: }
120:
121: /**
122: * Returns the enumeration instance corresponding to the provided service
123: * name.
124: *
125: * @param theName The name of the service
126: * @return The corresponding service instance
127: * @since 1.5
128: */
129: public static ServiceEnumeration valueOf(String theName) {
130: if (CALL_TEST_SERVICE.name.equals(theName)) {
131: return CALL_TEST_SERVICE;
132: } else if (GET_RESULTS_SERVICE.name.equals(theName)) {
133: return GET_RESULTS_SERVICE;
134: } else if (RUN_TEST_SERVICE.name.equals(theName)) {
135: return RUN_TEST_SERVICE;
136: } else if (CREATE_SESSION_SERVICE.name.equals(theName)) {
137: return CREATE_SESSION_SERVICE;
138: } else if (GET_VERSION_SERVICE.name.equals(theName)) {
139: return GET_VERSION_SERVICE;
140: }
141: return null;
142: }
143:
144: }
|