KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > beanutils > locale > converters > SqlDateLocaleConverter


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.beanutils.locale.converters;
18
19 import java.sql.Date JavaDoc;
20 import java.text.ParseException JavaDoc;
21 import java.util.Locale JavaDoc;
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.Date</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 SqlDateLocaleConverter extends DateLocaleConverter {
35
36
37     // ----------------------------------------------------------- Constructors
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 SqlDateLocaleConverter() {
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 SqlDateLocaleConverter(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 SqlDateLocaleConverter(Locale JavaDoc 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 SqlDateLocaleConverter(Locale JavaDoc locale, boolean locPattern) {
86
87         this(locale, (String JavaDoc) 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 SqlDateLocaleConverter(Locale JavaDoc locale, String JavaDoc 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 SqlDateLocaleConverter(Locale JavaDoc locale, String JavaDoc 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 SqlDateLocaleConverter(Object JavaDoc 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 SqlDateLocaleConverter(Object JavaDoc defaultValue, boolean locPattern) {
141
142         this(defaultValue, Locale.getDefault(), locPattern);
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 SqlDateLocaleConverter(Object JavaDoc defaultValue, Locale JavaDoc 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 SqlDateLocaleConverter(Object JavaDoc defaultValue, Locale JavaDoc 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 SqlDateLocaleConverter(Object JavaDoc defaultValue, Locale JavaDoc locale, String JavaDoc 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 SqlDateLocaleConverter(Object JavaDoc defaultValue, Locale JavaDoc locale, String JavaDoc pattern, boolean locPattern) {
197
198         super(defaultValue, locale, pattern, locPattern);
199     }
200
201
202     // --------------------------------------------------------- Methods
203

204     /**
205      * Convert the specified locale-sensitive input object into an output object of the
206      * specified type.
207      *
208      * @param value The input object to be converted
209      * @param pattern The pattern is used for the convertion
210      *
211      * @exception ConversionException if conversion cannot be performed
212      * successfully
213      */

214     protected Object JavaDoc parse(Object JavaDoc value, String JavaDoc pattern) throws ParseException JavaDoc {
215
216         return new Date JavaDoc(((java.util.Date JavaDoc) super.parse((String JavaDoc) value, pattern)).getTime());
217     }
218 }
219
Popular Tags