package com.ejie.ad74a.xmlparser;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.springframework.context.i18n.LocaleContextHolder;

import com.ejie.x38.util.DateTimeManager;

public class DateAdapter extends XmlAdapter<String, Date> {

	@Override
	public String marshal(Date v) throws Exception {
		Locale locale = LocaleContextHolder.getLocale();
		SimpleDateFormat format = DateTimeManager.getDateTimeFormat(locale);
		return format.format(v);
	}

	@Override
	public Date unmarshal(String v) throws Exception {
		Locale locale = LocaleContextHolder.getLocale();
		SimpleDateFormat format = DateTimeManager.getDateTimeFormat(locale);
		return format.parse(v);

	}

}
