package semistructured.xml;

import org.w3c.dom.Document;

import uk.ac.bbk.dcs.automed.qproc.QueryProcessorConfiguration;
import uk.ac.bbk.dcs.automed.xml.materialisation.XMLDSSDOMMaterialiser;
import uk.ac.bbk.dcs.automed.xml.materialisation.XMLDSSMaterialiser;
import uk.ac.bbk.dcs.automed.xml.utilities.PrintUtility;
import uk.ac.bbk.dcs.automed.xml.utilities.XMLUtilities;
import uk.ac.bbk.dcs.automed.xml.wrappers.DOMWrapper;
import uk.ac.bbk.dcs.automed.xml.wrappers.XMLWrapper;
import uk.ac.ic.doc.automed.reps.Schema;

public class XMLBankDOMMaterialisation {
	public static void main(String[] args) {
		try {
			String fileName = "materialized.xml", filePath = "C:\\", globalSchemaName = "bank1";
			PrintUtility.title("XML Global Schema Materialisation Demo");
			System.out.println();

			Schema globalSchema = Schema.getSchema(globalSchemaName);
			XMLWrapper xw = new DOMWrapper(globalSchema.getAccessMethods()[0], "");

			Schema[] localSchemas = { Schema.getKnownSchema("bank1"), Schema.getKnownSchema("bank2"),
					Schema.getKnownSchema("bank3") };
			QueryProcessorConfiguration qpc = new QueryProcessorConfiguration();
			XMLDSSMaterialiser materialiser = new XMLDSSDOMMaterialiser(globalSchema, localSchemas, filePath, fileName, qpc);

			// Print temp results
			PrintUtility.title("Global AutoMed XDSS");
			globalSchema.listSchema();
			PrintUtility.banner();
			System.out.println();

			System.out.println();
			PrintUtility.prettyPrint(xw.getSchemaUIDDoc(), "Global XML DataSource Schema");
			System.out.println();

			materialiser.materialiseSchema();
			Document materialisedDoc = XMLUtilities.parseFile(materialiser.getMaterialisedFile().getAbsolutePath(), false);
			PrintUtility.prettyPrint(materialisedDoc, "Materialised Schema " + globalSchemaName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
