Mercurial Hosting > nabble
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.naml.namespaces; | |
2 | |
3 | |
4 public class TemplateException extends Exception { | |
5 | |
6 // this class is just to prevent constructor confusion with message | |
7 protected static final class Name { | |
8 private final String s; | |
9 | |
10 private Name(String s) { | |
11 this.s = s; | |
12 } | |
13 } | |
14 | |
15 protected static Name name(String s) { | |
16 return new Name(s); | |
17 } | |
18 | |
19 | |
20 private final String name; | |
21 | |
22 protected TemplateException(Name name) { | |
23 this.name = name.s; | |
24 } | |
25 | |
26 protected TemplateException(Name name,Exception cause) { | |
27 super(cause.getMessage(),cause); | |
28 this.name = name.s; | |
29 } | |
30 | |
31 protected TemplateException(Name name,String msg) { | |
32 super(msg); | |
33 this.name = name.s; | |
34 } | |
35 | |
36 protected TemplateException(Name name,String msg,Exception cause) { | |
37 super(msg,cause); | |
38 this.name = name.s; | |
39 } | |
40 | |
41 public static TemplateException newInstance(String name) { | |
42 return new TemplateException(name(name)); | |
43 } | |
44 | |
45 public static TemplateException newInstance(String name,Exception cause) { | |
46 return new TemplateException(name(name),cause); | |
47 } | |
48 | |
49 protected String getName() { | |
50 return name; | |
51 } | |
52 | |
53 public boolean isNamed(String name) { | |
54 return this.name.equals(name); | |
55 } | |
56 | |
57 public String toString() { | |
58 String s = getClass().getName() + ": " + getName(); | |
59 String message = getLocalizedMessage(); | |
60 return (message != null) ? (s + ": " + message) : s; | |
61 } | |
62 | |
63 } |