package exceptions;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Clase que captura los errores producidos en la ejecución de comandos en terminal de Linux
 * 
 * @author Enrique M.L
 *
 */
public class ErrorRunException extends Exception {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String message;
	private String command = null;
	private String path = null;
	
	public ErrorRunException(String message){
        super(message);
        this.message = message;
    }
	
	private String arrayListToString(ArrayList<String> command){
		Iterator<String> ite = command.iterator();
        String finished_command = new String();
        while (ite.hasNext()) {
            finished_command = finished_command + ite.next() + " ";
        }
        return finished_command;
	}

	public ErrorRunException(String message, ArrayList<String> command,
			String path) {
		super(message);
		this.message = message;
		this.command = arrayListToString(command);
		this.path = path;
	}
	
	public void printError(){
		System.out.println("Mensaje de Error: " + message);
		if (!command.equals(null))
			System.out.println("Command: " + command);
		if (!path.equals(null))
			System.out.println("Path: " + path);
	}

}
