View Javadoc

1   /*
2    * Copyright 2007-2010 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.jaxb;
17  
18  import java.sql.Timestamp;
19  
20  import javax.xml.bind.annotation.adapters.XmlAdapter;
21  
22  import org.apache.commons.lang.StringUtils;
23  
24  /**
25   * This class allows for a {@link java.sql.Timestamp} instance to be passed across the wire by jaxws enabled services
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public class SqlTimestampAdapter extends XmlAdapter<String, Timestamp> {
31  
32  	/**
33  	 * This overridden method ...
34  	 * 
35  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
36  	 */
37  	@Override
38  	public String marshal(Timestamp timestamp) throws Exception {
39  		return (null != timestamp ? Long.toString(timestamp.getTime()) : null);
40  	}
41  
42  	/**
43  	 * This overridden method ...
44  	 * 
45  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
46  	 */
47  	@Override
48  	public Timestamp unmarshal(String timestampStr) throws Exception {
49  		return (StringUtils.isNotBlank(timestampStr) ? new Timestamp(Long.parseLong(timestampStr)) : null);
50  	}
51  
52  }