Coverage Report - org.seasar.teeda.core.taglib.core.ValidateDoubleRangeTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateDoubleRangeTag
100%
28/28
100%
12/12
3
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.taglib.core;
 17  
 
 18  
 import javax.faces.context.FacesContext;
 19  
 import javax.faces.el.ValueBinding;
 20  
 import javax.faces.internal.ValueBindingUtil;
 21  
 import javax.faces.validator.DoubleRangeValidator;
 22  
 import javax.faces.validator.Validator;
 23  
 import javax.servlet.jsp.JspException;
 24  
 
 25  
 import org.seasar.framework.util.AssertionUtil;
 26  
 import org.seasar.teeda.core.util.BindingUtil;
 27  
 import org.seasar.teeda.core.util.ConverterUtil;
 28  
 
 29  
 /**
 30  
  * @author yone
 31  
  * @author shot
 32  
  */
 33  
 public class ValidateDoubleRangeTag extends MaxMinValidatorTag {
 34  
 
 35  
     private static final long serialVersionUID = 1L;
 36  
 
 37  
     private static final String VALIDATOR_ID = DoubleRangeValidator.VALIDATOR_ID;
 38  
 
 39  7
     protected double minimum = 0;
 40  
 
 41  7
     protected double maximum = 0;
 42  
 
 43  
     public ValidateDoubleRangeTag() {
 44  7
         super();
 45  7
     }
 46  
 
 47  
     protected Validator createValidator() throws JspException {
 48  7
         super.setValidatorId(VALIDATOR_ID);
 49  7
         DoubleRangeValidator validator = null;
 50  7
         validator = (DoubleRangeValidator) super.createValidator();
 51  7
         AssertionUtil.assertNotNull("DoubleRangeValidator", validator);
 52  
 
 53  6
         evaluateExpressions();
 54  6
         if (isMinimumSet()) {
 55  2
             validator.setMinimum(minimum);
 56  
         }
 57  6
         if (isMaximumSet()) {
 58  2
             validator.setMaximum(maximum);
 59  
         }
 60  6
         return validator;
 61  
     }
 62  
 
 63  
     private void evaluateExpressions() throws JspException {
 64  6
         FacesContext context = FacesContext.getCurrentInstance();
 65  6
         final String min = getMinimum();
 66  6
         if (min != null) {
 67  2
             if (BindingUtil.isValueReference(min)) {
 68  1
                 ValueBinding vb = ValueBindingUtil.createValueBinding(context,
 69  
                         min);
 70  1
                 minimum = ConverterUtil.convertToDouble(vb.getValue(context));
 71  
             } else {
 72  1
                 minimum = ConverterUtil.convertToDouble(min);
 73  
             }
 74  
         }
 75  6
         final String max = getMaximum();
 76  6
         if (max != null) {
 77  2
             if (BindingUtil.isValueReference(max)) {
 78  1
                 ValueBinding vb = context.getApplication().createValueBinding(
 79  
                         max);
 80  1
                 maximum = ConverterUtil.convertToDouble(vb.getValue(context));
 81  
             } else {
 82  1
                 maximum = ConverterUtil.convertToDouble(max);
 83  
             }
 84  
         }
 85  6
     }
 86  
 }