package xml.biomap;

import org.w3c.dom.Document;

import uk.ac.bbk.dcs.automed.xml.XMLConstants;
import uk.ac.bbk.dcs.automed.xml.XMLTransformer;
import uk.ac.bbk.dcs.automed.xml.XMLUIDs;
import uk.ac.bbk.dcs.automed.xml.XMLUtilities;
import uk.ac.bbk.dcs.automed.xml.wrappers.XMLDSSFromAMSchema;
import uk.ac.ic.doc.automed.reps.Construct;
import uk.ac.ic.doc.automed.reps.Model;
import uk.ac.ic.doc.automed.reps.Schema;

/**
 * Class Task Description
 * 
 * @author <a href="mailto:lucas@dcs.bbk.ac.uk">Lucas Zamboulis </a>
 */
public class CATHIntegration {

    public static void main(String[] args) {
        try {
            System.out.println("Starting CATH integration: " + System.currentTimeMillis());
            String finalCATHSchemaName = "CATH_final2";
            String finalGlobalSchemaName = "GLOBAL_final";
            String cathSchemaName = "cath_int";
            String globalSchemaName = "global_int";

            Model xmlModel = Model.getModel(XMLConstants.model);
            Construct element = xmlModel.getConstruct(XMLConstants.element);
            Construct nestList = xmlModel.getConstruct(XMLConstants.nestList);

            //Get XMLDSS in AutoMed schema and DOM formats
System.out.println("p1");            
            Schema finalCATHSchema = Schema.getSchema(finalCATHSchemaName);
System.out.println("p2");            
            Schema finalGlobalSchema = Schema.getSchema(finalGlobalSchemaName);
System.out.println("p3");

            Schema cathSchema = XMLUIDs.changeSchemaUIDs(finalCATHSchema, cathSchemaName);
            Schema globalSchema = XMLUIDs.changeSchemaUIDs(finalGlobalSchema, globalSchemaName);
            XMLDSSFromAMSchema doc1Creator = new XMLDSSFromAMSchema(cathSchema);
            XMLDSSFromAMSchema docCreator = new XMLDSSFromAMSchema(globalSchema);
            Document cathDoc = doc1Creator.getSchemaDoc();
            Document globalDoc = docCreator.getSchemaDoc();

            //Transform and integrate source schemas
            XMLUtilities.banner();
            cathSchema.listSchema();
            XMLUtilities.banner();
            globalSchema.listSchema();
            XMLUtilities.banner();
            XMLTransformer t1 = new XMLTransformer(cathSchema, cathDoc, globalSchema, globalDoc);
            t1.transform(false, false, false);
            t1.listTransformationPathway();
            System.out.println("Finished CATH integration: " + System.currentTimeMillis());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}