1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.grouplens.grapht.solver;
21
22 import org.apache.commons.lang3.tuple.Pair;
23 import org.grouplens.grapht.ResolutionException;
24 import org.grouplens.grapht.reflect.Desire;
25 import org.grouplens.grapht.reflect.InjectionPoint;
26 import org.grouplens.grapht.reflect.Satisfaction;
27
28 import java.util.List;
29
30
31
32
33
34
35 public class UnresolvableDependencyException extends ResolutionException {
36 private static final long serialVersionUID = 1L;
37
38 private final DesireChain desires;
39 private final InjectionContext context;
40
41 public UnresolvableDependencyException(DesireChain chain, InjectionContext context) {
42 this.desires = chain;
43 this.context = context;
44 }
45
46 public UnresolvableDependencyException(DesireChain chain, InjectionContext context, Throwable cause) {
47 super(cause);
48 this.desires = chain;
49 this.context = context;
50 }
51
52
53
54
55
56
57 public InjectionContext getContext() {
58 return context;
59 }
60
61
62
63
64
65 public DesireChain getDesireChain() {
66 return desires;
67 }
68
69
70
71
72
73
74 public Desire getDesire() {
75 return desires.getCurrentDesire();
76 }
77
78 @Override
79 public String getMessage() {
80 StringBuilder sb = new StringBuilder("Unable to satisfy desire ")
81 .append(format(desires.getCurrentDesire().getInjectionPoint()));
82 List<Pair<Satisfaction, InjectionPoint>> path = context;
83 if (!path.isEmpty()) {
84 sb.append(" of ")
85 .append(path.get(0).getLeft());
86 }
87 sb.append('\n')
88 .append(format(context, desires));
89 return sb.toString();
90 }
91 }