Coverage Report - org.apache.myfaces.el.convert.ValueExpressionToValueBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueExpressionToValueBinding
0%
0/73
0%
0/30
3.933
 
 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.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 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  
         {
 67  0
             return true;
 68  
         }
 69  0
         if (obj == null)
 70  
         {
 71  0
             return false;
 72  
         }
 73  0
         if (getClass() != obj.getClass())
 74  
         {
 75  0
             return false;
 76  
         }
 77  0
         final ValueExpressionToValueBinding other = (ValueExpressionToValueBinding) obj;
 78  0
         if (_valueExpression == null)
 79  
         {
 80  0
             if (other._valueExpression != null)
 81  
             {
 82  0
                 return false;
 83  
             }
 84  
         }
 85  0
         else if (!_valueExpression.equals(other._valueExpression))
 86  
         {
 87  0
             return false;
 88  
         }
 89  0
         if (isTransient != other.isTransient)
 90  
         {
 91  0
             return false;
 92  
         }
 93  0
         return true;
 94  
     }
 95  
 
 96  
     /**
 97  
      * @return the valueExpression
 98  
      */
 99  
     public ValueExpression getValueExpression()
 100  
     {
 101  0
         return getNotNullValueExpression();
 102  
     }
 103  
 
 104  
     /**
 105  
      * @return the valueExpression
 106  
      */
 107  
     private ValueExpression getNotNullValueExpression()
 108  
     {
 109  0
         if (_valueExpression == null)
 110  
         {
 111  0
             throw new IllegalStateException("value expression is null");
 112  
         }
 113  0
         return _valueExpression;
 114  
     }
 115  
 
 116  
     @Override
 117  
     public String getExpressionString()
 118  
     {
 119  0
         return getNotNullValueExpression().getExpressionString();
 120  
     }
 121  
 
 122  
     /** Creates a new instance of ValueExpressionToValueBinding */
 123  
     public ValueExpressionToValueBinding(ValueExpression valueExpression)
 124  0
     {
 125  0
         if (valueExpression == null)
 126  
         {
 127  0
             throw new IllegalArgumentException("value expression must not be null.");
 128  
         }
 129  0
         _valueExpression = valueExpression;
 130  0
     }
 131  
 
 132  
     @Override
 133  
     public void setValue(FacesContext facesContext, Object value) throws EvaluationException, PropertyNotFoundException
 134  
     {
 135  
         try
 136  
         {
 137  0
             getNotNullValueExpression().setValue(facesContext.getELContext(), value);
 138  
         }
 139  0
         catch (javax.el.PropertyNotFoundException e)
 140  
         {
 141  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 142  
         }
 143  0
         catch (ELException e)
 144  
         {
 145  0
             throw new EvaluationException(e);
 146  0
         }
 147  0
     }
 148  
 
 149  
     @Override
 150  
     public boolean isReadOnly(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 151  
     {
 152  
 
 153  
         try
 154  
         {
 155  0
             return getNotNullValueExpression().isReadOnly(facesContext.getELContext());
 156  
         }
 157  0
         catch (javax.el.PropertyNotFoundException e)
 158  
         {
 159  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 160  
         }
 161  0
         catch (ELException e)
 162  
         {
 163  0
             throw new EvaluationException(e);
 164  
         }
 165  
 
 166  
     }
 167  
 
 168  
     @Override
 169  
     public Object getValue(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 170  
     {
 171  
         try
 172  
         {
 173  0
             return getNotNullValueExpression().getValue(facesContext.getELContext());
 174  
         }
 175  0
         catch (javax.el.PropertyNotFoundException e)
 176  
         {
 177  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 178  
         }
 179  0
         catch (ELException e)
 180  
         {
 181  0
             throw new EvaluationException(e);
 182  
         }
 183  
     }
 184  
 
 185  
     @Override
 186  
     public Class getType(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException
 187  
     {
 188  
         try
 189  
         {
 190  0
             return getNotNullValueExpression().getType(facesContext.getELContext());
 191  
         }
 192  0
         catch (javax.el.PropertyNotFoundException e)
 193  
         {
 194  0
             throw new javax.faces.el.PropertyNotFoundException(e);
 195  
         }
 196  0
         catch (ELException e)
 197  
         {
 198  0
             throw new EvaluationException(e);
 199  
         }
 200  
     }
 201  
 
 202  
     // -------- StateHolder methods -------------------------------------------
 203  
 
 204  
     public void restoreState(FacesContext facesContext, Object state)
 205  
     {
 206  0
         if (state != null)
 207  
         {
 208  0
             if (state instanceof ValueExpression)
 209  
             {
 210  0
                 _valueExpression = (ValueExpression) state;
 211  
             }
 212  
             else
 213  
             {
 214  0
                 Object[] stateArray = (Object[]) state;
 215  0
                 _valueExpression
 216  
                         = (ValueExpression) ClassUtils.newInstance((String) stateArray[0], ValueExpression.class);
 217  0
                 ((StateHolder) _valueExpression).restoreState(facesContext, stateArray[1]);
 218  
             }
 219  
         }
 220  0
     }
 221  
 
 222  
     public Object saveState(FacesContext context)
 223  
     {
 224  0
         if (!isTransient)
 225  
         {
 226  0
             if (_valueExpression instanceof StateHolder)
 227  
             {
 228  0
                 Object[] state = new Object[2];
 229  0
                 state[0] = _valueExpression.getClass().getName();
 230  0
                 state[1] = ((StateHolder) _valueExpression).saveState(context);
 231  0
                 return state;
 232  
             }
 233  
             else
 234  
             {
 235  0
                 return _valueExpression;
 236  
             }
 237  
         }
 238  0
         return null;
 239  
     }
 240  
 
 241  
     public void setTransient(boolean newTransientValue)
 242  
     {
 243  0
         isTransient = newTransientValue;
 244  0
     }
 245  
 
 246  
     public boolean isTransient()
 247  
     {
 248  0
         return isTransient;
 249  
     }
 250  
 
 251  
 }