/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.gotoandplay.smartfoxclient.test;

import it.gotoandplay.smartfoxclient.data.SFSObject;
import it.gotoandplay.smartfoxclient.util.SFSObjectSerializer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/*
 *
 * @author Lapo
 */
public class TestSerializer 
{
    public TestSerializer()
    {
	test1();
	System.out.println("\n---------------------------------\nDone!");
    }
    
    public void test1()
    {
	
	List fruits = Arrays.asList( "apple", "orange", "pear", "apricoat", "peach", "mango" );
	List years = Arrays.asList( 1492d, 1789d, 1914d, 1939d, 1989d );

	List linuxDistros = new ArrayList();
	linuxDistros.add("RedHat");
	linuxDistros.add("Debian");
	linuxDistros.add("Slackware");

	Map retroComputers = new HashMap();
	retroComputers.put("Commodore", "C=64");
	retroComputers.put("Acorn", "Atom");
	retroComputers.put("Synclair", "ZX Spectrum");
	retroComputers.put("Texas Instrument", "T99-4A");

	Map musiciansByGenre = new HashMap();
	musiciansByGenre.put(
				"blues",
				Arrays.asList("Muddy Waters","Buddy Guy","B.B. King")
			    );

	musiciansByGenre.put(
		
				"rock",
				Arrays.asList("Jimi Hendrix","Eric Clapton","Jimmy Page")
			);

	musiciansByGenre.put(
				"jazz",
				Arrays.asList("Charlie Parker","Miles Davis","John Coltrane")
			);


	    // Create the object to test
	SFSObject ao = new SFSObject();
	ao.put("String key", "String value");
	ao.putNumber("Pi", 3.14159);
	ao.putBool("Is the earth flat?", false);
	ao.put("NullItem", null);

	ao.putCollection("fruit list", fruits);
	ao.putCollection("hystorical dates", years);
	ao.putCollection("linuxes", linuxDistros);
	ao.putMap("retrocomputing", retroComputers);
	ao.putMap("musicians", musiciansByGenre);

	/**
	 * Dump object structure
	 */
	System.out.println(":::::::::::::::::::::::::::::::::::");
	System.out.println(": Original data structure         :");
	System.out.println(":::::::::::::::::::::::::::::::::::");

	SFSObjectSerializer.dumpAsObj(ao);

	/**
	 * Serialize to ==> XML
	 */
	System.out.println(":::::::::::::::::::::::::::::::::::");
	System.out.println(": Object ==> XML                  :");
	System.out.println(":::::::::::::::::::::::::::::::::::");

	String xmlSerializedObject = SFSObjectSerializer.serialize(ao);
	System.out.println("\nXML:\n" + xmlSerializedObject);
	System.out.println("");

	/**
	 * Deserialize to ==> ActionscriptObject
	 */
	System.out.println(":::::::::::::::::::::::::::::::::::");
	System.out.println(": XML ==> Object                  :");
	System.out.println(":::::::::::::::::::::::::::::::::::");
	SFSObject deserialized = SFSObjectSerializer.deserialize(xmlSerializedObject);
	SFSObjectSerializer.dumpAsObj(deserialized);
    }
}
