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 @ 44669
History | View | Annotate | Download (894 Bytes)
1 |
package org.gvsig.timesupport.impl.coercion; |
---|---|
2 |
|
3 |
import java.util.Date; |
4 |
import org.gvsig.timesupport.RelativeInstant; |
5 |
import org.gvsig.timesupport.RelativeInterval; |
6 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
7 |
import org.gvsig.tools.dataTypes.CoercionException; |
8 |
import org.gvsig.tools.dataTypes.CoercionContext; |
9 |
|
10 |
/**
|
11 |
*
|
12 |
* @author jjdelcerro
|
13 |
*/
|
14 |
public class CoerceToDate extends AbstractCoercion { |
15 |
|
16 |
public CoerceToDate() {
|
17 |
} |
18 |
|
19 |
@Override
|
20 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
21 |
if (value == null || value instanceof Date) { |
22 |
return value;
|
23 |
} |
24 |
if (value instanceof RelativeInstant) { |
25 |
return ((RelativeInstant) value).toDate();
|
26 |
} |
27 |
if (value instanceof RelativeInterval) { |
28 |
return ((RelativeInterval) value).getStart().toDate();
|
29 |
} |
30 |
throw new CoercionException("Can't convert object to date"); |
31 |
} |
32 |
|
33 |
} |