package xml;

import org.w3c.dom.Document;

import uk.ac.bbk.dcs.automed.xml.DOMMaterialiser;
import uk.ac.bbk.dcs.automed.xml.NodeUtility;
import uk.ac.bbk.dcs.automed.xml.XMLNotFoundException;
import uk.ac.bbk.dcs.automed.xml.wrappers.DOMWrapper;
import uk.ac.bbk.dcs.automed.xml.wrappers.DOMWrapperFactory;
import uk.ac.ic.doc.automed.InconsistentException;
import uk.ac.ic.doc.automed.NotFoundException;
import uk.ac.ic.doc.automed.reps.Schema;
import uk.ac.ic.doc.automed.wrappers.DataSourceException;

public class XMLBankDOMMaterialisation {
	public static void main(String[] args) {
		try {
			String fileName = "materialized.xml", filePath = "C:\\", globalSchemaName = "bank1";
			boolean validate = false;
			NodeUtility.title("XML Global Schema Materialisation Demo");
			System.out.println();
			
			DOMWrapperFactory xwf = new DOMWrapperFactory();
			Schema globalSchema = Schema.getSchema(globalSchemaName);
			DOMWrapper xw = new DOMWrapper(globalSchema.getAccessMethods()[0],"");
			
			String[] localNames = { "bank1", "bank2", "bank3" };
			DOMMaterialiser materialiser = new DOMMaterialiser(xw, filePath, fileName, localNames, validate);
			
			//Print temp results
			NodeUtility.title("Global AutoMed XDSS");
			globalSchema.listSchema();
			NodeUtility.banner();
			System.out.println();
			
			System.out.println();
			NodeUtility.prettyPrint(xw.getSchemaUIDDoc(), "Global XML DataSource Schema");
			System.out.println();
			
			Document materialisedDoc = materialiser.materialiseSchema(xw.getSchemaUIDDoc());
			NodeUtility.prettyPrint(materialisedDoc,"Materialised Schema " + globalSchemaName);
		}
		catch (XMLNotFoundException e) {
			e.printStackTrace();
		}
		catch (NotFoundException e) {
			e.printStackTrace();
		}
		catch (DataSourceException e) {
			e.printStackTrace();
		}
		catch (InconsistentException e) {
			e.printStackTrace();
		}
	}
}
