Coverage Report - javax.faces.validator.MethodExpressionValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodExpressionValidator
0%
0/33
0%
0/12
2.429
 
 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.validator;
 21  
 
 22  
 import javax.el.ELException;
 23  
 import javax.el.MethodExpression;
 24  
 import javax.faces.component.StateHolder;
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.context.FacesContext;
 27  
 
 28  
 /**
 29  
  * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 30  
  */
 31  
 public class MethodExpressionValidator implements Validator, StateHolder
 32  
 {
 33  
 
 34  
     private MethodExpression methodExpression;
 35  
 
 36  0
     private boolean isTransient = false;
 37  
 
 38  
     /** Creates a new instance of MethodExpressionValidator */
 39  
     public MethodExpressionValidator()
 40  0
     {
 41  0
     }
 42  
 
 43  
     public MethodExpressionValidator(MethodExpression methodExpression)
 44  0
     {
 45  0
         if (methodExpression == null)
 46  
         {
 47  0
             throw new NullPointerException("methodExpression can not be null.");
 48  
         }
 49  
 
 50  0
         this.methodExpression = methodExpression;
 51  0
     }
 52  
 
 53  
     public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
 54  
     {
 55  0
         Object[] params = new Object[3];
 56  0
         params[0] = context;
 57  0
         params[1] = component;
 58  0
         params[2] = value;
 59  
 
 60  
         try
 61  
         {
 62  0
             methodExpression.invoke(context.getELContext(), params);
 63  
         }
 64  0
         catch (ELException e)
 65  
         {
 66  0
             Throwable cause = e.getCause();
 67  0
             ValidatorException vex = null;
 68  0
             if (cause != null)
 69  
             {
 70  
                 do
 71  
                 {
 72  0
                     if (cause != null && cause instanceof ValidatorException)
 73  
                     {
 74  0
                         vex = (ValidatorException) cause;
 75  0
                         break;
 76  
                     }
 77  0
                     cause = cause.getCause();
 78  
                 }
 79  0
                 while (cause != null);
 80  
             }
 81  0
             if (vex != null)
 82  
             {
 83  0
                 throw vex;
 84  
             }
 85  
             else
 86  
             {
 87  0
                 throw e;
 88  
             }
 89  
             //Throwable cause = e.getCause();
 90  
             //if (cause instanceof ValidatorException)
 91  
             //{
 92  
             //    throw (ValidatorException)cause;
 93  
             //}
 94  
             //else
 95  
             //{
 96  
             //    throw e;
 97  
             //}
 98  0
         }
 99  0
     }
 100  
 
 101  
     public void restoreState(FacesContext context, Object state)
 102  
     {
 103  0
         methodExpression = (MethodExpression)state;
 104  0
     }
 105  
 
 106  
     public Object saveState(FacesContext context)
 107  
     {
 108  0
         return methodExpression;
 109  
     }
 110  
 
 111  
     public void setTransient(boolean newTransientValue)
 112  
     {
 113  0
         isTransient = newTransientValue;
 114  0
     }
 115  
 
 116  
     public boolean isTransient()
 117  
     {
 118  0
         return isTransient;
 119  
     }
 120  
 
 121  
 }