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