
package de.ivu.elect.business.exchange.control;

import static de.ivu.elect.jee.exception.ElectCommonException.RedirectDestination.NONE;

import java.util.List;

import de.ivu.elect.jee.exception.ElectCommonException;
import de.ivu.elect.jee.exchange.AbstractViolation;
import de.ivu.elect.jee.faces.Messages;

public class ImportException extends ElectCommonException {

  private static final long serialVersionUID = 1L;

  public ImportException(Messages messages, String msgKey, List<AbstractViolation> errorViolations, Object... parameter) {
    super(NONE, msgKey, createRoot(messages, errorViolations), parameter);
  }

  private static Throwable createRoot(Messages messages, List<AbstractViolation> errorViolations) {
    Throwable root = null;

    for (AbstractViolation errorViolation : errorViolations) {
      root = new ElectCommonException(NONE, errorViolation.getMessageKey(), root, errorViolation.getMessageParameters(messages)) {

        private static final long serialVersionUID = 1L;

        @Override
        public synchronized Throwable fillInStackTrace() {
          return this; // nicht notwendig
        }
      };
    }

    return root;
  }
}
