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 org.apache.myfaces.orchestra.lib.jsf;
    20
    21  import javax.faces.context.FacesContext;
    22  import javax.faces.context.FacesContextWrapper;
    23
    24
    25  /**
    26   * Convenient class to wrap the current FacesContext.
    27   * <p>
    28   * A class of this name is provided in JSF1.2, but not in JSF1.1.
    29   * <p>
    30   * Any methods that do not actually need to be overridden are declared final
    31   * in order to improve performance (helps the JVM to optimise away the call).
    32   * <p>
    33   * Note that whether a newly-created instance immediately becomes the
    34   * object that is returned by FacesContext.getCurrentInstance() depends
    35   * upon the value of the "install" parameter for the constructor method.
    36   * <p>
    37   * This class is copied from the code in MyFaces Core Impl 1.2.x, but
    38   * modified to be compatible with JSF1.1.
    39   * <p>
    40   * Note that this class must be public in order to support custom
    41   * FacesContextFactory classes in other libraries that also wrap this
    42   * instance, then use reflection to invoke methods on this object. In
    43   * this case, an IllegalAccessException would occur if this class was
    44   * package-scoped. However this class is NOT intended to be part of the
    45   * public Orchestra API, and may change at any time.
    46   *
    47   * @since 1.1
    48   *
    49   * @author Manfred Geiler (latest modification by $Author: skitching $)
    50   * @author Anton Koinov
    51   * @version $Revision: 672906 $ $Date: 2008-06-30 15:45:16 -0500 (lun, 30 jun 2008) $
    52   */
    53  public class _FacesContextWrapper extends FacesContextWrapper
    54  {
    55      //~ Instance fields -------------------------------------------------------
    56
    57      private final FacesContext _facesContext;
    58
    59      //~ Constructors ----------------------------------------------------------
    60
    61      /**
    62       * The install parameter controls whether this object will be configured as
    63       * the object returned from calls to FacesContext.getCurrentInstance() or not.
    64       * <p>
    65       * When only overriding the release() method, then install=false is ok as that
    66       * is called directly by the FacesServlet on the instance returned by the
    67       * FacesContextFactory. However all other methods are invoked on the object
    68       * that is returned from FacesContext.getCurrentInstance, so install=true is
    69       * needed in order for any other method overrides to have any effect.
    70       * <p>
    71       * <b>IMPORTANT</b>: install=true should not be used until MYFACES-1820 is fixed.
    72       */
    73      public _FacesContextWrapper(FacesContext facesContext, boolean install)
    74      {
    75          _facesContext = facesContext;
    76
    77          if (install)
    78          {
    79              FacesContext.setCurrentInstance(this);
    80          }
    81      }
    82
    83      //~ Non-Final Methods -----------------------------------------------------
    84
    85      @Override
    86      public FacesContext getWrapped()
    87      {
    88          return _facesContext;
    89      }
    90
    91      //~ Final Methods ---------------------------------------------------------
    92
    93  }