/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.beanutils.locale.converters;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Locale;

Standard LocaleConverter implementation that converts an incoming locale-sensitive String into a java.sql.Timestamp object, optionally using a default value or throwing a ConversionException if a conversion error occurs.

Version:$Id$
/** * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} * implementation that converts an incoming * locale-sensitive String into a <code>java.sql.Timestamp</code> object, * optionally using a default value or throwing a * {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs.</p> * * @version $Id$ */
public class SqlTimestampLocaleConverter extends DateLocaleConverter { // ----------------------------------------------------------- Constructors
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine and an unlocalized pattern is used for the convertion.
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. The locale is the default locale for * this instance of the Java Virtual Machine and an unlocalized pattern is used * for the convertion. * */
public SqlTimestampLocaleConverter() { this(false); }
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine.
Params:
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. The locale is the default locale for * this instance of the Java Virtual Machine. * * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final boolean locPattern) { this(Locale.getDefault(), locPattern); }
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. An unlocalized pattern is used for the convertion.
Params:
  • locale – The locale
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. An unlocalized pattern is used for the convertion. * * @param locale The locale */
public SqlTimestampLocaleConverter(final Locale locale) { this(locale, (String) null); }
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
Params:
  • locale – The locale
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. * * @param locale The locale * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final Locale locale, final boolean locPattern) { this(locale, (String) null); }
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. An unlocalized pattern is used for the convertion.
Params:
  • locale – The locale
  • pattern – The convertion pattern
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. An unlocalized pattern is used for the convertion. * * @param locale The locale * @param pattern The convertion pattern */
public SqlTimestampLocaleConverter(final Locale locale, final String pattern) { this(locale, pattern, false); }
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
Params:
  • locale – The locale
  • pattern – The convertion pattern
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will throw a {@link org.apache.commons.beanutils.ConversionException} * if a conversion error occurs. * * @param locale The locale * @param pattern The convertion pattern * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) { super(locale, pattern, locPattern); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine and an unlocalized pattern is used for the convertion.
Params:
  • defaultValue – The default value to be returned
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. The locale is the default locale for * this instance of the Java Virtual Machine and an unlocalized pattern is used * for the convertion. * * @param defaultValue The default value to be returned */
public SqlTimestampLocaleConverter(final Object defaultValue) { this(defaultValue, false); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine.
Params:
  • defaultValue – The default value to be returned
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. The locale is the default locale for * this instance of the Java Virtual Machine. * * @param defaultValue The default value to be returned * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final Object defaultValue, final boolean locPattern) { this(defaultValue, Locale.getDefault(), locPattern); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs. An unlocalized pattern is used for the convertion.
Params:
  • defaultValue – The default value to be returned
  • locale – The locale
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. An unlocalized pattern is used for the convertion. * * @param defaultValue The default value to be returned * @param locale The locale */
public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale) { this(defaultValue, locale, false); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
Params:
  • defaultValue – The default value to be returned
  • locale – The locale
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. * * @param defaultValue The default value to be returned * @param locale The locale * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) { this(defaultValue, locale, null, locPattern); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs. An unlocalized pattern is used for the convertion.
Params:
  • defaultValue – The default value to be returned
  • locale – The locale
  • pattern – The convertion pattern
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. An unlocalized pattern is used for the convertion. * * @param defaultValue The default value to be returned * @param locale The locale * @param pattern The convertion pattern */
public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) { this(defaultValue, locale, pattern, false); }
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
Params:
  • defaultValue – The default value to be returned
  • locale – The locale
  • pattern – The convertion pattern
  • locPattern – Indicate whether the pattern is localized or not
/** * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} * that will return the specified default value * if a conversion error occurs. * * @param defaultValue The default value to be returned * @param locale The locale * @param pattern The convertion pattern * @param locPattern Indicate whether the pattern is localized or not */
public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) { super(defaultValue, locale, pattern, locPattern); } // --------------------------------------------------------- Methods
Convert the specified locale-sensitive input object into an output object of the specified type.
Params:
  • value – The input object to be converted
  • pattern – The pattern is used for the convertion
Throws:
Returns:The converted value
/** * Convert the specified locale-sensitive input object into an output object of the * specified type. * * @param value The input object to be converted * @param pattern The pattern is used for the convertion * @return The converted value * * @throws org.apache.commons.beanutils.ConversionException if conversion * cannot be performed successfully * @throws ParseException if an error occurs parsing a String to a Number */
@Override protected Object parse(final Object value, final String pattern) throws ParseException { return new Timestamp(((java.util.Date) super.parse(value, pattern)).getTime()); } }