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
29
30
31
32
33 public class TermResolutionException extends RiceRuntimeException {
34
35 private static final long serialVersionUID = 1L;
36
37 public final String termResolverClassName;
38 public final String outputTerm;
39 public final Set<String> prereqs;
40 public final Set<String> parameterNames;
41 public final Map<String, String> parameters;
42
43
44
45
46
47
48
49 private static String buildResolutionInfoString(TermResolver<?> tr, Map<String, String> parameters) {
50 StringBuilder result = new StringBuilder();
51
52 result.append("[");
53 result.append(TermResolver.class.getSimpleName() + "=");
54
55 if (tr == null) {
56 result.append("null");
57 } else {
58 result.append(tr.toString());
59 }
60
61 result.append(", parameters={");
62
63 boolean firstEntry = true;
64 if (!CollectionUtils.isEmpty(parameters)) {
65
66 for (Entry<String,String> parameter : parameters.entrySet()){
67
68 if (firstEntry) {
69 firstEntry = false;
70 } else {
71 result.append(",");
72 }
73
74 result.append(parameter.getKey());
75 result.append("=");
76 result.append(parameter.getValue());
77 }
78 }
79
80 result.append("}]");
81 return result.toString();
82 }
83
84
85
86
87
88
89
90
91 public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters, Throwable cause) {
92 super(message + " " + buildResolutionInfoString(tr, parameters), cause);
93 if (tr == null) {
94 termResolverClassName = "";
95 outputTerm = null;
96 prereqs = null;
97 parameterNames = null;
98 } else {
99 termResolverClassName = tr.getClass().getName();
100 outputTerm = tr.getOutput();
101 prereqs = tr.getPrerequisites();
102 parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames()));
103 }
104 if (parameters != null){
105 this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters));
106 } else {
107 this.parameters = null;
108 }
109 }
110
111
112
113
114
115
116
117 public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters) {
118 super(message + " " + buildResolutionInfoString(tr, parameters));
119 if (tr == null) {
120 termResolverClassName = "";
121 outputTerm = null;
122 prereqs = null;
123 parameterNames = null;
124 } else {
125 termResolverClassName = tr.getClass().getName();
126 outputTerm = tr.getOutput();
127 prereqs = tr.getPrerequisites();
128 parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames()));
129 }
130 if (parameters != null){
131 this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters));
132 } else {
133 this.parameters = null;
134 }
135 }
136
137 }