Coverage Report - org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionActionListener
 
Classes in this File Line Coverage Branch Coverage Complexity
RedirectMethodExpressionValueExpressionActionListener
0%
0/22
0%
0/8
1.75
 
 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  
 import javax.el.ELContext;
 26  
 import javax.el.MethodExpression;
 27  
 import javax.el.ValueExpression;
 28  
 import javax.faces.FacesWrapper;
 29  
 import javax.faces.context.FacesContext;
 30  
 import javax.faces.event.AbortProcessingException;
 31  
 import javax.faces.event.ActionEvent;
 32  
 import javax.faces.event.ActionListener;
 33  
 
 34  
 /**
 35  
  *
 36  
  * @author Leonardo Uribe
 37  
  */
 38  0
 public class RedirectMethodExpressionValueExpressionActionListener
 39  
        implements ActionListener, FacesWrapper<ValueExpression>, Externalizable
 40  
 {
 41  
     private ValueExpression valueExpression;
 42  
 
 43  
     public RedirectMethodExpressionValueExpressionActionListener()
 44  0
     {
 45  0
     }
 46  
     
 47  
     public RedirectMethodExpressionValueExpressionActionListener(ValueExpression valueExpression)
 48  0
     {
 49  0
         this.valueExpression = valueExpression;
 50  0
     }
 51  
 
 52  
     public void processAction(ActionEvent actionEvent) throws AbortProcessingException
 53  
     {
 54  0
         getMethodExpression().invoke(FacesContext.getCurrentInstance().getELContext(), new Object[]{actionEvent});
 55  0
     }
 56  
     
 57  
     private MethodExpression getMethodExpression()
 58  
     {
 59  0
         return getMethodExpression(FacesContext.getCurrentInstance().getELContext());
 60  
     }
 61  
     
 62  
     private MethodExpression getMethodExpression(ELContext context)
 63  
     {
 64  0
         Object meOrVe = valueExpression.getValue(context);
 65  0
         if (meOrVe instanceof MethodExpression)
 66  
         {
 67  0
             return (MethodExpression) meOrVe;
 68  
         }
 69  0
         else if (meOrVe instanceof ValueExpression)
 70  
         {
 71  0
             while (meOrVe != null && meOrVe instanceof ValueExpression)
 72  
             {
 73  0
                 meOrVe = ((ValueExpression)meOrVe).getValue(context);
 74  
             }
 75  0
             return (MethodExpression) meOrVe;
 76  
         }
 77  
         else
 78  
         {
 79  0
             return null;
 80  
         }
 81  
     }
 82  
 
 83  
     public ValueExpression getWrapped()
 84  
     {
 85  0
         return valueExpression;
 86  
     }
 87  
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 88  
     {
 89  0
         this.valueExpression = (ValueExpression) in.readObject();
 90  0
     }
 91  
 
 92  
     public void writeExternal(ObjectOutput out) throws IOException
 93  
     {
 94  0
         out.writeObject(this.valueExpression);
 95  0
     }
 96  
 }