Home » Mojarra-2.0.1 » javax » faces » event » [javadoc | source]

    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        * <p>The (optional) name for this phase.</p>
   78        */
   79   
   80       private String phaseName = null;
   81   
   82   
   83       // --------------------------------------------------------- Public Methods
   84   
   85   
   86       /**
   87        * <p>Compare this {@link PhaseId} instance to the specified one.
   88        * Returns a negative integer, zero, or a positive integer if this
   89        * object is less than, equal to, or greater than the specified object.</p>
   90        *
   91        * @param other The other object to be compared to
   92        */
   93       public int compareTo(Object other) {
   94   
   95           return this.ordinal - ((PhaseId) other).ordinal;
   96   
   97       }
   98   
   99   
  100       /**
  101        * <p>Return the ordinal value of this {@link PhaseId} instance.</p>
  102        */
  103       public int getOrdinal() {
  104   
  105           return (this.ordinal);
  106   
  107       }
  108   
  109   
  110       /**
  111        * <p>Return a String representation of this {@link PhaseId} instance.</p>
  112        */
  113       public String toString() {
  114           if (null == phaseName) {
  115               return (String.valueOf(this.ordinal));
  116           }
  117   
  118           return (String.valueOf(this.phaseName) + ' ' + this.ordinal);
  119       }
  120   
  121   
  122       // ------------------------------------------------------- Static Variables
  123   
  124   
  125       /**
  126        * <p>Static counter returning the ordinal value to be assigned to the
  127        * next instance that is created.</p>
  128        */
  129       private static int nextOrdinal = 0;
  130   
  131   
  132       // ------------------------------------------------------ Create Instances
  133   
  134   
  135       // Any new Phase values must go at the end of the list, or we will break
  136       // backwards compatibility on serialized instances
  137   
  138   
  139       private static final String ANY_PHASE_NAME = "ANY";
  140       /**
  141        * <p>Identifier that indicates an interest in events, no matter
  142        * which request processing phase is being performed.</p>
  143        */
  144       public static final PhaseId ANY_PHASE = new PhaseId(ANY_PHASE_NAME);
  145   
  146   
  147       private static final String RESTORE_VIEW_NAME = "RESTORE_VIEW";
  148       /**
  149        * <p>Identifier that indicates an interest in events queued for
  150        * the <em>Restore View</em> phase of the request
  151        * processing lifecycle.</p>
  152        */
  153       public static final PhaseId RESTORE_VIEW = new PhaseId(RESTORE_VIEW_NAME);
  154   
  155   
  156       private static final String APPLY_REQUEST_VALUES_NAME = "APPLY_REQUEST_VALUES";
  157       /**
  158        * <p>Identifier that indicates an interest in events queued for
  159        * the <em>Apply Request Values</em> phase of the request
  160        * processing lifecycle.</p>
  161        */
  162       public static final PhaseId APPLY_REQUEST_VALUES = new PhaseId(APPLY_REQUEST_VALUES_NAME);
  163   
  164   
  165       private static final String PROCESS_VALIDATIONS_NAME = "PROCESS_VALIDATIONS";
  166       /**
  167        * <p>Identifier that indicates an interest in events queued for
  168        * the <em>Process Validations</em> phase of the request
  169        * processing lifecycle.</p>
  170        */
  171       public static final PhaseId PROCESS_VALIDATIONS = new PhaseId(PROCESS_VALIDATIONS_NAME);
  172   
  173   
  174       private static final String UPDATE_MODEL_VALUES_NAME = "UPDATE_MODEL_VALUES";
  175       /**
  176        * <p>Identifier that indicates an interest in events queued for
  177        * the <em>Update Model Values</em> phase of the request
  178        * processing lifecycle.</p>
  179        */
  180       public static final PhaseId UPDATE_MODEL_VALUES = new PhaseId(UPDATE_MODEL_VALUES_NAME);
  181   
  182   
  183       private static final String INVOKE_APPLICATION_NAME = "INVOKE_APPLICATION";
  184       /**
  185        * <p>Identifier that indicates an interest in events queued for
  186        * the <em>Invoke Application</em> phase of the request
  187        * processing lifecycle.</p>
  188        */
  189       public static final PhaseId INVOKE_APPLICATION = new PhaseId(INVOKE_APPLICATION_NAME);
  190   
  191       private static final String RENDER_RESPONSE_NAME = "RENDER_RESPONSE";
  192       /**
  193        * <p>Identifier for the <em>Render Response</em> phase of the
  194        * request processing lifecycle.</p>
  195        */
  196       public static final PhaseId RENDER_RESPONSE = new PhaseId(RENDER_RESPONSE_NAME);
  197   
  198   
  199       /**
  200        * <p>Array of all defined values, ascending order of ordinal value.
  201        * Be sure you include any new instances created above, in the
  202        * same order.</p>
  203        */
  204       private static final PhaseId[] values =
  205               {ANY_PHASE, RESTORE_VIEW, APPLY_REQUEST_VALUES,
  206                       PROCESS_VALIDATIONS, UPDATE_MODEL_VALUES, INVOKE_APPLICATION, RENDER_RESPONSE};
  207   
  208   
  209       /**
  210        * <p>List of valid {@link PhaseId} instances, in ascending order
  211        * of their ordinal value.</p>
  212        */
  213       public static final List<PhaseId> VALUES =
  214               Collections.unmodifiableList(Arrays.asList(values));
  215   
  216   
  217   }

Home » Mojarra-2.0.1 » javax » faces » event » [javadoc | source]