/**
 * Copyright (c) 2011 University of Bolton
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to the following 
 * conditions:
 * The above copyright notice and this permission notice shall be included in all copies 
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
 * OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.xcri.types;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

import javax.xml.bind.DatatypeConverter;

import org.jdom.Element;
import org.jdom.Namespace;
import org.xcri.exceptions.InvalidElementException;

public class TemporalType  extends XcriElement {
	
	private Date dtf;

	/**
	 * @return the dtf
	 */
	public Date getDtf() {
		return dtf;
	}

	/**
	 * @param dtf the dtf to set
	 */
	public void setDtf(Date dtf) {
		this.dtf = dtf;
	}

	/* (non-Javadoc)
	 * @see org.xcri.types.XcriElement#toXml()
	 */
	@Override
	public Element toXml() {
		Element element = super.toXml();
		if (this.getDtf() != null) element.setAttribute("dtf", this.getDtf().toString());
		return element;
	}

	/* (non-Javadoc)
	 * @see org.xcri.types.XcriElement#fromXml(org.jdom.Element)
	 */
	@Override
	public void fromXml(Element element) throws InvalidElementException {
		super.fromXml(element);
		if (element.getAttribute("dtf") != null){
			try {
				Date date = new Date();
				date = DatatypeConverter.parseDateTime(element.getAttributeValue("dtf")).getTime();
				this.setDtf(date);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	

}

@@ -1211,16 +1211,43 @@
 eption;%0A
+import java.util.Calendar;%0A
 import j
@@ -1302,16 +1302,64 @@
 nverter;
+%0Aimport javax.xml.datatype.XMLGregorianCalendar;
 %0A%0Aimport
@@ -1833,16 +1833,87 @@
 oXml();%0A
+%09%09Calendar dtf = Calendar.getInstance();%0A%09%09dtf.setTime(this.getDtf());%0A
 %09%09if (th
@@ -1965,31 +1965,43 @@
 f%22, 
-this.getDtf().toString(
+DatatypeConverter.printDateTime(dtf
 ));%0A

output datetime correctly