KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > validator > TestTypeValidator


1 /*
2  * $Id: TestTypeValidator.java 164749 2005-04-26 06:15:17Z mrdon $
3  * $Rev$
4  * $Date: 2005-04-25 23:15:17 -0700 (Mon, 25 Apr 2005) $
5  *
6  * ====================================================================
7  * Copyright 2001-2005 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package org.apache.commons.validator;
23
24 import java.util.Locale JavaDoc;
25
26 import org.apache.commons.validator.util.ValidatorUtils;
27                                                           
28 /**
29  * Contains validation methods for different unit tests.
30  */

31 public class TestTypeValidator {
32
33    /**
34     * Checks if the field can be successfully converted to a <code>byte</code>.
35     *
36     * @param value The value validation is being performed on.
37     * @return boolean If the field can be successfully converted
38     * to a <code>byte</code> <code>true</code> is returned.
39     * Otherwise <code>false</code>.
40     */

41    public static Byte JavaDoc validateByte(Object JavaDoc bean, Field field) {
42       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
43
44       return GenericTypeValidator.formatByte(value);
45    }
46
47    /**
48     * Checks if the field can be successfully converted to a <code>byte</code>.
49     *
50     * @param value The value validation is being performed on.
51     * @return boolean If the field can be successfully converted
52     * to a <code>byte</code> <code>true</code> is returned.
53     * Otherwise <code>false</code>.
54     */

55    public static Byte JavaDoc validateByte(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
56       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
57
58       return GenericTypeValidator.formatByte(value, locale);
59    }
60
61    /**
62     * Checks if the field can be successfully converted to a <code>short</code>.
63     *
64     * @param value The value validation is being performed on.
65     * @return boolean If the field can be successfully converted
66     * to a <code>short</code> <code>true</code> is returned.
67     * Otherwise <code>false</code>.
68     */

69    public static Short JavaDoc validateShort(Object JavaDoc bean, Field field) {
70       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
71
72       return GenericTypeValidator.formatShort(value);
73    }
74
75    /**
76     * Checks if the field can be successfully converted to a <code>short</code>.
77     *
78     * @param value The value validation is being performed on.
79     * @return boolean If the field can be successfully converted
80     * to a <code>short</code> <code>true</code> is returned.
81     * Otherwise <code>false</code>.
82     */

83    public static Short JavaDoc validateShort(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
84       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
85
86       return GenericTypeValidator.formatShort(value, locale);
87    }
88
89    /**
90     * Checks if the field can be successfully converted to a <code>int</code>.
91     *
92     * @param value The value validation is being performed on.
93     * @return boolean If the field can be successfully converted
94     * to a <code>int</code> <code>true</code> is returned.
95     * Otherwise <code>false</code>.
96     */

97    public static Integer JavaDoc validateInt(Object JavaDoc bean, Field field) {
98       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
99
100       return GenericTypeValidator.formatInt(value);
101    }
102
103    /**
104     * Checks if the field can be successfully converted to a <code>int</code>.
105     *
106     * @param value The value validation is being performed on.
107     * @return boolean If the field can be successfully converted
108     * to a <code>int</code> <code>true</code> is returned.
109     * Otherwise <code>false</code>.
110     */

111    public static Integer JavaDoc validateInt(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
112       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
113
114       return GenericTypeValidator.formatInt(value, locale);
115    }
116
117    /**
118     * Checks if the field can be successfully converted to a <code>long</code>.
119     *
120     * @param value The value validation is being performed on.
121     * @return boolean If the field can be successfully converted
122     * to a <code>long</code> <code>true</code> is returned.
123     * Otherwise <code>false</code>.
124     */

125    public static Long JavaDoc validateLong(Object JavaDoc bean, Field field) {
126       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
127
128       return GenericTypeValidator.formatLong(value);
129    }
130
131    /**
132     * Checks if the field can be successfully converted to a <code>long</code>.
133     *
134     * @param value The value validation is being performed on.
135     * @return boolean If the field can be successfully converted
136     * to a <code>long</code> <code>true</code> is returned.
137     * Otherwise <code>false</code>.
138     */

139    public static Long JavaDoc validateLong(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
140       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
141
142       return GenericTypeValidator.formatLong(value, locale);
143    }
144
145    /**
146     * Checks if the field can be successfully converted to a <code>float</code>.
147     *
148     * @param value The value validation is being performed on.
149     * @return boolean If the field can be successfully converted
150     * to a <code>float</code> <code>true</code> is returned.
151     * Otherwise <code>false</code>.
152     */

153    public static Float JavaDoc validateFloat(Object JavaDoc bean, Field field) {
154       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
155
156       return GenericTypeValidator.formatFloat(value);
157    }
158    
159    /**
160     * Checks if the field can be successfully converted to a <code>float</code>.
161     *
162     * @param value The value validation is being performed on.
163     * @return boolean If the field can be successfully converted
164     * to a <code>float</code> <code>true</code> is returned.
165     * Otherwise <code>false</code>.
166     */

167    public static Float JavaDoc validateFloat(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
168       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
169
170       return GenericTypeValidator.formatFloat(value, locale);
171    }
172    
173    /**
174     * Checks if the field can be successfully converted to a <code>double</code>.
175     *
176     * @param value The value validation is being performed on.
177     * @return boolean If the field can be successfully converted
178     * to a <code>double</code> <code>true</code> is returned.
179     * Otherwise <code>false</code>.
180     */

181    public static Double JavaDoc validateDouble(Object JavaDoc bean, Field field) {
182       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
183
184       return GenericTypeValidator.formatDouble(value);
185    }
186    
187    /**
188     * Checks if the field can be successfully converted to a <code>double</code>.
189     *
190     * @param value The value validation is being performed on.
191     * @return boolean If the field can be successfully converted
192     * to a <code>double</code> <code>true</code> is returned.
193     * Otherwise <code>false</code>.
194     */

195    public static Double JavaDoc validateDouble(Object JavaDoc bean, Field field, Locale JavaDoc locale) {
196       String JavaDoc value = ValidatorUtils.getValueAsString(bean, field.getProperty());
197
198       return GenericTypeValidator.formatDouble(value, locale);
199    }
200 }
Popular Tags