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$)
 33  
  * @version $Revision$ $Date$
 34  
  * @since 1.2
 35  
  */
 36  0
 public class ValidatorTag extends ValidatorELTag
 37  
 {
 38  
     private ValueExpression _validatorId;
 39  
     private ValueExpression _binding;
 40  0
     private String _validatorIdString = null;
 41  
 
 42  
     public void setValidatorId(ValueExpression validatorId)
 43  
     {
 44  0
         _validatorId = validatorId;
 45  0
     }
 46  
 
 47  
     public void setBinding(ValueExpression binding)
 48  
     {
 49  0
         _binding = binding;
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Use this method to specify the validatorId programmatically.
 54  
      * 
 55  
      * @param validatorIdString
 56  
      */
 57  
     public void setValidatorIdString(String validatorIdString)
 58  
     {
 59  0
         _validatorIdString = validatorIdString;
 60  0
     }
 61  
 
 62  
     @Override
 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  
     @Override
 72  
     protected Validator createValidator() throws javax.servlet.jsp.JspException
 73  
     {
 74  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 75  0
         ELContext elContext = facesContext.getELContext();
 76  0
         if (null != _binding)
 77  
         {
 78  
             Object validator;
 79  
             try
 80  
             {
 81  0
                 validator = _binding.getValue(elContext);
 82  
             }
 83  0
             catch (Exception e)
 84  
             {
 85  0
                 throw new JspException("Error while creating the Validator", e);
 86  0
             }
 87  0
             if (validator instanceof Validator)
 88  
             {
 89  0
                 return (Validator)validator;
 90  
             }
 91  
         }
 92  0
         Application application = facesContext.getApplication();
 93  0
         Validator validator = null;
 94  
         try
 95  
         {
 96  
             // first check if an ValidatorId was set by a method
 97  0
             if (null != _validatorIdString)
 98  
             {
 99  0
                 validator = application.createValidator(_validatorIdString);
 100  
             }
 101  0
             else if (null != _validatorId)
 102  
             {
 103  0
                 String validatorId = (String)_validatorId.getValue(elContext);
 104  0
                 validator = application.createValidator(validatorId);
 105  
             }
 106  
         }
 107  0
         catch (Exception e)
 108  
         {
 109  0
             throw new JspException("Error while creating the Validator", e);
 110  0
         }
 111  
 
 112  0
         if (null != validator)
 113  
         {
 114  0
             if (null != _binding)
 115  
             {
 116  0
                 _binding.setValue(elContext, validator);
 117  
             }
 118  0
             return validator;
 119  
         }
 120  0
         throw new JspException("validatorId and/or binding must be specified");
 121  
     }
 122  
 
 123  
 }