001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.core.util.jaxb;
017
018import java.util.Date;
019
020import javax.xml.bind.annotation.adapters.XmlAdapter;
021
022/**
023 * Marshall/unmarshall java.util.Date
024 * 
025 * @author Kuali Rice Team (kuali-rice@googlegroups.com)
026 *
027 */
028public class JaxbDateAdapter extends XmlAdapter<String, Date> {
029
030        /**
031         * This overridden method ...
032         * 
033         * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
034         */
035        @Override
036        public String marshal(Date date) throws Exception {
037                return (null != date ? Long.toString(date.getTime()) : null);
038        }
039
040        /**
041         * This overridden method ...
042         * 
043         * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
044         */
045        @Override
046        public Date unmarshal(String dateStr) throws Exception {
047                return (null != dateStr ? new Date(Long.parseLong(dateStr)) : null);
048        }
049
050}