Coverage Report - javax.faces.validator.MethodExpressionValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodExpressionValidator
0%
0/25
0%
0/4
1.857
 
 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.application.FacesMessage;
 25  
 import javax.faces.component.StateHolder;
 26  
 import javax.faces.component.UIComponent;
 27  
 import javax.faces.context.FacesContext;
 28  
 
 29  
 /**
 30  
  * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 31  
  *
 32  
  * @author Stan Silvert
 33  
  */
 34  
 public class MethodExpressionValidator implements Validator, StateHolder {
 35  
     
 36  
     private MethodExpression methodExpression;
 37  
     
 38  0
     private boolean isTransient = false;
 39  
     
 40  
     /** Creates a new instance of MethodExpressionValidator */
 41  0
     public MethodExpressionValidator() {
 42  0
     }
 43  
     
 44  0
     public MethodExpressionValidator(MethodExpression methodExpression) {
 45  0
         if (methodExpression == null) throw new NullPointerException("methodExpression can not be null.");
 46  
         
 47  0
         this.methodExpression = methodExpression;
 48  0
     }
 49  
 
 50  
     public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
 51  0
         Object[] params = new Object[3];
 52  0
         params[0] = context;
 53  0
         params[1] = component;
 54  0
         params[2] = value;
 55  
         
 56  
         try {
 57  0
             methodExpression.invoke(context.getELContext(), params);
 58  
         } 
 59  0
         catch (ELException e) {
 60  0
             Throwable cause = e.getCause();
 61  0
             if (cause instanceof ValidatorException) {
 62  0
                 throw (ValidatorException) cause;
 63  
             }
 64  
             else {
 65  0
                 throw e;
 66  
             }
 67  0
         }
 68  0
     }
 69  
 
 70  
     public void restoreState(FacesContext context, Object state) {
 71  0
         methodExpression = (MethodExpression)state;
 72  0
     }
 73  
 
 74  
     public Object saveState(FacesContext context) {
 75  0
         return methodExpression;
 76  
     }
 77  
 
 78  
     public void setTransient(boolean newTransientValue) {
 79  0
         isTransient = newTransientValue;
 80  0
     }
 81  
 
 82  
     public boolean isTransient() {
 83  0
         return isTransient;
 84  
     }
 85  
     
 86  
 }