01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.mvc.validate;
08:
09: import java.lang.annotation.Annotation;
10:
11: /**
12: * @author <a href="mailto:jfox.young@gmail.com">Yang Yong</a>
13: */
14: public class FloatValidator implements Validator<Float> {
15:
16: public Float validate(String inputValue, Annotation validation)
17: throws ValidateException {
18: FloatValidation floatValidation = (FloatValidation) validation;
19: if (inputValue == null || inputValue.trim().length() == 0) {
20: if (!floatValidation.nullable()) {
21: throw new ValidateException("input can not be null!",
22: inputValue);
23: }
24:
25: }
26: try {
27: return Float.valueOf(inputValue);
28: } catch (NumberFormatException e) {
29: throw new ValidateException(
30: "Illegal float format for input: " + inputValue,
31: inputValue);
32: }
33:
34: }
35:
36: public static void main(String[] args) {
37:
38: }
39: }
|