Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.el » [javadoc | source]
    1   /*
    2    * $Id: FacesCompositeELResolver.java,v 1.8.4.1 2007/12/17 21:14:35 rlubke Exp $
    3    */
    4   /*
    5    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    6    * 
    7    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    8    * 
    9    * The contents of this file are subject to the terms of either the GNU
   10    * General Public License Version 2 only ("GPL") or the Common Development
   11    * and Distribution License("CDDL") (collectively, the "License").  You
   12    * may not use this file except in compliance with the License. You can obtain
   13    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   14    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   15    * language governing permissions and limitations under the License.
   16    * 
   17    * When distributing the software, include this License Header Notice in each
   18    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   19    * Sun designates this particular file as subject to the "Classpath" exception
   20    * as provided by Sun in the GPL Version 2 section of the License file that
   21    * accompanied this code.  If applicable, add the following below the License
   22    * Header, with the fields enclosed by brackets [] replaced by your own
   23    * identifying information: "Portions Copyrighted [year]
   24    * [name of copyright owner]"
   25    * 
   26    * Contributor(s):
   27    * 
   28    * If you wish your version of this file to be governed by only the CDDL or
   29    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   30    * elects to include this software in this distribution under the [CDDL or GPL
   31    * Version 2] license."  If you don't indicate a single choice of license, a
   32    * recipient has the option to distribute your version of this file under
   33    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   34    * its licensees as provided above.  However, if you add GPL Version 2 code
   35    * and therefore, elected the GPL Version 2 license, then the option applies
   36    * only if the new code is made subject to such option by the copyright
   37    * holder.
   38    */
   39   
   40   package com.sun.faces.el;
   41   
   42   import com.sun.faces.util.RequestStateManager;
   43   
   44   import java.beans.FeatureDescriptor;
   45   import java.util.Iterator;
   46   
   47   import javax.el.ELResolver;
   48   import javax.el.ELContext;
   49   import javax.el.CompositeELResolver;
   50   import javax.el.ELException;
   51   
   52   import javax.faces.context.FacesContext;
   53   
   54   /**
   55    * Maintains an ordered composite list of child <code>ELResolver for JSF</code>.
   56    *
   57    */
   58   public class FacesCompositeELResolver extends CompositeELResolver {
   59       
   60       public void add(ELResolver elResolver) {                                                                             
   61           super.add(elResolver);
   62       }
   63   
   64       public Object getValue(ELContext context, Object base, Object property) 
   65           throws ELException {
   66           
   67           context.setPropertyResolved(false);
   68           if (FacesContext.getCurrentInstance() == null) {
   69               return null;
   70           }                    
   71           setChainType();
   72           Object result = super.getValue(context, base, property);
   73           clearChainType();
   74           
   75           return result;
   76       }
   77   
   78       public Class<?> getType(ELContext context, Object base, Object property) 
   79           throws ELException {
   80   
   81           context.setPropertyResolved(false);
   82           if (FacesContext.getCurrentInstance() == null) {
   83               return null;
   84           }
   85           setChainType();
   86           Class<?> result = super.getType(context, base, property);
   87           clearChainType();
   88   
   89           return result;
   90       }
   91   
   92       
   93       public void setValue(ELContext context, Object base, Object property,
   94           Object val) throws ELException {
   95           context.setPropertyResolved(false);
   96           if (FacesContext.getCurrentInstance() == null) {
   97               return;
   98           }
   99           setChainType();
  100           super.setValue(context, base, property, val);
  101           clearChainType();
  102       }
  103   
  104       
  105       public boolean isReadOnly(ELContext context, Object base, Object property) 
  106           throws ELException {
  107           context.setPropertyResolved(false);
  108           if (FacesContext.getCurrentInstance() == null) {
  109               return false;
  110           }
  111           setChainType();
  112           boolean result = super.isReadOnly(context, base, property);
  113           clearChainType();
  114           return result;
  115       }
  116   
  117       
  118       public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
  119           setChainType();
  120           Iterator<FeatureDescriptor> result = super.getFeatureDescriptors(context, base);
  121           clearChainType();
  122           return result;
  123       }
  124       
  125       public Class<?> getCommonPropertyType(ELContext context, Object base) {
  126           return null;
  127       }
  128   
  129       /**
  130        * <p><b>JSP</b> indicates this CompositeELResolver instance is the
  131        * JSP chain, specified in section 5.6.1 of the spec.</p>
  132        *
  133        * <p><b>Faces</b> indicates this CompositeELResolver instance is the
  134        * JSF chain, specified in section 5.6.2 of the spec.</p>
  135        */
  136   
  137       public enum ELResolverChainType {
  138           JSP,
  139           Faces
  140       }
  141   
  142       private ELResolverChainType chainType;
  143   
  144       /**
  145        * <p>Guarantee that this instance knows of what chain it is a
  146        * member.</p>
  147        * @param chainType the {@link ELResolverChainType} 
  148        */
  149       public FacesCompositeELResolver(ELResolverChainType chainType) {
  150           this.chainType = chainType;
  151       }
  152   
  153       /**
  154        * <p>Set a request scoped attribute indicating what kind of chain
  155        * the current expression is.</p>
  156        */
  157   
  158       private void setChainType() {
  159           RequestStateManager.set(FacesContext.getCurrentInstance(),
  160                                   RequestStateManager.EL_RESOLVER_CHAIN_TYPE_NAME,
  161                                   chainType);
  162       }
  163   
  164       /**
  165        * <p>Clear the request scoped attribute indicating what kind of
  166        * chain the current expression is.</p>
  167        */
  168       
  169       private void clearChainType() {
  170           RequestStateManager.remove(FacesContext.getCurrentInstance(),
  171                                      RequestStateManager.EL_RESOLVER_CHAIN_TYPE_NAME);
  172       }
  173   
  174   }
  175   

Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.el » [javadoc | source]