Factory method for molecular.Sequence
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / jaxb / DateTimeAdapter.java
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
10 package eu.etaxonomy.cdm.jaxb;
11
12 import javax.xml.bind.annotation.adapters.XmlAdapter;
13
14 import org.apache.log4j.Logger;
15 import org.joda.time.DateTime;
16 import org.joda.time.format.DateTimeFormatter;
17 import org.joda.time.format.ISODateTimeFormat;
18
19 /**
20 * @author a.mueller
21 * @created 23.07.2008
22 * @version 1.0
23 */
24 public class DateTimeAdapter extends XmlAdapter<String, DateTime> {
25 private static final Logger logger = Logger.getLogger(DateTimeAdapter.class);
26
27 @Override
28 public String marshal(DateTime dateTime) throws Exception {
29 if (logger.isDebugEnabled()){logger.debug("marshal");}
30 if(dateTime == null) {
31 return null;
32 } else {
33 DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
34 return dateTimeFormatter.print(dateTime);
35 }
36 }
37
38 @Override
39 public DateTime unmarshal(String value) throws Exception {
40 if (logger.isDebugEnabled()){logger.debug("unmarshal");}
41 return ISODateTimeFormat.dateTimeParser().parseDateTime(value);
42 }
43 }