1 /*
2 * $Id: PhaseId.java,v 1.22 2007/04/27 22:00:08 ofung Exp $
3 */
4
5 /*
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
7 *
8 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
9 *
10 * The contents of this file are subject to the terms of either the GNU
11 * General Public License Version 2 only ("GPL") or the Common Development
12 * and Distribution License("CDDL") (collectively, the "License"). You
13 * may not use this file except in compliance with the License. You can obtain
14 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
15 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
16 * language governing permissions and limitations under the License.
17 *
18 * When distributing the software, include this License Header Notice in each
19 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
20 * Sun designates this particular file as subject to the "Classpath" exception
21 * as provided by Sun in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the License
23 * Header, with the fields enclosed by brackets [] replaced by your own
24 * identifying information: "Portions Copyrighted [year]
25 * [name of copyright owner]"
26 *
27 * Contributor(s):
28 *
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41 package javax.faces.event;
42
43
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.List;
47
48
49 /**
50 * <p>Typesafe enumeration of the legal values that may be returned by the
51 * <code>getPhaseId()</code> method of the {@link FacesEvent} interface.
52 */
53
54 public class PhaseId implements Comparable {
55
56
57 // ----------------------------------------------------------- Constructors
58
59
60 /**
61 * <p>Private constructor to disable the creation of new instances.</p>
62 */
63 private PhaseId(String newPhaseName) {
64 phaseName = newPhaseName;
65 }
66
67
68 // ----------------------------------------------------- Instance Variables
69
70
71 /**
72 * <p>The ordinal value assigned to this instance.</p>
73 */
74 private final int ordinal = nextOrdinal++;
75
76 /**
77
78 * <p>The (optional) name for this phase.</p>
79
80 */
81
82 private String phaseName = null;
83
84
85 // --------------------------------------------------------- Public Methods
86
87
88 /**
89 * <p>Compare this {@link PhaseId} instance to the specified one.
90 * Returns a negative integer, zero, or a positive integer if this
91 * object is less than, equal to, or greater than the specified object.</p>
92 *
93 * @param other The other object to be compared to
94 */
95 public int compareTo(Object other) {
96
97 return this.ordinal - ((PhaseId) other).ordinal;
98
99 }
100
101
102 /**
103 * <p>Return the ordinal value of this {@link PhaseId} instance.</p>
104 */
105 public int getOrdinal() {
106
107 return (this.ordinal);
108
109 }
110
111
112 /**
113 * <p>Return a String representation of this {@link PhaseId} instance.</p>
114 */
115 public String toString() {
116 if (null == phaseName) {
117 return (String.valueOf(this.ordinal));
118 }
119
120 return (String.valueOf(this.phaseName) + ' ' + this.ordinal);
121 }
122
123
124 // ------------------------------------------------------- Static Variables
125
126
127 /**
128 * <p>Static counter returning the ordinal value to be assigned to the
129 * next instance that is created.</p>
130 */
131 private static int nextOrdinal = 0;
132
133
134 // ------------------------------------------------------ Create Instances
135
136
137 // Any new Phase values must go at the end of the list, or we will break
138 // backwards compatibility on serialized instances
139
140
141 private static final String ANY_PHASE_NAME = "ANY";
142 /**
143 * <p>Identifier that indicates an interest in events, no matter
144 * which request processing phase is being performed.</p>
145 */
146 public static final PhaseId ANY_PHASE = new PhaseId(ANY_PHASE_NAME);
147
148
149 private static final String RESTORE_VIEW_NAME = "RESTORE_VIEW";
150 /**
151 * <p>Identifier that indicates an interest in events queued for
152 * the <em>Restore View</em> phase of the request
153 * processing lifecycle.</p>
154 */
155 public static final PhaseId RESTORE_VIEW = new PhaseId(RESTORE_VIEW_NAME);
156
157
158 private static final String APPLY_REQUEST_VALUES_NAME = "APPLY_REQUEST_VALUES";
159 /**
160 * <p>Identifier that indicates an interest in events queued for
161 * the <em>Apply Request Values</em> phase of the request
162 * processing lifecycle.</p>
163 */
164 public static final PhaseId APPLY_REQUEST_VALUES = new PhaseId(APPLY_REQUEST_VALUES_NAME);
165
166
167 private static final String PROCESS_VALIDATIONS_NAME = "PROCESS_VALIDATIONS";
168 /**
169 * <p>Identifier that indicates an interest in events queued for
170 * the <em>Process Validations</em> phase of the request
171 * processing lifecycle.</p>
172 */
173 public static final PhaseId PROCESS_VALIDATIONS = new PhaseId(PROCESS_VALIDATIONS_NAME);
174
175
176 private static final String UPDATE_MODEL_VALUES_NAME = "UPDATE_MODEL_VALUES";
177 /**
178 * <p>Identifier that indicates an interest in events queued for
179 * the <em>Update Model Values</em> phase of the request
180 * processing lifecycle.</p>
181 */
182 public static final PhaseId UPDATE_MODEL_VALUES = new PhaseId(UPDATE_MODEL_VALUES_NAME);
183
184
185 private static final String INVOKE_APPLICATION_NAME = "INVOKE_APPLICATION";
186 /**
187 * <p>Identifier that indicates an interest in events queued for
188 * the <em>Invoke Application</em> phase of the request
189 * processing lifecycle.</p>
190 */
191 public static final PhaseId INVOKE_APPLICATION = new PhaseId(INVOKE_APPLICATION_NAME);
192
193 private static final String RENDER_RESPONSE_NAME = "RENDER_RESPONSE";
194 /**
195 * <p>Identifier for the <em>Render Response</em> phase of the
196 * request processing lifecycle.</p>
197 */
198 public static final PhaseId RENDER_RESPONSE = new PhaseId(RENDER_RESPONSE_NAME);
199
200
201
202 /**
203 * <p>Array of all defined values, ascending order of ordinal value.
204 * Be sure you include any new instances created above, in the
205 * same order.</p>
206 */
207 private static final PhaseId[] values =
208 { ANY_PHASE, RESTORE_VIEW, APPLY_REQUEST_VALUES,
209 PROCESS_VALIDATIONS, UPDATE_MODEL_VALUES, INVOKE_APPLICATION, RENDER_RESPONSE };
210
211
212 /**
213 * <p>List of valid {@link PhaseId} instances, in ascending order
214 * of their ordinal value.</p>
215 */
216 public static final List VALUES =
217 Collections.unmodifiableList(Arrays.asList(values));
218
219
220 }