package com.hammurapi.test;

import java.io.File;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import com.hammurapi.config.ConfigFactory;
import com.hammurapi.config.ObjectDefinition;


/**
 * This class builds configurator model programmatically and saves it to Generated.hgconfig
 * @author Pavel Vlasov
 *
 */
public class BuildModel {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		ObjectDefinition objDef = ConfigFactory.eINSTANCE.createObjectDefinition();
		objDef.setDescription("Generated object definition");
		objDef.setType("java.lang.Integer");
		objDef.setValue("1234");
		
		ResourceSet resourceSet = new ResourceSetImpl();
		// Register the appropriate resource factory to handle all file extensions.
		//
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
				Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
		
		URI uri = URI.createFileURI(new File("Generated.hgconfig").getAbsolutePath());
		Resource configResource = resourceSet.createResource(uri);
		EList<EObject> contents = configResource.getContents();
		contents.add(objDef);
		configResource.save(null);
	}

}
