/*
 * Copyright (c) 2004-2006 Elsag Solutions AG, Germany. All rights reserved.
 * www.elsag-solutions.com
 *
 * $Id: $
 */

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.TimeZone;

import org.joda.time.LocalDate;

import com.thoughtworks.xstream.XStream;

/*
 * Copyright (C) 2008 Elsag Solutions AG.
 * All rights reserved.
 *
 * Created 11.07.2008 by Joerg Schaible.
 * $Id$
 */


/**
 * <todo> Auto-generated JavaDoc
 *
 * @author  J&ouml;rg Schaible
 * @since   upcoming
 * @version $Revision: 1.0 $
 */
public class Main
{
	//~ Methods ----------------------------------------------------------------

	/**
	 * <todo> Auto-generated JavaDoc
	 *
	 * @param args DOCUMENT_ME
	 * @since upcoming
	 */
	public static void main(String[] args)
	{
	        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
		final LocalDate ld0 = new LocalDate(2008, 07, 03);
		final XStream xs = new XStream();
		final String xml0 = xs.toXML(ld0);
		final LocalDate ld1 = (LocalDate) xs.fromXML(xml0);
		final String xml1 = xs.toXML(ld1);
		final LocalDate ld2 = (LocalDate) xs.fromXML(xml1);
		
		LocalDate ld1s = null;
                LocalDate ld2s = null;
		try {
		    ByteArrayOutputStream baos = new ByteArrayOutputStream();
		    ObjectOutputStream oos = new ObjectOutputStream(baos);
		    oos.writeObject(ld0);
		    oos.close();
		    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
		    ld1s = (LocalDate)ois.readObject();
		    ois.close();
                    baos = new ByteArrayOutputStream();
                    oos = new ObjectOutputStream(baos);
                    oos.writeObject(ld1s);
                    oos.close();
                    ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
                    ld2s = (LocalDate)ois.readObject();
                    ois.close();
		} catch (Exception e) {
		    // nothing 
		}
		System.out.println(ld0.toString() + '\n' + xml0 + '\n'
		                   + ld1 + " (" + ld1s + ")\n" + xml1 + '\n' + xs.toXML(ld1s) + '\n'
		                   + ld2  + " (" + ld2s + ")\n");
	}
}

