Revision 1388 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/AbstractCoerceToDate.java
AbstractCoerceToDate.java | ||
---|---|---|
36 | 36 |
* Abstract implementation for Date coercion classes. If the value is not a |
37 | 37 |
* {@link Date}, it will use the {@link Object#toString()} method to convert the |
38 | 38 |
* resulting {@link String} to a Date object. |
39 |
*
|
|
39 |
* |
|
40 | 40 |
* @author gvSIG Team |
41 | 41 |
* @version $Id$ |
42 | 42 |
*/ |
... | ... | |
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
public Object coerce(Object value, Locale locale) throws CoercionException { |
50 |
return coerce(value, this.createFormatter(locale)); |
|
51 |
} |
|
52 |
|
|
53 |
protected Object coerce(Object value, DateFormat dateFormatter) throws CoercionException { |
|
50 | 54 |
if( value == null ) { |
51 | 55 |
return null; |
52 | 56 |
} |
53 | 57 |
if (!(value instanceof Date)) { |
54 |
DateFormat dateFormatter = createFormatter(locale); |
|
55 | 58 |
String valueStr = value.toString(); |
56 | 59 |
if( valueStr == null ) { |
57 | 60 |
return null; |
... | ... | |
60 | 63 |
if( valueStr.length()==0 ) { |
61 | 64 |
return null; |
62 | 65 |
} |
63 |
|
|
66 |
|
|
64 | 67 |
try { |
65 | 68 |
Date d = dateFormatter.parse(valueStr); |
66 | 69 |
if (d == null) { |
... | ... | |
87 | 90 |
/** |
88 | 91 |
* Returns the {@link DateFormat} to apply when the value to coerce is not |
89 | 92 |
* of Date type and it will be parsed as String. |
90 |
*
|
|
93 |
* |
|
91 | 94 |
* @return the {@link DateFormat} to apply to parse the value to coerce as |
92 | 95 |
* {@link String} |
93 | 96 |
*/ |
... | ... | |
97 | 100 |
* Returns the name of the Date type being coerced. Ex: Date, DateTime, |
98 | 101 |
* Time. Only used for description when an error is produced when coercing |
99 | 102 |
* the value. |
100 |
*
|
|
103 |
* |
|
101 | 104 |
* @return the name of the Date type being coerced |
102 | 105 |
*/ |
103 | 106 |
protected abstract String getDateType(); |
Also available in: Unified diff