1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.api.engine; |
17 | |
|
18 | |
import java.util.Collections; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.HashSet; |
21 | |
import java.util.Map; |
22 | |
import java.util.Map.Entry; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
26 | |
import org.springframework.util.CollectionUtils; |
27 | |
|
28 | |
public class TermResolutionException extends RiceRuntimeException { |
29 | |
|
30 | |
private static final long serialVersionUID = 1L; |
31 | |
|
32 | |
public final String termResolverClassName; |
33 | |
public final String outputTerm; |
34 | |
public final Set<String> prereqs; |
35 | |
public final Set<String> parameterNames; |
36 | |
public final Map<String, String> parameters; |
37 | |
|
38 | |
private static String buildResolutionInfoString(TermResolver<?> tr, Map<String, String> parameters) { |
39 | 0 | StringBuilder result = new StringBuilder(); |
40 | |
|
41 | 0 | result.append("["); |
42 | 0 | result.append(TermResolver.class.getSimpleName() + "="); |
43 | |
|
44 | 0 | if (tr == null) { |
45 | 0 | result.append("null"); |
46 | |
} else { |
47 | 0 | result.append(tr.toString()); |
48 | |
} |
49 | |
|
50 | 0 | result.append(", parameters={"); |
51 | |
|
52 | 0 | boolean firstEntry = true; |
53 | 0 | if (!CollectionUtils.isEmpty(parameters)) { |
54 | |
|
55 | 0 | for (Entry<String,String> parameter : parameters.entrySet()){ |
56 | |
|
57 | 0 | if (firstEntry) { |
58 | 0 | firstEntry = false; |
59 | |
} else { |
60 | 0 | result.append(","); |
61 | |
} |
62 | |
|
63 | 0 | result.append(parameter.getKey()); |
64 | 0 | result.append("="); |
65 | 0 | result.append(parameter.getValue()); |
66 | |
} |
67 | |
} |
68 | |
|
69 | 0 | result.append("}]"); |
70 | 0 | return result.toString(); |
71 | |
} |
72 | |
|
73 | |
public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters, Throwable cause) { |
74 | 0 | super(message + " " + buildResolutionInfoString(tr, parameters), cause); |
75 | 0 | if (tr == null) { |
76 | 0 | termResolverClassName = ""; |
77 | 0 | outputTerm = null; |
78 | 0 | prereqs = null; |
79 | 0 | parameterNames = null; |
80 | |
} else { |
81 | 0 | termResolverClassName = tr.getClass().getName(); |
82 | 0 | outputTerm = tr.getOutput(); |
83 | 0 | prereqs = tr.getPrerequisites(); |
84 | 0 | parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames())); |
85 | |
} |
86 | 0 | if (parameters != null){ |
87 | 0 | this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters)); |
88 | |
} else { |
89 | 0 | this.parameters = null; |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters) { |
94 | 0 | super(message + " " + buildResolutionInfoString(tr, parameters)); |
95 | 0 | if (tr == null) { |
96 | 0 | termResolverClassName = ""; |
97 | 0 | outputTerm = null; |
98 | 0 | prereqs = null; |
99 | 0 | parameterNames = null; |
100 | |
} else { |
101 | 0 | termResolverClassName = tr.getClass().getName(); |
102 | 0 | outputTerm = tr.getOutput(); |
103 | 0 | prereqs = tr.getPrerequisites(); |
104 | 0 | parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames())); |
105 | |
} |
106 | 0 | if (parameters != null){ |
107 | 0 | this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters)); |
108 | |
} else { |
109 | 0 | this.parameters = null; |
110 | |
} |
111 | 0 | } |
112 | |
|
113 | |
} |