package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller;

import java.io.FileInputStream;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.CancelParsingSAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.SimulationSetupInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;

public class SimulationSetupInformationProvider {
	private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider();

	private SimulationSetupInformationHandler _handler = new SimulationSetupInformationHandler();

	private SimulationSetupInformationProvider() {
	}

	public static SimulationSetupInformationProvider getOnlyInstance() {
		return ONLY_INSTANCE;
	}

	public Location getUpperLeft() {
		return _handler.getUpperLeft();
	}

	public Location getLowerRight() {
		return _handler.getLowerRight();
	}

	public static void init(String pNetFileLocation) {
		try {
			SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
			parser.parse(new FileInputStream(pNetFileLocation), ONLY_INSTANCE._handler);
		} catch (CancelParsingSAXException e) {
			return;
		} catch (ParserConfigurationException | SAXException | IOException e) {
			e.printStackTrace();
		}
	}
}
