view src/nabble/naml/namespaces/TemplateException.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line source

package nabble.naml.namespaces;


public class TemplateException extends Exception {

	// this class is just to prevent constructor confusion with message
	protected static final class Name {
		private final String s;

		private Name(String s) {
			this.s = s;
		}
	}

	protected static Name name(String s) {
		return new Name(s);
	}


	private final String name;

	protected TemplateException(Name name) {
		this.name = name.s;
	}

	protected TemplateException(Name name,Exception cause) {
		super(cause.getMessage(),cause);
		this.name = name.s;
	}

	protected TemplateException(Name name,String msg) {
		super(msg);
		this.name = name.s;
	}

	protected TemplateException(Name name,String msg,Exception cause) {
		super(msg,cause);
		this.name = name.s;
	}

	public static TemplateException newInstance(String name) {
		return new TemplateException(name(name));
	}

	public static TemplateException newInstance(String name,Exception cause) {
		return new TemplateException(name(name),cause);
	}

	protected String getName() {
		return name;
	}

	public boolean isNamed(String name) {
		return this.name.equals(name);
	}

	public String toString() {
		String s = getClass().getName() + ": " + getName();
		String message = getLocalizedMessage();
		return (message != null) ? (s + ": " + message) : s;
	}

}