package basic;
import uk.ac.bbk.dcs.automed.qproc.iql.ASG;
import uk.ac.ic.doc.automed.p2p.tree.Root;
import uk.ac.ic.doc.automed.util.Debugger;
import uk.ac.ic.doc.rodex.p2p.protocol.QEP;
import utils.AutoMedUtils;
/**
 * SerialiseASG.java
 *
 * Test serialisation of ASG into XML with debug information
 *
 * @author Duc M Le  <a href="mailto:dmle@doc.ic.ac.uk"><i>dmle@doc.ic.ac.uk</i></a>
 * Created on 03 July 2006
 * Department of Computing, Imperial College
 */

public class SerialiseASG {
  
  /**
   * Creates a new instance of SerialiseASG
   */
  public SerialiseASG() {
    
  }
  
  
  public static void main(String[] args) throws Exception {
    String str1 = "[{8 ,0 },{9 ,0 },{10 ,2 },{11 ,2 },{12 ,4 },{13 ,4 }]";
    String str2 = "[{x,y} | {r,x} <- <<sensor,damage>>; {r,y} <- <<sensor,time>>]";
    String str3 = "[{x} | {r,x} <- <<sensor,damage>>]";
    String str4 = "<<sensor,damage>>";
    String str5 = "[{8 ,0 },{9 ,0 }]";
    String str6 = "[{100,200}]";
    String str7 = "[{x} | {r,x} <- <<staff,name>>]";
    String str8 = "[{'Alex' ,'CS-BBK' },{'Dimitri' ,'CS-BBK' }," +
      "{'Mike' ,'Computing-IC' },{'Nerissa' ,'Computing-IC' },{'Peter' ,'Computing-IC' },{'Nick' ,'Maths-IC' }]";
    
    Debugger.setSectionDebugLevel(new String[] {"-d", "20.10 8.10"});
    
    String iql = str8;
    
    ASG q = new ASG(iql);
    ASG q1 = q.copyOfASG();
        
    //serialise
    AutoMedUtils.banner("Serialising IQL/ASG into XML: ");
    System.out.println("IQL:"+ iql);
    System.out.println("ASG: ");
    q1.explore();

    Root xml = QEP.serialiseASG(q1);
    
    System.out.println("XML: " + xml.getXMLString());

    // deserialise
    AutoMedUtils.banner("Derialising XML into IQL/ASG: ");
    
    ASG qr = QEP.deserialiseASG(xml);
    
    System.out.println("\nFinal ASG:");
    qr.explore();
    
    boolean equal =  q.equals(qr);
    
    AutoMedUtils.banner((equal) ? "SUCCESS" : "FAILED (original and deserialised objects don't match!");
  }
}
