All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.tid.topologyModuleBase.plugins.writer.gson.GsonTest Maven / Gradle / Ivy

The newest version!
package es.tid.topologyModuleBase.plugins.writer.gson;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.logging.Logger;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import es.tid.provisioningManager.objects.RouterInfoPM;
import es.tid.tedb.IntraDomainEdge;
import es.tid.tedb.SimpleTEDB;
import es.tid.tedb.controllers.TEDUpdaterFloodlight;
import es.tid.topologyModuleBase.TopologyModuleParams;

public class GsonTest 
{
	
	static Logger log=Logger.getLogger("TMController");
	
	public static void main(String [] args)
	{
		
		TopologyModuleParams params;
		params=new TopologyModuleParams("/home/jaume/Desktop/TopologyModuleNoONE.xml");
		params.initialize();
		
		
		log.warning("Initializing TED from WLAN Controller");
		
		SimpleTEDB ted = new SimpleTEDB();
		
		
		//Thread thread = new TEDUpdaterFloodlight(params.getControllerIP(), params.getControllerPORT(), params.getTopologyPath(), params.getTopologyNodesPath(), ted, log);
		//thread.start();	
		
		
		Gson gson = new Gson();
		//String json = gson.toJson(ted); 
		

		Collection links = ted.getIntraDomainLinks();
		Collection nodes = ted.getNetworkGraph().vertexSet();
		 
		//TE_Information te = new TE_Information(((IntraDomainEdge)(edge.toArray()[0])));
		//String json = gson.toJson(((IntraDomainEdge)(links.toArray()[0])));
		/*
		String json = gson.toJson(nodes); 
		
		Type collectionType = new TypeToken>(){}.getType();
		
		Collection recoveredNodes = gson.fromJson(json, collectionType);
		*/
		
		GsonTEDB gsonTed = new GsonTEDB(ted);
		String json = gson.toJson(gsonTed); 
		
		Type collectionType = new TypeToken>(){}.getType();
		
		class auxGsonClass
		{
			Collection links;
			Collection nodes;
			
			public String toString()
			{
				return links +"|"+nodes;
			}
		}
		
		//auxGsonClass recoveredNodes = gson.fromJson(json, auxGsonClass.class);
		
		json = gson.toJson(nodes);
		Collection recoveredNodes = gson.fromJson(json, collectionType);
		
		
		collectionType = new TypeToken>(){}.getType();
		String jsonLinks = gson.toJson(links);
		//Collection recoverdLinks = gson.fromJson(jsonLinks, collectionType);
		
		log.info(json.toString());
		log.info("As JSON:::"+recoveredNodes);
		//log.info("Recoverd nodes::"+recoverdLinks.toString());
	}
}