1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.grouplens.grapht;
21
22 import org.grouplens.grapht.reflect.InjectionPoint;
23
24 import javax.annotation.Nullable;
25 import java.lang.reflect.Member;
26
27
28
29
30
31
32
33
34
35 public class ConstructionException extends InjectionException {
36 private static final long serialVersionUID = 1L;
37
38 private final Class<?> type;
39 private final InjectionPoint injectionPoint;
40
41 public ConstructionException(InjectionPoint ip, String message) {
42 this(ip, message, null);
43 }
44
45 public ConstructionException(InjectionPoint ip, Throwable cause) {
46 this(ip, defaultMessage(ip, null), cause);
47 }
48
49 public ConstructionException(InjectionPoint ip, String message, Throwable cause) {
50 super(message, cause);
51 type = null;
52 injectionPoint = ip;
53 }
54
55 private static String defaultMessage(InjectionPoint ip, Class<?> type) {
56 if (ip != null) {
57 return String.format("Error injecting into %s", ip);
58 } else {
59 return String.format("Error injecting %s", type);
60 }
61 }
62
63 public ConstructionException(String msg, Throwable cause) {
64 super(msg, cause);
65 type = null;
66 injectionPoint = null;
67 }
68
69 public ConstructionException(Class<?> type, Throwable cause) {
70 this(type, defaultMessage(null, type), cause);
71 }
72
73 public ConstructionException(Member target, String message, Throwable cause) {
74 this(target.getDeclaringClass(), message, cause);
75 }
76
77 public ConstructionException(Class<?> type, String message, Throwable cause) {
78 super(message, cause);
79 this.type = type;
80 injectionPoint = null;
81 }
82
83
84
85
86
87 public Class<?> getType() {
88 if (type != null) {
89 return type;
90 } else if (injectionPoint != null) {
91 Member target = injectionPoint.getMember();
92 if (target != null) {
93 return target.getDeclaringClass();
94 }
95 }
96
97 return null;
98 }
99
100 @Nullable
101 public InjectionPoint getInjectionPoint() {
102 return injectionPoint;
103 }
104 }