svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.timesupport / org.gvsig.timesupport.lib / org.gvsig.timesupport.lib.impl / src / main / java / org / gvsig / timesupport / impl / coercion / CoerceToDate.java @ 44078
History | View | Annotate | Download (1.17 KB)
1 |
package org.gvsig.timesupport.impl.coercion; |
---|---|
2 |
|
3 |
import java.util.Locale; |
4 |
import org.gvsig.timesupport.RelativeInstant; |
5 |
import org.gvsig.timesupport.RelativeInterval; |
6 |
import org.gvsig.tools.dataTypes.CoercionException; |
7 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
8 |
import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
9 |
|
10 |
/**
|
11 |
*
|
12 |
* @author jjdelcerro
|
13 |
*/
|
14 |
public class CoerceToDate implements CoercionWithLocale{ |
15 |
|
16 |
private final Coercion previous; |
17 |
|
18 |
public CoerceToDate(Coercion previous) {
|
19 |
this.previous = previous;
|
20 |
} |
21 |
|
22 |
@Override
|
23 |
public Object coerce(Object o) throws CoercionException { |
24 |
return this.coerce(o, null); |
25 |
} |
26 |
|
27 |
@Override
|
28 |
public Object coerce(Object o, Locale locale) throws CoercionException { |
29 |
if( o instanceof RelativeInstant ) { |
30 |
return ((RelativeInstant) o).toDate();
|
31 |
} |
32 |
if( o instanceof RelativeInterval ) { |
33 |
return ((RelativeInterval) o).getStart().toDate();
|
34 |
} |
35 |
if( this.previous instanceof CoercionWithLocale ) { |
36 |
return ((CoercionWithLocale)this.previous).coerce(o, locale); |
37 |
} |
38 |
return this.previous.coerce(o); |
39 |
} |
40 |
|
41 |
} |