001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.beanutils.locale.converters;
019:
020: import java.sql.Time;
021: import java.text.ParseException;
022: import java.util.Locale;
023:
024: /**
025: * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter}
026: * implementation that converts an incoming
027: * locale-sensitive String into a <code>java.sql.Time</code> object,
028: * optionally using a default value or throwing a
029: * {@link org.apache.commons.beanutils.ConversionException}
030: * if a conversion error occurs.</p>
031: *
032: * @author Yauheny Mikulski
033: */
034:
035: public class SqlTimeLocaleConverter extends DateLocaleConverter {
036:
037: // ----------------------------------------------------------- Constructors
038:
039: /**
040: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
041: * that will throw a {@link org.apache.commons.beanutils.ConversionException}
042: * if a conversion error occurs. The locale is the default locale for
043: * this instance of the Java Virtual Machine and an unlocalized pattern is used
044: * for the convertion.
045: *
046: */
047: public SqlTimeLocaleConverter() {
048:
049: this (false);
050: }
051:
052: /**
053: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
054: * that will throw a {@link org.apache.commons.beanutils.ConversionException}
055: * if a conversion error occurs. The locale is the default locale for
056: * this instance of the Java Virtual Machine.
057: *
058: * @param locPattern Indicate whether the pattern is localized or not
059: */
060: public SqlTimeLocaleConverter(boolean locPattern) {
061:
062: this (Locale.getDefault(), locPattern);
063: }
064:
065: /**
066: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
067: * that will throw a {@link org.apache.commons.beanutils.ConversionException}
068: * if a conversion error occurs. An unlocalized pattern is used for the convertion.
069: *
070: * @param locale The locale
071: */
072: public SqlTimeLocaleConverter(Locale locale) {
073:
074: this (locale, false);
075: }
076:
077: /**
078: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
079: * that will throw a {@link org.apache.commons.beanutils.ConversionException}
080: * if a conversion error occurs.
081: *
082: * @param locale The locale
083: * @param locPattern Indicate whether the pattern is localized or not
084: */
085: public SqlTimeLocaleConverter(Locale locale, boolean locPattern) {
086:
087: this (locale, (String) null, locPattern);
088: }
089:
090: /**
091: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
092: * that will throw a {@link org.apache.commons.beanutils.ConversionException}
093: * if a conversion error occurs. An unlocalized pattern is used for the convertion.
094: *
095: * @param locale The locale
096: * @param pattern The convertion pattern
097: */
098: public SqlTimeLocaleConverter(Locale locale, String pattern) {
099:
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,
113: boolean locPattern) {
114:
115: super (locale, pattern, locPattern);
116: }
117:
118: /**
119: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
120: * that will return the specified default value
121: * if a conversion error occurs. The locale is the default locale for
122: * this instance of the Java Virtual Machine and an unlocalized pattern is used
123: * for the convertion.
124: *
125: * @param defaultValue The default value to be returned
126: */
127: public SqlTimeLocaleConverter(Object defaultValue) {
128:
129: this (defaultValue, false);
130: }
131:
132: /**
133: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
134: * that will return the specified default value
135: * if a conversion error occurs. The locale is the default locale for
136: * this instance of the Java Virtual Machine.
137: *
138: * @param defaultValue The default value to be returned
139: * @param locPattern Indicate whether the pattern is localized or not
140: */
141: public SqlTimeLocaleConverter(Object defaultValue,
142: boolean locPattern) {
143:
144: this (defaultValue, Locale.getDefault(), false);
145: }
146:
147: /**
148: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
149: * that will return the specified default value
150: * if a conversion error occurs. An unlocalized pattern is used for the convertion.
151: *
152: * @param defaultValue The default value to be returned
153: * @param locale The locale
154: */
155: public SqlTimeLocaleConverter(Object defaultValue, Locale locale) {
156:
157: this (defaultValue, locale, false);
158: }
159:
160: /**
161: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
162: * that will return the specified default value
163: * if a conversion error occurs.
164: *
165: * @param defaultValue The default value to be returned
166: * @param locale The locale
167: * @param locPattern Indicate whether the pattern is localized or not
168: */
169: public SqlTimeLocaleConverter(Object defaultValue, Locale locale,
170: boolean locPattern) {
171:
172: this (defaultValue, locale, null, locPattern);
173: }
174:
175: /**
176: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
177: * that will return the specified default value
178: * if a conversion error occurs. An unlocalized pattern is used for the convertion.
179: *
180: * @param defaultValue The default value to be returned
181: * @param locale The locale
182: * @param pattern The convertion pattern
183: */
184: public SqlTimeLocaleConverter(Object defaultValue, Locale locale,
185: String pattern) {
186:
187: this (defaultValue, locale, pattern, false);
188: }
189:
190: /**
191: * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter}
192: * that will return the specified default value
193: * if a conversion error occurs.
194: *
195: * @param defaultValue The default value to be returned
196: * @param locale The locale
197: * @param pattern The convertion pattern
198: * @param locPattern Indicate whether the pattern is localized or not
199: */
200: public SqlTimeLocaleConverter(Object defaultValue, Locale locale,
201: String pattern, boolean locPattern) {
202:
203: super (defaultValue, locale, pattern, locPattern);
204: }
205:
206: // --------------------------------------------------------- Methods
207:
208: /**
209: * Convert the specified locale-sensitive input object into an output object of the
210: * specified type.
211: *
212: * @param value The input object to be converted
213: * @param pattern The pattern is used for the convertion
214: * @return The converted value
215: *
216: * @exception org.apache.commons.beanutils.ConversionException if conversion
217: * cannot be performed successfully
218: * @throws ParseException if an error occurs parsing a String to a Number
219: */
220: protected Object parse(Object value, String pattern)
221: throws ParseException {
222:
223: return new Time(((java.util.Date) super.parse(value, pattern))
224: .getTime());
225: }
226: }
|