Coverage Report - org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextAwareTagValueExpression
0%
0/54
N/A
2.222
 
 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.view.facelets.el;
 20  
 
 21  
 import java.io.Externalizable;
 22  
 import java.io.IOException;
 23  
 import java.io.ObjectInput;
 24  
 import java.io.ObjectOutput;
 25  
 
 26  
 import javax.el.ELContext;
 27  
 import javax.el.ELException;
 28  
 import javax.el.PropertyNotFoundException;
 29  
 import javax.el.PropertyNotWritableException;
 30  
 import javax.el.ValueExpression;
 31  
 import javax.faces.FacesWrapper;
 32  
 import javax.faces.view.Location;
 33  
 import javax.faces.view.facelets.TagAttribute;
 34  
 
 35  
 /**
 36  
  * 
 37  
  * 
 38  
  * @author Jacob Hookom
 39  
  * @version $Id$
 40  
  */
 41  0
 public class ContextAwareTagValueExpression
 42  
         extends ValueExpression
 43  
         implements Externalizable, FacesWrapper<ValueExpression>, ContextAware
 44  
 {
 45  
 
 46  
     private static final long serialVersionUID = 1L;
 47  
 
 48  
     private ValueExpression _wrapped; 
 49  
 
 50  
     private Location _location;
 51  
     
 52  
     private String _qName;
 53  
 
 54  
     public ContextAwareTagValueExpression()
 55  
     {
 56  0
         super();
 57  0
     }
 58  
 
 59  
     public ContextAwareTagValueExpression(TagAttribute tagAttribute, ValueExpression valueExpression)
 60  0
     {
 61  0
         _location = tagAttribute.getLocation();
 62  0
         _qName = tagAttribute.getQName();
 63  0
         _wrapped = valueExpression;
 64  0
     }
 65  
 
 66  
     public Class<?> getExpectedType()
 67  
     {
 68  0
         return _wrapped.getExpectedType();
 69  
     }
 70  
 
 71  
     public Class<?> getType(ELContext context)
 72  
     {
 73  
         try
 74  
         {
 75  0
             return _wrapped.getType(context);
 76  
         }
 77  0
         catch (PropertyNotFoundException pnfe)
 78  
         {
 79  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 80  
         }
 81  0
         catch (ELException e)
 82  
         {
 83  0
             throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
 84  
         }
 85  
         //Not necessary because NullPointerException by null context never occur and should not be wrapped
 86  
         //catch (Exception e)
 87  
         //{
 88  
         //    throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e); 
 89  
         //}
 90  
     }
 91  
 
 92  
     public Object getValue(ELContext context)
 93  
     {
 94  
         try
 95  
         {
 96  0
             return _wrapped.getValue(context);
 97  
         }
 98  0
         catch (PropertyNotFoundException pnfe)
 99  
         {
 100  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 101  
         }
 102  0
         catch (ELException e)
 103  
         {
 104  0
             throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
 105  
         }
 106  
         //Not necessary because NullPointerException by null context never occur and should not be wrapped
 107  
         //catch (Exception e)
 108  
         //{
 109  
         //    throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
 110  
         //}
 111  
     }
 112  
     
 113  
     private String getLocalExpressionString()
 114  
     {
 115  0
         String expressionString = null;
 116  
         try
 117  
         {
 118  0
             expressionString = getExpressionString();
 119  
         }
 120  0
         catch (Throwable t)
 121  
         {
 122  
             //swallo it because it is not important
 123  0
         }
 124  0
         return expressionString;
 125  
     }
 126  
 
 127  
     public boolean isReadOnly(ELContext context)
 128  
     {
 129  
         try
 130  
         {
 131  0
             return _wrapped.isReadOnly(context);
 132  
         }
 133  0
         catch (PropertyNotFoundException pnfe)
 134  
         {
 135  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 136  
         }
 137  0
         catch (ELException e)
 138  
         {
 139  0
             throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
 140  
         }
 141  
         //Not necessary because NullPointerException by null context never occur and should not be wrapped
 142  
         //catch (Exception e)
 143  
         //{
 144  
         //    throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
 145  
         //}
 146  
         
 147  
     }
 148  
 
 149  
     public void setValue(ELContext context, Object value)
 150  
     {
 151  
         try
 152  
         {
 153  0
             _wrapped.setValue(context, value);
 154  
         }
 155  0
         catch (PropertyNotFoundException pnfe)
 156  
         {
 157  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 158  
         }
 159  0
         catch (PropertyNotWritableException pnwe)
 160  
         {
 161  0
             throw new ContextAwarePropertyNotWritableException(getLocation(), getLocalExpressionString(),
 162  
                                                                getQName(), pnwe);
 163  
         }
 164  0
         catch (ELException e)
 165  
         {
 166  0
             throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
 167  0
         }
 168  
         //Not necessary because NullPointerException by null context never occur and should not be wrapped
 169  
         //catch (Exception e)
 170  
         //{
 171  
         //    throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
 172  
         //}
 173  0
     }
 174  
     
 175  
     public boolean equals(Object obj)
 176  
     {
 177  0
         return _wrapped.equals(obj);
 178  
     }
 179  
 
 180  
     public String getExpressionString()
 181  
     {
 182  0
         return _wrapped.getExpressionString();
 183  
     }
 184  
 
 185  
     public int hashCode()
 186  
     {
 187  0
         return _wrapped.hashCode();
 188  
     }
 189  
 
 190  
     public boolean isLiteralText()
 191  
     {
 192  0
         return _wrapped.isLiteralText();
 193  
     }
 194  
 
 195  
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 196  
     {
 197  0
         _wrapped = (ValueExpression) in.readObject();
 198  0
         _location = (Location) in.readObject();
 199  0
         _qName = in.readUTF();
 200  0
     }
 201  
 
 202  
     public void writeExternal(ObjectOutput out) throws IOException
 203  
     {
 204  0
         out.writeObject(_wrapped);
 205  0
         out.writeObject(_location);
 206  0
         out.writeUTF(_qName);
 207  0
     }
 208  
 
 209  
     public String toString()
 210  
     {
 211  0
         return _location + ": " + _wrapped;
 212  
     }
 213  
 
 214  
     public ValueExpression getWrapped()
 215  
     {
 216  0
         return _wrapped;
 217  
     }
 218  
 
 219  
     public Location getLocation()
 220  
     {
 221  0
         return _location;
 222  
     }
 223  
     
 224  
     public String getQName()
 225  
     {
 226  0
         return _qName;
 227  
     }
 228  
 }