View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package javax.faces.event;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import javax.faces.FacesException;
25  
26  /**
27   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
28   */
29  public class PhaseId implements Comparable
30  {
31      // FIELDS
32      public static final PhaseId ANY_PHASE;
33      public static final PhaseId APPLY_REQUEST_VALUES;
34      public static final PhaseId INVOKE_APPLICATION;
35      public static final PhaseId PROCESS_VALIDATIONS;
36      public static final PhaseId RENDER_RESPONSE;
37      public static final PhaseId RESTORE_VIEW;
38      public static final PhaseId UPDATE_MODEL_VALUES;
39      public static final List<PhaseId> VALUES;
40  
41      static
42      {
43          int i = 0;
44          ArrayList<PhaseId> list = new ArrayList<PhaseId>(6);
45  
46          ANY_PHASE = new PhaseId("ANY_PHASE", i++);
47          list.add(ANY_PHASE);
48          RESTORE_VIEW = new PhaseId("RESTORE_VIEW", i++);
49          list.add(RESTORE_VIEW);
50          APPLY_REQUEST_VALUES = new PhaseId("APPLY_REQUEST_VALUES", i++);
51          list.add(APPLY_REQUEST_VALUES);
52          PROCESS_VALIDATIONS = new PhaseId("PROCESS_VALIDATIONS", i++);
53          list.add(PROCESS_VALIDATIONS);
54          UPDATE_MODEL_VALUES = new PhaseId("UPDATE_MODEL_VALUES", i++);
55          list.add(UPDATE_MODEL_VALUES);
56          INVOKE_APPLICATION = new PhaseId("INVOKE_APPLICATION", i++);
57          list.add(INVOKE_APPLICATION);
58          RENDER_RESPONSE = new PhaseId("RENDER_RESPONSE", i++);
59          list.add(RENDER_RESPONSE);
60          VALUES = Collections.unmodifiableList(list);
61      }
62  
63      private final String _name;
64      private final int _ordinal;
65  
66      // CONSTRUCTORS
67      private PhaseId(String name, int ordinal)
68      {
69          this._name = name;
70          this._ordinal = ordinal;
71      }
72  
73      // METHODS
74      public int compareTo(Object other)
75      {
76          return _ordinal - ((PhaseId) other)._ordinal;
77      }
78  
79      public int getOrdinal()
80      {
81          return _ordinal;
82      }
83  
84      @Override
85      public String toString()
86      {
87          return _name + "(" + _ordinal + ")";
88      }
89      
90      /*
91       * @since 2.2
92       */
93      public String getName()
94      {
95          return this._name;
96      }
97  
98      public static PhaseId phaseIdValueOf(String phase)
99      {
100         if (phase == null)
101         {
102             throw new NullPointerException("phase");
103         }
104         for (int i = 0; i < VALUES.size(); i++)
105         {
106             PhaseId phaseId = VALUES.get(i);
107             if (phaseId.getName().equals(phase))
108             {
109                 return phaseId;
110             }
111         }
112         throw new FacesException("Phase "+phase+" is invalid");
113     }
114 }