Coverage Report - org.apache.myfaces.el.convert.ValueExpressionToValueBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueExpressionToValueBinding
0%
0/73
0%
0/30
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.convert;
 20  
 
 21  
 import javax.el.ELException;
 22  
 import javax.el.ValueExpression;
 23  
 import javax.faces.component.StateHolder;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.el.EvaluationException;
 26  
 import javax.faces.el.PropertyNotFoundException;
 27  
 import javax.faces.el.ValueBinding;
 28  
 
 29  
 import org.apache.myfaces.shared_impl.util.ClassUtils;
 30  
 
 31  
 /**
 32  
  * Converter for legacy ValueBinding objects. See JSF 1.2 section 5.8.3
 33  
  * 
 34  
  * ATTENTION: If you make changes to this class, treat javax.faces.component.ValueExpressionToValueBinding accordingly.
 35  
  * 
 36  
  * @author Stan Silvert
 37  
  * @see javax.faces.component.ValueExpressionToValueBinding
 38  
  */
 39  
 @SuppressWarnings("deprecation")
 40  
 public class ValueExpressionToValueBinding extends ValueBinding implements StateHolder
 41  
 {
 42  
 
 43  
     private ValueExpression _valueExpression;
 44  
 
 45  0
     private boolean isTransient = false;
 46  
 
 47  
     // required no-arg constructor for StateHolder
 48  
     public ValueExpressionToValueBinding()
 49  0
     {
 50  0
         _valueExpression = null;
 51  0
     }
 52  
 
 53  
     @Override
 54  
     public int hashCode()
 55  
     {
 56  0
         int result = 1;
 57  0
         result = 31 * result + ((_valueExpression == null) ? 0 : _valueExpression.hashCode());
 58  0
         result = 31 * result + (isTransient ? 1231 : 1237);
 59  0
         return result;
 60  
     }
 61  
 
 62  
     @Override
 63  
     public boolean equals(Object obj)
 64  
     {
 65  0
         if (this == obj)
 66  0
             return true;
 67  0
         if (obj == null)
 68  0
             return false;
 69  0
         if (getClass() != obj.getClass())
 70  0
             return false;
 71  0
         final ValueExpressionToValueBinding other = (ValueExpressionToValueBinding) obj;
 72  0
         if (_valueExpression == null)
 73  
         {
 74  0
             if (other._valueExpression != null)
 75  0
                 return false;
 76  
         }
 77  0
         else if (!_valueExpression.equals(other._valueExpression))
 78  0
             return false;
 79  0
         if (isTransient != other.isTransient)
 80  0
             return false;
 81  0
         return true;
 82  
     }
 83  
 
 84  
     /**
 85  
      * @return the valueExpression
 86  
      */
 87  
     public ValueExpression getValueExpression()
 88  
     {
 89  0
         return getNotNullValueExpression();
 90  
     }
 91  
 
 92  
     /**
 93  
      * @return the valueExpression
 94  
      */
 95  
     private ValueExpression getNotNullValueExpression()
 96  
     {
 97  0
         if (_valueExpression == null)
 98  
         {
 99  0
             throw new IllegalStateException("value expression is null");
 100  
         }
 101  0
         return _valueExpression;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public String getExpressionString()
 106  
     {
 107  0
         return getNotNullValueExpression().getExpressionString();
 108  
     }
 109  
 
 110  
     /** Creates a new instance of ValueExpressionToValueBinding */
 111  
     public ValueExpressionToValueBinding(ValueExpression valueExpression)
 112  0
     {
 113  0
         if (valueExpression == null)
 114  
         {
 115  0
             throw new IllegalArgumentException("value expression must not be null.");
 116  
         }
 117  0
         _valueExpression = valueExpression;
 118  0
     }
 119  
 
 120  
     @Override
 121  
     public void setValue(FacesContext facesContext, Object value) throws EvaluationException, PropertyNotFoundException
 122  
     {
 123  
         try
 124  
         {
 125  0
             getNotNullValueExpression().setValue(facesContext.getELContext(), value);
 126  
         }
 127  0
         catch (javax.el.PropertyNotFoundException e)
 128  
         {
 129  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 130  
         }
 131  0
         catch (ELException e)
 132  
         {
 133  0
             throw new EvaluationException(e);
 134  0
         }
 135  0
     }
 136  
 
 137  
     @Override
 138  
     public boolean isReadOnly(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 139  
     {
 140  
 
 141  
         try
 142  
         {
 143  0
             return getNotNullValueExpression().isReadOnly(facesContext.getELContext());
 144  
         }
 145  0
         catch (javax.el.PropertyNotFoundException e)
 146  
         {
 147  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 148  
         }
 149  0
         catch (ELException e)
 150  
         {
 151  0
             throw new EvaluationException(e);
 152  
         }
 153  
 
 154  
     }
 155  
 
 156  
     @Override
 157  
     public Object getValue(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 158  
     {
 159  
         try
 160  
         {
 161  0
             return getNotNullValueExpression().getValue(facesContext.getELContext());
 162  
         }
 163  0
         catch (javax.el.PropertyNotFoundException e)
 164  
         {
 165  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 166  
         }
 167  0
         catch (ELException e)
 168  
         {
 169  0
             throw new EvaluationException(e);
 170  
         }
 171  
     }
 172  
 
 173  
     @Override
 174  
     public Class getType(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 175  
     {
 176  
         try
 177  
         {
 178  0
             return getNotNullValueExpression().getType(facesContext.getELContext());
 179  
         }
 180  0
         catch (javax.el.PropertyNotFoundException e)
 181  
         {
 182  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 183  
         }
 184  0
         catch (ELException e)
 185  
         {
 186  0
             throw new EvaluationException(e);
 187  
         }
 188  
     }
 189  
 
 190  
     // -------- StateHolder methods -------------------------------------------
 191  
 
 192  
     public void restoreState(FacesContext facesContext, Object state)
 193  
     {
 194  0
         if (state != null)
 195  
         {
 196  0
             if (state instanceof ValueExpression)
 197  
             {
 198  0
                 _valueExpression = (ValueExpression) state;
 199  
             }
 200  
             else
 201  
             {
 202  0
                 Object[] stateArray = (Object[]) state;
 203  0
                 _valueExpression = (ValueExpression) ClassUtils.newInstance((String) stateArray[0],
 204  
                         ValueExpression.class);
 205  0
                 ((StateHolder) _valueExpression).restoreState(facesContext, stateArray[1]);
 206  
             }
 207  
         }
 208  0
     }
 209  
 
 210  
     public Object saveState(FacesContext context)
 211  
     {
 212  0
         if (!isTransient)
 213  
         {
 214  0
             if (_valueExpression instanceof StateHolder)
 215  
             {
 216  0
                 Object[] state = new Object[2];
 217  0
                 state[0] = _valueExpression.getClass().getName();
 218  0
                 state[1] = ((StateHolder) _valueExpression).saveState(context);
 219  0
                 return state;
 220  
             }
 221  
             else
 222  
             {
 223  0
                 return _valueExpression;
 224  
             }
 225  
         }
 226  0
         return null;
 227  
     }
 228  
 
 229  
     public void setTransient(boolean newTransientValue)
 230  
     {
 231  0
         isTransient = newTransientValue;
 232  0
     }
 233  
 
 234  
     public boolean isTransient()
 235  
     {
 236  0
         return isTransient;
 237  
     }
 238  
 
 239  
 }