Coverage Report - org.apache.myfaces.taglib.core.ValidatorTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorTag
0%
0/37
0%
0/12
3.6
 
 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.taglib.core;
 20  
 
 21  
 import javax.el.ELContext;
 22  
 import javax.el.ValueExpression;
 23  
 import javax.faces.application.Application;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.validator.Validator;
 26  
 import javax.faces.webapp.ValidatorELTag;
 27  
 import javax.servlet.jsp.JspException;
 28  
 
 29  
 /**
 30  
  * Basic Validator implementation.
 31  
  *
 32  
  * @author Andreas Berger (latest modification by $Author: skitching $)
 33  
  * @version $Revision: 684465 $ $Date: 2008-08-10 06:38:21 -0500 (Sun, 10 Aug 2008) $
 34  
  * @since 1.2
 35  
  */
 36  0
 public class ValidatorTag
 37  
         extends ValidatorELTag
 38  
 {
 39  
     private ValueExpression _validatorId;
 40  
     private ValueExpression _binding;
 41  0
     private String _validatorIdString = null;
 42  
 
 43  
     public void setValidatorId(ValueExpression validatorId)
 44  
     {
 45  0
         _validatorId = validatorId;
 46  0
     }
 47  
 
 48  
     public void setBinding(ValueExpression binding)
 49  
     {
 50  0
         _binding = binding;
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Use this method to specify the validatorId programmatically.
 55  
      *
 56  
      * @param validatorIdString
 57  
      */
 58  
     public void setValidatorIdString(String validatorIdString)
 59  
     {
 60  0
         _validatorIdString = validatorIdString;
 61  0
     }
 62  
 
 63  
     public void release()
 64  
     {
 65  0
         super.release();
 66  0
         _validatorId = null;
 67  0
         _binding = null;
 68  0
         _validatorIdString = null;
 69  0
     }
 70  
 
 71  
     protected Validator createValidator() throws javax.servlet.jsp.JspException
 72  
     {
 73  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 74  0
         ELContext elContext = facesContext.getELContext();
 75  0
         if (null != _binding)
 76  
         {
 77  
             Object validator;
 78  
             try
 79  
             {
 80  0
                 validator = _binding.getValue(elContext);
 81  0
             } catch (Exception e)
 82  
             {
 83  0
                 throw new JspException("Error while creating the Validator", e);
 84  0
             }
 85  0
             if (validator instanceof Validator)
 86  
             {
 87  0
                 return (Validator) validator;
 88  
             }
 89  
         }
 90  0
         Application application = facesContext.getApplication();
 91  0
         Validator validator = null;
 92  
         try
 93  
         {
 94  
             // first check if an ValidatorId was set by a method
 95  0
             if (null != _validatorIdString)
 96  
             {
 97  0
                 validator = application.createValidator(_validatorIdString);
 98  0
             } else if (null != _validatorId)
 99  
             {
 100  0
                 String validatorId = (String) _validatorId.getValue(elContext);
 101  0
                 validator = application.createValidator(validatorId);
 102  
             }
 103  0
         } catch (Exception e)
 104  
         {
 105  0
             throw new JspException("Error while creating the Validator", e);
 106  0
         }
 107  
 
 108  0
         if (null != validator)
 109  
         {
 110  0
             if (null != _binding)
 111  
             {
 112  0
                 _binding.setValue(elContext, validator);
 113  
             }
 114  0
             return validator;
 115  
         }
 116  0
         throw new JspException("validatorId and/or binding must be specified");
 117  
     }
 118  
 
 119  
 }