KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > ServiceEnumeration


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.internal;
21
22 /**
23  * List of valid services that the test redirectors can perform.
24  *
25  * @version $Id: ServiceEnumeration.java,v 1.1 2004/05/22 11:34:47 vmassol Exp $
26  */

27 public final class ServiceEnumeration
28 {
29     /**
30      * Call test method Service.
31      */

32     public static final ServiceEnumeration CALL_TEST_SERVICE =
33         new ServiceEnumeration("CALL_TEST");
34
35     /**
36      * Get the previous test results Service.
37      */

38     public static final ServiceEnumeration GET_RESULTS_SERVICE =
39         new ServiceEnumeration("GET_RESULTS");
40
41     /**
42      * Noop service for testing.
43      */

44     public static final ServiceEnumeration RUN_TEST_SERVICE =
45         new ServiceEnumeration("RUN_TEST");
46
47     /**
48      * Service used to create an HTTP session so that it is returned
49      * in a cookie.
50      * @since 1.5
51      */

52     public static final ServiceEnumeration CREATE_SESSION_SERVICE =
53         new ServiceEnumeration("CREATE_SESSION");
54
55     /**
56      * Service that returns a cactus version identifier. This is used
57      * to verify that the server side and client side versions of
58      * Cactus are the same.
59      * @since 1.5
60      */

61     public static final ServiceEnumeration GET_VERSION_SERVICE =
62         new ServiceEnumeration("GET_VERSION");
63
64     /**
65      * The service's name
66      */

67     private String JavaDoc name;
68
69     /**
70      * Private constructor to only allow the predefined instances of the
71      * enumeration.
72      *
73      * @param theServiceName the name of the service
74      */

75     private ServiceEnumeration(String JavaDoc theServiceName)
76     {
77         this.name = theServiceName;
78     }
79
80     /**
81      * Compares a string representing the name of the service with the service
82      * enumerated type.
83      *
84      * @param theString the string to compare with this Service name
85      * @return true if the string corresponds to the current Service
86      * @deprecated Use {@link ServiceEnumeration#valueOf} and identity
87      * comparison instead of this method
88      */

89     public boolean equals(String JavaDoc theString)
90     {
91         return theString.equals(this.name);
92     }
93
94     /**
95      * Always compares object identity.
96      *
97      * @see java.lang.Object#equals(Object)
98      * @since 1.5
99      */

100     public boolean equals(Object JavaDoc theObject)
101     {
102         return super.equals(theObject);
103     }
104
105     /**
106      * Delegates to the <code>java.lang.Object</code> implementation.
107      *
108      * @see java.lang.Object#equals(Object)
109      * @since 1.5
110      */

111     public int hashCode()
112     {
113         return super.hashCode();
114     }
115
116     /**
117      * Returns the string representation of the service.
118      *
119      * @return the service's name
120      * @see java.lang.Object#toString
121      */

122     public String JavaDoc toString()
123     {
124         return this.name;
125     }
126     
127     /**
128      * Returns the enumeration instance corresponding to the provided service
129      * name.
130      *
131      * @param theName The name of the service
132      * @return The corresponding service instance
133      * @since 1.5
134      */

135     public static ServiceEnumeration valueOf(String JavaDoc theName)
136     {
137         if (CALL_TEST_SERVICE.name.equals(theName))
138         {
139             return CALL_TEST_SERVICE;
140         }
141         else if (GET_RESULTS_SERVICE.name.equals(theName))
142         {
143             return GET_RESULTS_SERVICE;
144         }
145         else if (RUN_TEST_SERVICE.name.equals(theName))
146         {
147             return RUN_TEST_SERVICE;
148         }
149         else if (CREATE_SESSION_SERVICE.name.equals(theName))
150         {
151             return CREATE_SESSION_SERVICE;
152         }
153         else if (GET_VERSION_SERVICE.name.equals(theName))
154         {
155             return GET_VERSION_SERVICE;
156         }
157         return null;
158     }
159     
160 }
161
Popular Tags