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