Coverage Report - org.apache.myfaces.el.PropertyResolverImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyResolverImpl
0%
0/42
0%
0/36
0
PropertyResolverImpl$1
0%
0/2
N/A
0
PropertyResolverImpl$2
0%
0/4
N/A
0
PropertyResolverImpl$3
0%
0/2
N/A
0
PropertyResolverImpl$4
0%
0/2
N/A
0
PropertyResolverImpl$ResolverInvoker
0%
0/5
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;
 20  
 
 21  
 import java.util.List;
 22  
 
 23  
 import javax.el.ELContext;
 24  
 import javax.el.ELException;
 25  
 import javax.el.ELResolver;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.el.EvaluationException;
 28  
 import javax.faces.el.PropertyNotFoundException;
 29  
 import javax.faces.el.PropertyResolver;
 30  
 
 31  
 /**
 32  
  * @author Manfred Geiler (latest modification by $Author: bommel $)
 33  
  * @author Anton Koinov
 34  
  * @version $Revision: 693059 $ $Date: 2008-09-08 06:42:28 -0500 (Mon, 08 Sep 2008) $
 35  
  */
 36  
 @SuppressWarnings("deprecation")
 37  0
 public final class PropertyResolverImpl extends PropertyResolver
 38  
 {
 39  
     // ~ Public PropertyResolver Methods
 40  
     // ----------------------------------------
 41  
 
 42  
     @Override
 43  
     public Object getValue(final Object base, final Object property) throws EvaluationException,
 44  
             PropertyNotFoundException
 45  
     {
 46  0
         return invokeResolver(new ResolverInvoker<Object>(base, property)
 47  0
         {
 48  
             public Object invoke(ELResolver resolver, ELContext context)
 49  
             {
 50  0
                 return getELResolver().getValue(getELContext(), base, property);
 51  
             }
 52  
         });
 53  
     }
 54  
 
 55  
     @Override
 56  
     public Object getValue(final Object base, final int index) throws EvaluationException, PropertyNotFoundException
 57  
     {
 58  0
         return getValue(base, Integer.valueOf(index));
 59  
     }
 60  
 
 61  
     @Override
 62  
     public void setValue(final Object base, final Object property, final Object newValue) throws EvaluationException,
 63  
             PropertyNotFoundException
 64  
     {
 65  0
         if (base == null || property == null)
 66  0
             throw new PropertyNotFoundException();
 67  
         
 68  0
         invokeResolver(new ResolverInvoker<Object>(base, property)
 69  0
         {
 70  
             @Override
 71  
             public Object invoke(ELResolver resolver, ELContext context)
 72  
             {
 73  0
                 resolver.setValue(context, base, property, newValue);
 74  0
                 return null;
 75  
             }
 76  
 
 77  
             @Override
 78  
             String getMessage()
 79  
             {
 80  0
                 return super.getMessage() + " newValue: '" + newValue + "'";
 81  
             }
 82  
         });
 83  0
     }
 84  
 
 85  
     @Override
 86  
     public void setValue(Object base, int index, Object newValue) throws EvaluationException, PropertyNotFoundException
 87  
     {
 88  0
         if (base == null)
 89  0
             throw new PropertyNotFoundException();
 90  
         
 91  0
         if (base instanceof Object[]) {
 92  0
             if (index < 0 || index>=((Object[])base).length) {
 93  0
                 throw new PropertyNotFoundException();
 94  
             }
 95  0
         } else if (base instanceof List) {
 96  0
             if (index < 0 || index>=((List)base).size()) {
 97  0
                 throw new PropertyNotFoundException();
 98  
             }
 99  
         }
 100  
         
 101  0
         setValue(base, Integer.valueOf(index), newValue);
 102  0
     }
 103  
 
 104  
     @Override
 105  
     public boolean isReadOnly(final Object base, final Object property)
 106  
     {
 107  0
         return invokeResolver(new ResolverInvoker<Boolean>(base, property)
 108  0
         {
 109  
             public Boolean invoke(ELResolver resolver, ELContext context)
 110  
             {
 111  0
                 return Boolean.valueOf(getELResolver().isReadOnly(getELContext(), base, property));
 112  
             }
 113  
         });
 114  
     }
 115  
 
 116  
     @Override
 117  
     public boolean isReadOnly(final Object base, final int index)
 118  
     {
 119  0
         return isReadOnly(base, Integer.valueOf(index));
 120  
     }
 121  
 
 122  
     @Override
 123  
     public Class getType(final Object base, final Object property)
 124  
     {
 125  0
         if (base == null || property == null)
 126  0
             throw new PropertyNotFoundException();
 127  
         
 128  0
         return invokeResolver(new ResolverInvoker<Class>(base, property)
 129  0
         {
 130  
             public Class invoke(final ELResolver resolver, final ELContext context)
 131  
             {
 132  0
                 return resolver.getType(context, base, property);
 133  
             }
 134  
         });
 135  
     }
 136  
 
 137  
     @Override
 138  
     public Class getType(Object base, int index)
 139  
     {
 140  0
         if (base == null)
 141  0
             throw new PropertyNotFoundException();
 142  
         
 143  0
         if (base instanceof Object[]) {
 144  0
             if (index < 0 || index>=((Object[])base).length) {
 145  0
                 throw new PropertyNotFoundException();
 146  
             }
 147  0
         } else if (base instanceof List) {
 148  0
             if (index < 0 || index>=((List)base).size()) {
 149  0
                 throw new PropertyNotFoundException();
 150  
             }
 151  
         }
 152  
         
 153  0
         return getType(base, Integer.valueOf(index));
 154  
     }
 155  
     
 156  
     // ~ Internal Helper Methods
 157  
     // ------------------------------------------------
 158  
 
 159  
     ELContext getELContext()
 160  
     {
 161  0
         return getFacesContext().getELContext();
 162  
     }
 163  
 
 164  
     ELResolver getELResolver()
 165  
     {
 166  0
         return getFacesContext().getApplication().getELResolver();
 167  
     }
 168  
 
 169  
     FacesContext getFacesContext()
 170  
     {
 171  0
         return FacesContext.getCurrentInstance();
 172  
     }
 173  
 
 174  
     <T> T invokeResolver(ResolverInvoker<T> invoker) throws EvaluationException, PropertyNotFoundException
 175  
     {
 176  
         try
 177  
         {
 178  0
             return invoker.invoke(getELResolver(), getELContext());
 179  
         }
 180  0
         catch (javax.el.PropertyNotFoundException e)
 181  
         {
 182  0
             throw new PropertyNotFoundException("property not found: " + invoker.getMessage() + ": " + e.getMessage(),
 183  
                     e);
 184  
         }
 185  0
         catch (ELException e)
 186  
         {
 187  0
             throw new EvaluationException("exception: " + invoker.getMessage() + ": " + e.getMessage(), e);
 188  
         }
 189  0
         catch (RuntimeException e)
 190  
         {
 191  0
             throw new RuntimeException("runtime exception: " + invoker.getMessage() + ": " + e.getMessage(), e);
 192  
         }
 193  
     }
 194  
 
 195  0
     abstract static class ResolverInvoker<T>
 196  
     {
 197  
         private final Object _base;
 198  
         private final Object _property;
 199  
 
 200  
         ResolverInvoker(final Object base, final Object property)
 201  0
         {
 202  0
             _base = base;
 203  0
             _property = property;
 204  0
         }
 205  
 
 206  
         abstract T invoke(ELResolver resolver, ELContext context);
 207  
 
 208  
         String getMessage()
 209  
         {
 210  0
             return "base: '" + _base + "' property/index: '" + _property + "'";
 211  
         }
 212  
     }
 213  
 }