// Path: src/main/java/br/com/six2six/fixturefactory/JavaVersion.java
// public class JavaVersion {
// 
// 	public static final JavaVersion JAVA_8 = new JavaVersion("1.8");
// 	public static final JavaVersion JAVA_7 = new JavaVersion("1.7");
// 	public static final JavaVersion JAVA_6 = new JavaVersion("1.6");
// 	
// 	private int major;
// 	private int minor;
// 
// 	public JavaVersion(String version) {
// 	    String[] fields = version.split("\\.");
// 	    this.major = Integer.parseInt(fields[0]);
// 	    this.minor = Integer.parseInt(fields[1]);
// 	}
// 	
// 	public boolean gte(JavaVersion version) {
// 	    return this.major >= version.major && this.minor >= version.minor;
// 	}
// 	
// 	public static JavaVersion current(){
// 		return new JavaVersion(System.getProperty("java.version"));
// 	}
// 
// 	public int getMajor() {
// 		return major;
// 	}
// 
// 	public void setMajor(int major) {
// 		this.major = major;
// 	}
// 
// 	public int getMinor() {
// 		return minor;
// 	}
// 
// 	public void setMinor(int minor) {
// 		this.minor = minor;
// 	}
// 	
// }


import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.lang.ClassUtils;
import br.com.six2six.fixturefactory.JavaVersion;
package br.com.six2six.fixturefactory.transformer;






public class CalendarTransformer implements Transformer {

	public <T> T transform(Object value, Class<T> type)  {
		Object returnValue = null;
		
		if (value == null) {
			return null;
		}
		
		if (ClassUtils.isAssignable(type, XMLGregorianCalendar.class)) {
			try {
				returnValue = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) value);
			} catch (DatatypeConfigurationException e) {
				throw new IllegalArgumentException("Error parser Calendar to XMLGregorianCalendar", e);
			}
			
		} else if (ClassUtils.isAssignable(type, java.sql.Date.class)) {
			returnValue = new java.sql.Date(((Calendar) value).getTimeInMillis());
			
		} else if (ClassUtils.isAssignable(type, java.util.Date.class)) {
			returnValue = ((Calendar) value).getTime();
		
		} else if (ClassUtils.isAssignable(type, Calendar.class)) { 
			returnValue = value;
			
		} else {
			throw new IllegalArgumentException("Incorrect type for transformer: " + type.getCanonicalName());
		}
		
		return type.cast(returnValue);
	}

    public boolean accepts(Object value, Class<?> type) {
    	boolean instanceOfCalendar = value instanceof Calendar;
// Path: src/main/java/br/com/six2six/fixturefactory/JavaVersion.java
// public class JavaVersion {
// 
// 	public static final JavaVersion JAVA_8 = new JavaVersion("1.8");
// 	public static final JavaVersion JAVA_7 = new JavaVersion("1.7");
// 	public static final JavaVersion JAVA_6 = new JavaVersion("1.6");
// 	
// 	private int major;
// 	private int minor;
// 
// 	public JavaVersion(String version) {
// 	    String[] fields = version.split("\\.");
// 	    this.major = Integer.parseInt(fields[0]);
// 	    this.minor = Integer.parseInt(fields[1]);
// 	}
// 	
// 	public boolean gte(JavaVersion version) {
// 	    return this.major >= version.major && this.minor >= version.minor;
// 	}
// 	
// 	public static JavaVersion current(){
// 		return new JavaVersion(System.getProperty("java.version"));
// 	}
// 
// 	public int getMajor() {
// 		return major;
// 	}
// 
// 	public void setMajor(int major) {
// 		this.major = major;
// 	}
// 
// 	public int getMinor() {
// 		return minor;
// 	}
// 
// 	public void setMinor(int minor) {
// 		this.minor = minor;
// 	}
// 	
// }


// Path: src/main/java/br/com/six2six/fixturefactory/transformer/CalendarTransformer.java
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.lang.ClassUtils;
import br.com.six2six.fixturefactory.JavaVersion;

package br.com.six2six.fixturefactory.transformer;






public class CalendarTransformer implements Transformer {

	public <T> T transform(Object value, Class<T> type)  {
		Object returnValue = null;
		
		if (value == null) {
			return null;
		}
		
		if (ClassUtils.isAssignable(type, XMLGregorianCalendar.class)) {
			try {
				returnValue = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) value);
			} catch (DatatypeConfigurationException e) {
				throw new IllegalArgumentException("Error parser Calendar to XMLGregorianCalendar", e);
			}
			
		} else if (ClassUtils.isAssignable(type, java.sql.Date.class)) {
			returnValue = new java.sql.Date(((Calendar) value).getTimeInMillis());
			
		} else if (ClassUtils.isAssignable(type, java.util.Date.class)) {
			returnValue = ((Calendar) value).getTime();
		
		} else if (ClassUtils.isAssignable(type, Calendar.class)) { 
			returnValue = value;
			
		} else {
			throw new IllegalArgumentException("Incorrect type for transformer: " + type.getCanonicalName());
		}
		
		return type.cast(returnValue);
	}

    public boolean accepts(Object value, Class<?> type) {
    	boolean instanceOfCalendar = value instanceof Calendar;
        return JavaVersion.current().gte(JavaVersion.JAVA_8) ? instanceOfCalendar && !java.time.temporal.Temporal.class.isAssignableFrom(type) : instanceOfCalendar;