|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StringToSQLDateConverter.java | - | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Copyright (C) The Spice Group. All rights reserved.
|
|
3 |
*
|
|
4 |
* This software is published under the terms of the Spice
|
|
5 |
* Software License version 1.1, a copy of which has been included
|
|
6 |
* with this distribution in the LICENSE.txt file.
|
|
7 |
*/
|
|
8 |
package org.codehaus.spice.converter.lib;
|
|
9 |
|
|
10 |
import java.sql.Date;
|
|
11 |
import org.codehaus.spice.converter.AbstractConverter;
|
|
12 |
import org.codehaus.spice.converter.ConverterException;
|
|
13 |
|
|
14 |
/**
|
|
15 |
* String to Date converter.
|
|
16 |
*
|
|
17 |
* <p>Parses a date according to the same rules as the Date.parse() method. In
|
|
18 |
* particular it recognizes the IETF standard date syntax:</p>
|
|
19 |
* <p>"Sat, 12 Aug 1995 13:30:00 GMT"</p>
|
|
20 |
*
|
|
21 |
* @author Peter Donald
|
|
22 |
* @version $Revision: 1.1 $ $Date: 2003/12/02 08:37:56 $
|
|
23 |
*/
|
|
24 |
public class StringToSQLDateConverter |
|
25 |
extends AbstractConverter
|
|
26 |
{ |
|
27 |
/**
|
|
28 |
* Construct the converter.
|
|
29 |
*/
|
|
30 | 0 |
public StringToSQLDateConverter()
|
31 |
{ |
|
32 | 0 |
this( null ); |
33 |
} |
|
34 |
|
|
35 |
/**
|
|
36 |
* Construct the converter with a default value.
|
|
37 |
* If the default value is non-null, it will be returned if unable
|
|
38 |
* to convert object to correct type.
|
|
39 |
*
|
|
40 |
* @param defaultValue the default value
|
|
41 |
*/
|
|
42 | 0 |
public StringToSQLDateConverter( final Date defaultValue )
|
43 |
{ |
|
44 | 0 |
super( String.class, Date.class, defaultValue ); |
45 |
} |
|
46 |
|
|
47 |
/**
|
|
48 |
* Converts a String to a Date.
|
|
49 |
*
|
|
50 |
* @param object the original object to convert
|
|
51 |
* @param context the context in which to convert object (unused)
|
|
52 |
* @return the converted object
|
|
53 |
* @throws ConverterException if error converting object
|
|
54 |
*/
|
|
55 | 0 |
public Object convert( final Object object, final Object context )
|
56 |
throws ConverterException
|
|
57 |
{ |
|
58 | 0 |
try
|
59 |
{ |
|
60 | 0 |
return Date.valueOf( (String)object );
|
61 |
} |
|
62 |
catch( final IllegalArgumentException iae )
|
|
63 |
{ |
|
64 | 0 |
return noConvert( object, iae );
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
|
|