Coverage Report - org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
FacesCompositeELResolver
0%
0/53
0%
0/14
0
FacesCompositeELResolver$Scope
0%
0/2
N/A
0
 
 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.el.unified.resolver;
 20  
 
 21  
 import org.apache.myfaces.el.VariableResolverImpl;
 22  
 
 23  
 import javax.el.ELContext;
 24  
 import javax.faces.application.Application;
 25  
 import javax.faces.context.FacesContext;
 26  
 import javax.servlet.jsp.JspApplicationContext;
 27  
 import java.beans.FeatureDescriptor;
 28  
 import java.util.Iterator;
 29  
 import java.util.Map;
 30  
 import java.util.Arrays;
 31  
 
 32  
 /**
 33  
  * <p>
 34  
  * This composite el resolver will be used at the top level resolver for faces ({@link Application#getELResolver()})
 35  
  * and jsp (the one we add with {@link JspApplicationContext#addELResolver(javax.el.ELResolver)}. It keeps track of its
 36  
  * scope to let the variable resolver {@link VariableResolverImpl} know in which scope it is executed. This is
 37  
  * necessarry to call either the faces or the jsp resolver head.
 38  
  * </p>
 39  
  * <p>
 40  
  * This implementation does nothing if there is no actual faces context. This is necessarry since we registered our
 41  
  * resolvers into the jsp engine. Therefore we have to make sure that jsp only pages where no faces context is available
 42  
  * are still working
 43  
  * </p>
 44  
  *
 45  
  * @author Mathias Broekelmann (latest modification by $Author: lu4242 $)
 46  
  * @version $Revision: 938283 $ $Date: 2010-04-26 20:18:21 -0500 (Mon, 26 Apr 2010) $
 47  
  */
 48  
 public final class FacesCompositeELResolver extends org.apache.myfaces.el.CompositeELResolver
 49  
 {
 50  
     private final Scope _scope;
 51  
 
 52  0
     public enum Scope
 53  
     {
 54  0
         Faces, JSP
 55  
     }
 56  
     
 57  
     public static final String SCOPE = "org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope";
 58  
 
 59  
     public FacesCompositeELResolver(final Scope scope)
 60  0
     {
 61  0
         if (scope == null)
 62  
         {
 63  0
             throw new IllegalArgumentException("scope must not be one of " + Arrays.toString(Scope.values()));
 64  
         }
 65  0
         _scope = scope;
 66  0
     }
 67  
 
 68  
     @Override
 69  
     public Class<?> getCommonPropertyType(final ELContext context, final Object base)
 70  
     {
 71  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 72  0
         if (facesContext == null)
 73  
         {
 74  0
             return null;
 75  
         }
 76  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 77  
         try
 78  
         {
 79  0
             setScope(requestMap);
 80  0
             return super.getCommonPropertyType(context, base);
 81  
         }
 82  
         finally
 83  
         {
 84  0
             unsetScope(requestMap);
 85  
         }
 86  
 
 87  
     }
 88  
 
 89  
     @Override
 90  
     public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base)
 91  
     {
 92  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 93  0
         if (facesContext == null)
 94  
         {
 95  0
             return null;
 96  
         }
 97  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 98  
         try
 99  
         {
 100  0
             setScope(requestMap);
 101  0
             return super.getFeatureDescriptors(context, base);
 102  
 
 103  
         }
 104  
         finally
 105  
         {
 106  0
             unsetScope(requestMap);
 107  
         }
 108  
     }
 109  
 
 110  
     @Override
 111  
     public Class<?> getType(final ELContext context, final Object base, final Object property)
 112  
     {
 113  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 114  0
         if (facesContext == null)
 115  
         {
 116  0
             return null;
 117  
         }
 118  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 119  
         try
 120  
         {
 121  0
             setScope(requestMap);
 122  0
             return super.getType(context, base, property);
 123  
         }
 124  
         finally
 125  
         {
 126  0
             unsetScope(requestMap);
 127  
         }
 128  
     }
 129  
 
 130  
     @Override
 131  
     public Object getValue(final ELContext context, final Object base, final Object property)
 132  
     {
 133  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 134  0
         if (facesContext == null)
 135  
         {
 136  0
             return null;
 137  
         }
 138  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 139  
         try
 140  
         {
 141  0
             setScope(requestMap);
 142  0
             return super.getValue(context, base, property);
 143  
         }
 144  
         finally
 145  
         {
 146  0
             unsetScope(requestMap);
 147  
         }
 148  
     }
 149  
 
 150  
     @Override
 151  
     public boolean isReadOnly(final ELContext context, final Object base, final Object property)
 152  
     {
 153  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 154  0
         if (facesContext == null)
 155  
         {
 156  0
             return false;
 157  
         }
 158  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 159  
         try
 160  
         {
 161  0
             setScope(requestMap);
 162  0
             return super.isReadOnly(context, base, property);
 163  
         }
 164  
         finally
 165  
         {
 166  0
             unsetScope(requestMap);
 167  
         }
 168  
     }
 169  
 
 170  
     @Override
 171  
     public void setValue(final ELContext context, final Object base, final Object property, final Object val)
 172  
     {
 173  0
         final FacesContext facesContext = FacesContext.getCurrentInstance();
 174  0
         if (facesContext == null)
 175  
         {
 176  0
             return;
 177  
         }
 178  0
         final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
 179  
         try
 180  
         {
 181  0
             setScope(requestMap);
 182  0
             super.setValue(context, base, property, val);
 183  
 
 184  
         }
 185  
         finally
 186  
         {
 187  0
             unsetScope(requestMap);
 188  0
         }
 189  0
     }
 190  
 
 191  
     private void setScope(final Map<String, Object> requestMap)
 192  
     {
 193  0
         requestMap.put(SCOPE, _scope);
 194  0
     }
 195  
 
 196  
     private static void unsetScope(final Map<String, Object> requestMap)
 197  
     {
 198  0
         requestMap.remove(SCOPE);
 199  0
     }
 200  
 }