01: /* SqlDatePropertyEditor.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: * www.ddsteps.org
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License version 2.1 as published by the Free Software Foundation.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, visit
18: * http://www.opensource.org/licenses/lgpl-license.php
19: */
20:
21: package org.ddsteps.beans;
22:
23: import java.text.SimpleDateFormat;
24: import java.util.Date;
25:
26: import org.springframework.beans.propertyeditors.CustomDateEditor;
27:
28: /**
29: * Custom Property Editor, handles java.util.Date to java.sql.Date conversions.
30: * <p>
31: * Dates passed in as text are parsed using the date pattern: yyyy-MM-dd
32: *
33: * @author adamskogman
34: * @version $Id: SqlDatePropertyEditor.java,v 1.1 2005/12/03 12:51:41 adamskogman Exp $
35: */
36: public class SqlDatePropertyEditor extends CustomDateEditor {
37:
38: /**
39: * Default Constructor.
40: *
41: */
42: public SqlDatePropertyEditor() {
43: super (new SimpleDateFormat("yyyy-MM-dd"), true);
44:
45: }
46:
47: /**
48: * Does conversion if java.util.Date.
49: *
50: * @see java.beans.PropertyEditor#setValue(java.lang.Object)
51: */
52: public void setValue(Object value) {
53:
54: if (value instanceof Date) {
55: Date utilDate = (Date) value;
56: value = new java.sql.Date(utilDate.getTime());
57: }
58:
59: if (value != null && !(value instanceof java.sql.Date)) {
60: throw new IllegalArgumentException("Not an SQL Date ["
61: + value + "]");
62: }
63:
64: super.setValue(value);
65: }
66:
67: }
|