/**
 * TemplateReaderException.java
 * Created Oct 5, 2007
 * Copyright (c) Tandberg Television 2007
 */
package com.tandbergtv.workflow.driver.template;

import static org.jbpm.jpdl.xml.Problem.LEVEL_ERROR;
import static org.jbpm.jpdl.xml.Problem.LEVEL_FATAL;

import java.util.Collection;
import java.util.List;

import org.jbpm.jpdl.JpdlException;
import org.jbpm.jpdl.xml.Problem;

/**
 * Thrown to indicate an error while reading a template
 * 
 * @author Sahil Verma
 */
public class TemplateReaderException extends JpdlException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2114765932418405999L;

	/**
	 * Creates a {@link TemplateReaderException}
	 */
	public TemplateReaderException(List<Problem> problems) {
		super(problems);
	}

	/**
	 * Creates a {@link TemplateReaderException}
	 * 
	 * @param message
	 * @param cause
	 */
	public TemplateReaderException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * Creates a {@link TemplateReaderException}
	 * 
	 * @param message
	 */
	public TemplateReaderException(String message) {
		super(message);
	}

	/* (non-Javadoc)
	 * @see java.lang.Throwable#toString()
	 */
	@SuppressWarnings("unchecked")
	public String toString() {
        String s = getClass().getName();
        String message = System.getProperty("line.separator");

        for (Problem problem : (Collection<Problem>)problems) {
        	if (problem.getLevel() == LEVEL_ERROR || problem.getLevel() == LEVEL_FATAL)
        		message += problem + System.getProperty("line.separator");
        }
        
        return s + ": " + message;
	}
}
