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 jakarta.faces.event;
20  
21  import jakarta.faces.FacesException;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  /**
28   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
29   */
30  public class PhaseId implements Comparable
31  {
32      // FIELDS
33      public static final PhaseId ANY_PHASE;
34      public static final PhaseId APPLY_REQUEST_VALUES;
35      public static final PhaseId INVOKE_APPLICATION;
36      public static final PhaseId PROCESS_VALIDATIONS;
37      public static final PhaseId RENDER_RESPONSE;
38      public static final PhaseId RESTORE_VIEW;
39      public static final PhaseId UPDATE_MODEL_VALUES;
40      public static final List<PhaseId> VALUES;
41  
42      static
43      {
44          int i = 0;
45          ArrayList<PhaseId> list = new ArrayList<PhaseId>(6);
46  
47          ANY_PHASE = new PhaseId("ANY_PHASE", i++);
48          list.add(ANY_PHASE);
49          RESTORE_VIEW = new PhaseId("RESTORE_VIEW", i++);
50          list.add(RESTORE_VIEW);
51          APPLY_REQUEST_VALUES = new PhaseId("APPLY_REQUEST_VALUES", i++);
52          list.add(APPLY_REQUEST_VALUES);
53          PROCESS_VALIDATIONS = new PhaseId("PROCESS_VALIDATIONS", i++);
54          list.add(PROCESS_VALIDATIONS);
55          UPDATE_MODEL_VALUES = new PhaseId("UPDATE_MODEL_VALUES", i++);
56          list.add(UPDATE_MODEL_VALUES);
57          INVOKE_APPLICATION = new PhaseId("INVOKE_APPLICATION", i++);
58          list.add(INVOKE_APPLICATION);
59          RENDER_RESPONSE = new PhaseId("RENDER_RESPONSE", i++);
60          list.add(RENDER_RESPONSE);
61          VALUES = Collections.unmodifiableList(list);
62      }
63  
64      private final String _name;
65      private final int _ordinal;
66  
67      // CONSTRUCTORS
68      private PhaseId(String name, int ordinal)
69      {
70          this._name = name;
71          this._ordinal = ordinal;
72      }
73  
74      // METHODS
75      public int compareTo(Object other)
76      {
77          return _ordinal - ((PhaseId) other)._ordinal;
78      }
79  
80      public int getOrdinal()
81      {
82          return _ordinal;
83      }
84  
85      @Override
86      public String toString()
87      {
88          return _name + "(" + _ordinal + ")";
89      }
90      
91      /*
92       * @since 2.2
93       */
94      public String getName()
95      {
96          return this._name;
97      }
98  
99      public static PhaseId phaseIdValueOf(String phase)
100     {
101         if (phase == null)
102         {
103             throw new NullPointerException("phase");
104         }
105         for (int i = 0; i < VALUES.size(); i++)
106         {
107             PhaseId phaseId = VALUES.get(i);
108             if (phaseId.getName().equals(phase))
109             {
110                 return phaseId;
111             }
112         }
113         throw new FacesException("Phase "+phase+" is invalid");
114     }
115 }