package de.ugoe.cs.autoquest.plugin.jfc.commands;

import java.util.Collection;
import java.util.List;

import de.ugoe.cs.autoquest.CommandHelpers;
import de.ugoe.cs.autoquest.eventcore.Event;
import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
import de.ugoe.cs.autoquest.plugin.jfc.JFCLogParser;
import de.ugoe.cs.util.console.Command;
import de.ugoe.cs.util.console.GlobalDataContainer;

/**
 * <p>
 * Command to parse an XML file with sessions monitored by EventBench's
 * JFCMonitor.
 * </p>
 * 
 * @author Steffen Herbold
 * @version 1.0
 */
public class CMDparseJFC implements Command {

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.ugoe.cs.util.console.Command#run(java.util.List)
	 */
	@Override
	public void run(List<Object> parameters) {
		String filename;
		String sequencesName = "sequences";

		try {
			filename = (String) parameters.get(0);
			if (parameters.size() >= 2) {
				sequencesName = (String) parameters.get(1);
			}
		} catch (Exception e) {
			throw new IllegalArgumentException();
		}
		
		JFCLogParser parser = new JFCLogParser();

		parser.parseFile(filename);
		Collection<List<Event>> sequences = parser.getSequences();

	        GUIModel targets = parser.getGuiModel();

		if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
			CommandHelpers.dataOverwritten(sequencesName);
		}
		
	        if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) {
	            CommandHelpers.dataOverwritten(sequencesName + "_targets");
	        }
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.ugoe.cs.util.console.Command#help()
	 */
	@Override
	public String help() {
		return "parseJFC <filename> {<sequencesName>}";
	}

}
