Coverage Report - org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueExpressionMethodExpression
0%
0/46
0%
0/28
2.769
 
 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.MethodExpression;
 28  
 import javax.el.MethodInfo;
 29  
 import javax.el.ValueExpression;
 30  
 import javax.faces.FacesWrapper;
 31  
 import javax.faces.context.FacesContext;
 32  
 
 33  
 /**
 34  
  * This MethodExpression contains a ValueExpression which resolves to 
 35  
  * the "real" MethodExpression that should be invoked. This is needed 
 36  
  * when the MethodExpression is on the parent composite component attribute map.
 37  
  * See FaceletViewDeclarationLanguage.retargetMethodExpressions() for details.
 38  
  * 
 39  
  * @author Jakob Korherr (latest modification by $Author$)
 40  
  * @version $Revision$ $Date$
 41  
  */
 42  0
 public class ValueExpressionMethodExpression extends MethodExpression 
 43  
     implements FacesWrapper<ValueExpression>, Externalizable
 44  
 {
 45  
     
 46  
     private static final long serialVersionUID = -2847633717581167765L;
 47  
     
 48  
     private ValueExpression valueExpression;
 49  
     
 50  
     public ValueExpressionMethodExpression()
 51  0
     {
 52  0
     }
 53  
     
 54  
     public ValueExpressionMethodExpression(ValueExpression valueExpression)
 55  0
     {
 56  0
         this.valueExpression = valueExpression;   
 57  0
     }
 58  
 
 59  
     @Override
 60  
     public MethodInfo getMethodInfo(ELContext context)
 61  
     {
 62  0
         MethodExpression me = getMethodExpression(context);
 63  0
         if (me != null)
 64  
         {
 65  0
             return me.getMethodInfo(context);
 66  
         }
 67  0
         return null;
 68  
     }
 69  
 
 70  
     @Override
 71  
     public Object invoke(ELContext context, Object[] params)
 72  
     {
 73  0
         MethodExpression me = getMethodExpression(context);
 74  0
         if (me != null)
 75  
         {        
 76  0
             return me.invoke(context, params);
 77  
         }
 78  0
         return null;
 79  
     }
 80  
 
 81  
     @Override
 82  
     public boolean equals(Object obj)
 83  
     {
 84  0
         MethodExpression me = getMethodExpression();
 85  0
         if (me != null)
 86  
         {        
 87  0
             return me.equals(obj);
 88  
         }
 89  0
         if (!(obj instanceof ValueExpressionMethodExpression))
 90  
         {
 91  0
             return false;
 92  
         }
 93  0
         ValueExpressionMethodExpression other = (ValueExpressionMethodExpression) obj;
 94  0
         if ((this.valueExpression == null && other.valueExpression != null) || 
 95  
              (this.valueExpression != null && !this.valueExpression.equals(other.valueExpression)))
 96  
         {
 97  0
             return false;
 98  
         }
 99  0
         return true;
 100  
     }
 101  
 
 102  
     @Override
 103  
     public String getExpressionString()
 104  
     {
 105  
         //getMethodExpression().getExpressionString()
 106  0
         return valueExpression.getExpressionString();
 107  
     }
 108  
 
 109  
     @Override
 110  
     public int hashCode()
 111  
     {
 112  0
         MethodExpression me = getMethodExpression();
 113  0
         if (me != null)
 114  
         {        
 115  0
             return me.hashCode();
 116  
         }
 117  0
         return valueExpression.hashCode();
 118  
     }
 119  
 
 120  
     @Override
 121  
     public boolean isLiteralText()
 122  
     {
 123  0
         MethodExpression me = getMethodExpression();
 124  0
         if (me != null)
 125  
         {
 126  0
             return me.isLiteralText();
 127  
         }
 128  0
         return valueExpression.isLiteralText();
 129  
     }
 130  
     
 131  
     private MethodExpression getMethodExpression()
 132  
     {
 133  0
         return getMethodExpression(FacesContext.getCurrentInstance().getELContext());
 134  
     }
 135  
     
 136  
     private MethodExpression getMethodExpression(ELContext context)
 137  
     {
 138  0
         Object meOrVe = valueExpression.getValue(context);
 139  0
         if (meOrVe instanceof MethodExpression)
 140  
         {
 141  0
             return (MethodExpression) meOrVe;
 142  
         }
 143  0
         else if (meOrVe instanceof ValueExpression)
 144  
         {
 145  0
             while (meOrVe != null && meOrVe instanceof ValueExpression)
 146  
             {
 147  0
                 meOrVe = ((ValueExpression)meOrVe).getValue(context);
 148  
             }
 149  0
             return (MethodExpression) meOrVe;
 150  
         }
 151  
         else
 152  
         {
 153  0
             return null;
 154  
         }
 155  
     }
 156  
 
 157  
     public ValueExpression getWrapped()
 158  
     {
 159  0
         return valueExpression;
 160  
     }
 161  
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 162  
     {
 163  0
         this.valueExpression = (ValueExpression) in.readObject();
 164  0
     }
 165  
 
 166  
     public void writeExternal(ObjectOutput out) throws IOException
 167  
     {
 168  0
         out.writeObject(this.valueExpression);
 169  0
     }
 170  
 }