1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
|
10
|
|
11
|
|
12
|
import org.dozer.CustomConverter;
|
13
|
import org.dozer.MappingException;
|
14
|
import org.joda.time.DateTime;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
17
|
|
18
|
public class TimePeriodConverter implements CustomConverter {
|
19
|
|
20
|
@Override
|
21
|
public Object convert(Object existingDestinationFieldValue, Object source, Class<?> destClass, Class<?> sourceClass) {
|
22
|
|
23
|
if (source == null) {
|
24
|
return null;
|
25
|
}
|
26
|
if (source instanceof TimePeriod) {
|
27
|
|
28
|
//convert from TimePeriod -> DateTime
|
29
|
//FIXME .toDateTime(null) most probably not correct
|
30
|
if(((TimePeriod)source).getStart() != null){
|
31
|
return ((TimePeriod)source).getStart().toDateTime(null);
|
32
|
} else {
|
33
|
return null;
|
34
|
}
|
35
|
|
36
|
} else if (source instanceof DateTime) {
|
37
|
|
38
|
//convert from DateTime -> TimePeriod
|
39
|
//FIXME implement
|
40
|
return null;
|
41
|
} else {
|
42
|
|
43
|
throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
|
44
|
+ existingDestinationFieldValue + " and " + source);
|
45
|
}
|
46
|
}
|
47
|
}
|