donaldp 2002/07/15 22:30:06
Added: converter/src/java/org/apache/excalibur/converter/lib
StringToSQLDateConverter.java
Log:
Add support for SQLDate
Revision Changes Path
1.1
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/StringToSQLDateConverter.java
Index: StringToSQLDateConverter.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.converter.lib;
import org.apache.excalibur.converter.AbstractConverter;
import org.apache.excalibur.converter.ConverterException;
import java.sql.Date;
/**
* {@link String} to {@link Date} converter.
*
* <p>Parses a date according to the same rules as the Date.parse() method. In
* particular it recognizes the IETF standard date syntax:</p>
* <p>"Sat, 12 Aug 1995 13:30:00 GMT"</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @ant.converter source="java.lang.String" destination="java.sql.Date"
*/
public class StringToSQLDateConverter
extends AbstractConverter
{
/**
* Construct the converter.
*/
public StringToSQLDateConverter()
{
this( null );
}
/**
* Construct the converter with a default value.
* If the default value is non-null, it will be returned if unable
* to convert object to correct type.
*
* @param defaultValue the default value
*/
public StringToSQLDateConverter( final Date defaultValue )
{
super( String.class, Date.class, defaultValue );
}
/**
* Converts a {@link String} to a {@link Date}.
*
* @param object the original object to convert
* @param context the context in which to convert object (unused)
* @return the converted object
* @throws ConverterException if error converting object
*/
public Object convert( final Object object, final Object context )
throws ConverterException
{
try
{
return Date.valueOf( (String)object );
}
catch( final IllegalArgumentException iae )
{
return noConvert( object, iae );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>