Coverage Report - org.apache.myfaces.el.convert.VariableResolverToELResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
VariableResolverToELResolver
0%
0/44
0%
0/24
0
VariableResolverToELResolver$1
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.convert;
 20  
 
 21  
 import javax.el.ELContext;
 22  
 import javax.el.ELException;
 23  
 import javax.el.ELResolver;
 24  
 import javax.el.PropertyNotFoundException;
 25  
 import javax.el.PropertyNotWritableException;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.el.EvaluationException;
 28  
 import javax.faces.el.VariableResolver;
 29  
 
 30  
 import java.beans.FeatureDescriptor;
 31  
 import java.util.Collection;
 32  
 import java.util.HashSet;
 33  
 import java.util.Iterator;
 34  
 
 35  
 /**
 36  
  * Wrapper that converts a VariableResolver into an ELResolver. See JSF 1.2 spec section 5.6.1.5
 37  
  * 
 38  
  * @author Stan Silvert (latest modification by $Author$)
 39  
  * @author Mathias Broekelmann
 40  
  * @version $Revision$ $Date$
 41  
  */
 42  
 @SuppressWarnings("deprecation")
 43  
 public final class VariableResolverToELResolver extends ELResolver
 44  
 {
 45  
 
 46  
     // holds a flag to check if this instance is already called in current thread 
 47  0
     private static final ThreadLocal<Collection<String>> propertyGuard = new ThreadLocal<Collection<String>>() {
 48  
         @Override
 49  
         protected Collection<String> initialValue()
 50  
         {
 51  0
             return new HashSet<String>();
 52  
         }
 53  
     };
 54  
     
 55  
     private VariableResolver variableResolver;
 56  
 
 57  
     /**
 58  
      * Creates a new instance of VariableResolverToELResolver
 59  
      */
 60  
     public VariableResolverToELResolver(final VariableResolver variableResolver)
 61  0
     {
 62  0
         this.variableResolver = variableResolver;
 63  0
     }
 64  
     
 65  
     /**
 66  
      * @return the variableResolver
 67  
      */
 68  
     public VariableResolver getVariableResolver()
 69  
     {
 70  0
         return variableResolver;
 71  
     }
 72  
 
 73  
     public Object getValue(ELContext context, Object base, Object property) throws NullPointerException,
 74  
             PropertyNotFoundException, ELException
 75  
     {
 76  
 
 77  0
         if (base != null)
 78  0
             return null;
 79  0
         if (property == null)
 80  0
             throw new PropertyNotFoundException();
 81  
 
 82  0
         context.setPropertyResolved(true);
 83  
 
 84  0
         if (!(property instanceof String))
 85  0
             return null;
 86  
 
 87  0
         final String strProperty = (String) property;
 88  
 
 89  0
         Object result = null;
 90  
         try
 91  
         {
 92  
             // only call the resolver if we haven't done it in current stack
 93  0
             if(!propertyGuard.get().contains(strProperty)) {
 94  0
                 propertyGuard.get().add(strProperty);
 95  0
                 result = variableResolver.resolveVariable(facesContext(context), strProperty);
 96  
             }
 97  
         }
 98  0
         catch (javax.faces.el.PropertyNotFoundException e)
 99  
         {
 100  0
             context.setPropertyResolved(false);
 101  0
             throw new PropertyNotFoundException(e.getMessage(), e);
 102  
         }
 103  0
         catch (EvaluationException e)
 104  
         {
 105  0
             context.setPropertyResolved(false);
 106  0
             throw new ELException(e.getMessage(), e);
 107  
         }
 108  0
         catch (RuntimeException e)
 109  
         {
 110  0
             context.setPropertyResolved(false);
 111  0
             throw e;
 112  
         }
 113  
         finally
 114  
         {
 115  0
             propertyGuard.get().remove(strProperty);
 116  
             // set property resolved to false in any case if result is null
 117  0
             context.setPropertyResolved(result != null);
 118  0
         }
 119  
 
 120  0
         return result;
 121  
     }
 122  
 
 123  
     // get the FacesContext from the ELContext
 124  
     private static FacesContext facesContext(ELContext context)
 125  
     {
 126  0
         return (FacesContext) context.getContext(FacesContext.class);
 127  
     }
 128  
 
 129  
     public Class<?> getCommonPropertyType(ELContext context, Object base)
 130  
     {
 131  0
         if (base != null)
 132  0
             return null;
 133  
 
 134  0
         return String.class;
 135  
     }
 136  
 
 137  
     public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException,
 138  
             PropertyNotFoundException, PropertyNotWritableException, ELException
 139  
     {
 140  
 
 141  0
         if ((base == null) && (property == null))
 142  0
             throw new PropertyNotFoundException();
 143  0
     }
 144  
 
 145  
     public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException,
 146  
             PropertyNotFoundException, ELException
 147  
     {
 148  
 
 149  0
         if ((base == null) && (property == null))
 150  0
             throw new PropertyNotFoundException();
 151  
 
 152  0
         return false;
 153  
     }
 154  
 
 155  
     public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException,
 156  
             PropertyNotFoundException, ELException
 157  
     {
 158  
 
 159  0
         if ((base == null) && (property == null))
 160  0
             throw new PropertyNotFoundException();
 161  
 
 162  0
         return null;
 163  
     }
 164  
 
 165  
     public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
 166  
     {
 167  0
         return null;
 168  
     }
 169  
 
 170  
 }