Coverage Report - org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextAwareTagMethodExpression
0%
0/43
N/A
2
 
 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.MethodExpression;
 29  
 import javax.el.MethodInfo;
 30  
 import javax.el.MethodNotFoundException;
 31  
 import javax.el.PropertyNotFoundException;
 32  
 import javax.faces.FacesWrapper;
 33  
 import javax.faces.view.Location;
 34  
 import javax.faces.view.facelets.TagAttribute;
 35  
 
 36  
 /**
 37  
  * 
 38  
  * 
 39  
  * @author Jacob Hookom
 40  
  * @version $Id$
 41  
  */
 42  0
 public final class ContextAwareTagMethodExpression
 43  
         extends MethodExpression
 44  
         implements Externalizable, FacesWrapper<MethodExpression>, ContextAware
 45  
 {
 46  
 
 47  
     private static final long serialVersionUID = 1L;
 48  
 
 49  
     private MethodExpression _wrapped;
 50  
 
 51  
     private Location _location;
 52  
     
 53  
     private String _qName;
 54  
 
 55  
     public ContextAwareTagMethodExpression()
 56  
     {
 57  0
         super();
 58  0
     }
 59  
 
 60  
     public ContextAwareTagMethodExpression(TagAttribute tagAttribute, MethodExpression methodExpression)
 61  0
     {
 62  0
         _location = tagAttribute.getLocation();
 63  0
         _qName = tagAttribute.getQName();
 64  0
         _wrapped = methodExpression;
 65  0
     }
 66  
 
 67  
     public MethodInfo getMethodInfo(ELContext context)
 68  
     {
 69  
         try
 70  
         {
 71  0
             return _wrapped.getMethodInfo(context);
 72  
         }
 73  0
         catch (PropertyNotFoundException pnfe)
 74  
         {
 75  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 76  
         }
 77  0
         catch (MethodNotFoundException mnfe)
 78  
         {
 79  0
             throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
 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 invoke(ELContext context, Object[] params)
 93  
     {
 94  
         try
 95  
         {
 96  0
             return _wrapped.invoke(context, params);
 97  
         }
 98  0
         catch (PropertyNotFoundException pnfe)
 99  
         {
 100  0
             throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
 101  
         }
 102  0
         catch (MethodNotFoundException mnfe)
 103  
         {
 104  0
             throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
 105  
         }
 106  0
         catch (ELException e)
 107  
         {
 108  0
             throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
 109  
         }
 110  
         //Not necessary because NullPointerException by null context never occur and should not be wrapped
 111  
         //catch (Exception e)
 112  
         //{
 113  
         //    throw new ContextAwareException(getLocation(), getLocalExpressionString(), getQName(), e);
 114  
         //}
 115  
     }
 116  
     
 117  
         
 118  
     private String getLocalExpressionString()
 119  
     {
 120  0
         String expressionString = null;
 121  
         try
 122  
         {
 123  0
             expressionString = getExpressionString();
 124  
         }
 125  0
         catch (Throwable t)
 126  
         {
 127  
             //swallo it because it is not important
 128  0
         }
 129  0
         return expressionString;
 130  
     }
 131  
 
 132  
     public String getExpressionString()
 133  
     {
 134  0
         return _wrapped.getExpressionString();
 135  
     }
 136  
 
 137  
     public boolean equals(Object obj)
 138  
     {
 139  0
         return _wrapped.equals(obj);
 140  
     }
 141  
 
 142  
     public int hashCode()
 143  
     {
 144  0
         return _wrapped.hashCode();
 145  
     }
 146  
 
 147  
     public boolean isLiteralText()
 148  
     {
 149  0
         return _wrapped.isLiteralText();
 150  
     }
 151  
 
 152  
     public void writeExternal(ObjectOutput out) throws IOException
 153  
     {
 154  0
         out.writeObject(_wrapped);
 155  0
         out.writeObject(_location);
 156  0
         out.writeUTF(_qName);
 157  0
     }
 158  
 
 159  
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 160  
     {
 161  0
         _wrapped = (MethodExpression) in.readObject();
 162  0
         _location = (Location) in.readObject();
 163  0
         _qName = in.readUTF();
 164  0
     }
 165  
 
 166  
     public String toString()
 167  
     {
 168  0
         return _location + ": " + _wrapped;
 169  
     }
 170  
     
 171  
     public Location getLocation()
 172  
     {
 173  0
         return _location;
 174  
     }
 175  
     
 176  
     public String getQName()
 177  
     {
 178  0
         return _qName;
 179  
     }
 180  
     
 181  
     public MethodExpression getWrapped()
 182  
     {
 183  0
         return _wrapped;
 184  
     }
 185  
 
 186  
 }