package com.hammurapi.test;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import org.eclipse.emf.ecore.resource.Resource;

import com.hammurapi.config.Factory;
import com.hammurapi.config.runtime.ConfigurationException;
import com.hammurapi.config.runtime.FactoryConfig;
import com.hammurapi.config.runtime.FactoryResult;
import com.hammurapi.config.runtime.MapTokenSource;
import com.hammurapi.config.runtime.ResourceLoader;

public class MyApp {

	/**
	 * @param args
	 * @throws ConfigurationException 
	 */
	public static void main(String[] args) throws Exception {
		Resource resource = ResourceLoader.load("My.hgconfig");
		Factory root = (Factory) resource.getContents().get(0);
		FactoryConfig fConfig = new FactoryConfig();
		fConfig.setProfilePath("st_johns");
		
		Map<String, String> tokens = new HashMap<String, String>();
		tokens.put("promotion", "Organic milk - buy one, get one free!");
		fConfig.setTokenSource(new MapTokenSource(tokens));
		
		FactoryResult<Object> fr = root.create(fConfig);
		try {
			Receipt receipt = (Receipt) fr.call();
			
			Map<String, Double> items = new TreeMap<String, Double>();
			items.put("Milk", 3.53);
			items.put("Bread", 1.82);
			receipt.print(items);
		} finally {
			fr.destroy();
		}
	}

}
