1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.locale.converters;
18
19 import java.sql.Time;
20 import java.text.ParseException;
21 import java.util.Locale;
22
23 /**
24 * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
25 * implementation that converts an incoming
26 * locale-sensitive String into a <code>java.sql.Time</code> object,
27 * optionally using a default value or throwing a
28 * {@link org.apache.commons.beanutils.ConversionException}
29 * if a conversion error occurs.</p>
30 *
31 * @author Yauheny Mikulski
32 */
33
34 public class SqlTimeLocaleConverter extends DateLocaleConverter {
35
36
37
38
39 /**
40 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
41 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
42 * if a conversion error occurs. The locale is the default locale for
43 * this instance of the Java Virtual Machine and an unlocalized pattern is used
44 * for the convertion.
45 *
46 */
47 public SqlTimeLocaleConverter() {
48
49 this(false);
50 }
51
52 /**
53 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
54 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
55 * if a conversion error occurs. The locale is the default locale for
56 * this instance of the Java Virtual Machine.
57 *
58 * @param locPattern Indicate whether the pattern is localized or not
59 */
60 public SqlTimeLocaleConverter(boolean locPattern) {
61
62 this(Locale.getDefault(), locPattern);
63 }
64
65 /**
66 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
67 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
68 * if a conversion error occurs. An unlocalized pattern is used for the convertion.
69 *
70 * @param locale The locale
71 */
72 public SqlTimeLocaleConverter(Locale locale) {
73
74 this(locale, false);
75 }
76
77 /**
78 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
79 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
80 * if a conversion error occurs.
81 *
82 * @param locale The locale
83 * @param locPattern Indicate whether the pattern is localized or not
84 */
85 public SqlTimeLocaleConverter(Locale locale, boolean locPattern) {
86
87 this(locale, (String) null, locPattern);
88 }
89
90 /**
91 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
92 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
93 * if a conversion error occurs. An unlocalized pattern is used for the convertion.
94 *
95 * @param locale The locale
96 * @param pattern The convertion pattern
97 */
98 public SqlTimeLocaleConverter(Locale locale, String pattern) {
99
100 this(locale, pattern, false);
101 }
102
103 /**
104 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
105 * that will throw a {@link org.apache.commons.beanutils.ConversionException}
106 * if a conversion error occurs.
107 *
108 * @param locale The locale
109 * @param pattern The convertion pattern
110 * @param locPattern Indicate whether the pattern is localized or not
111 */
112 public SqlTimeLocaleConverter(Locale locale, String pattern, boolean locPattern) {
113
114 super(locale, pattern, locPattern);
115 }
116
117 /**
118 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
119 * that will return the specified default value
120 * if a conversion error occurs. The locale is the default locale for
121 * this instance of the Java Virtual Machine and an unlocalized pattern is used
122 * for the convertion.
123 *
124 * @param defaultValue The default value to be returned
125 */
126 public SqlTimeLocaleConverter(Object defaultValue) {
127
128 this(defaultValue, false);
129 }
130
131 /**
132 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
133 * that will return the specified default value
134 * if a conversion error occurs. The locale is the default locale for
135 * this instance of the Java Virtual Machine.
136 *
137 * @param defaultValue The default value to be returned
138 * @param locPattern Indicate whether the pattern is localized or not
139 */
140 public SqlTimeLocaleConverter(Object defaultValue, boolean locPattern) {
141
142 this(defaultValue, Locale.getDefault(), false);
143 }
144
145 /**
146 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
147 * that will return the specified default value
148 * if a conversion error occurs. An unlocalized pattern is used for the convertion.
149 *
150 * @param defaultValue The default value to be returned
151 * @param locale The locale
152 */
153 public SqlTimeLocaleConverter(Object defaultValue, Locale locale) {
154
155 this(defaultValue, locale, false);
156 }
157
158 /**
159 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
160 * that will return the specified default value
161 * if a conversion error occurs.
162 *
163 * @param defaultValue The default value to be returned
164 * @param locale The locale
165 * @param locPattern Indicate whether the pattern is localized or not
166 */
167 public SqlTimeLocaleConverter(Object defaultValue, Locale locale, boolean locPattern) {
168
169 this(defaultValue, locale, null, locPattern);
170 }
171
172 /**
173 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
174 * that will return the specified default value
175 * if a conversion error occurs. An unlocalized pattern is used for the convertion.
176 *
177 * @param defaultValue The default value to be returned
178 * @param locale The locale
179 * @param pattern The convertion pattern
180 */
181 public SqlTimeLocaleConverter(Object defaultValue, Locale locale, String pattern) {
182
183 this(defaultValue, locale, pattern, false);
184 }
185
186 /**
187 * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
188 * that will return the specified default value
189 * if a conversion error occurs.
190 *
191 * @param defaultValue The default value to be returned
192 * @param locale The locale
193 * @param pattern The convertion pattern
194 * @param locPattern Indicate whether the pattern is localized or not
195 */
196 public SqlTimeLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) {
197
198 super(defaultValue, locale, pattern, locPattern);
199 }
200
201
202
203 /**
204 * Convert the specified locale-sensitive input object into an output object of the
205 * specified type.
206 *
207 * @param value The input object to be converted
208 * @param pattern The pattern is used for the convertion
209 *
210 * @exception ConversionException if conversion cannot be performed
211 * successfully
212 */
213 protected Object parse(Object value, String pattern) throws ParseException {
214
215 return new Time(((java.util.Date) super.parse((String) value, pattern)).getTime());
216 }
217 }