1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.api.config.domain;
17
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Locale;
21
22 import org.apache.commons.lang.StringUtils;
23
24 import de.smartics.exceptions.i18n.message.MessageParam;
25 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
26 import de.smartics.properties.api.core.domain.PropertyDescriptor;
27 import de.smartics.properties.api.core.domain.PropertyException;
28
29
30
31
32
33
34
35
36 public class ConfigurationValidationException extends ConfigurationException
37 {
38
39
40
41
42
43
44
45
46
47
48 private static final long serialVersionUID = 1L;
49
50
51
52
53
54
55
56
57 private final List<PropertyException> propertyViolations;
58
59
60
61
62
63
64 private final List<PropertyDescriptor> mandatoryProperties;
65
66
67
68
69
70
71 private final UnknownProperties unknownProperties;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public ConfigurationValidationException(final ConfigurationKey<?> key,
87 final List<PropertyException> propertyViolations,
88 final List<PropertyDescriptor> mandatoryProperties,
89 final UnknownProperties unknownProperties)
90 {
91 this(null, key, propertyViolations, mandatoryProperties, unknownProperties);
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public ConfigurationValidationException(final Throwable cause,
107 final ConfigurationKey<?> key,
108 final List<PropertyException> propertyViolations,
109 final List<PropertyDescriptor> mandatoryProperties,
110 final UnknownProperties unknownProperties)
111 {
112 super(ConfigurationCode.INVALID_CONFIGURATION, cause, key);
113 this.propertyViolations = propertyViolations;
114 this.mandatoryProperties = mandatoryProperties;
115 this.unknownProperties = unknownProperties;
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public final List<PropertyException> getPropertyViolations()
132 {
133 return Collections.unmodifiableList(propertyViolations);
134 }
135
136
137
138
139
140
141
142
143 public final List<PropertyDescriptor> getMandatoryProperties()
144 {
145 return Collections.unmodifiableList(mandatoryProperties);
146 }
147
148
149
150
151
152
153 public final UnknownProperties getUnknownProperties()
154 {
155 return unknownProperties;
156 }
157
158
159
160
161
162
163
164
165
166 @MessageParam("violations")
167 public final String getViolationsAsText(final Locale locale)
168 {
169 final StringBuilder buffer = new StringBuilder();
170 if (propertyViolations != null && !propertyViolations.isEmpty())
171 {
172 for (final PropertyException violation : propertyViolations)
173 {
174 buffer.append(" ").append(violation.getLocalizedMessage(locale))
175 .append('\n');
176 }
177 }
178 return StringUtils.chomp(buffer.toString());
179 }
180
181
182
183
184
185
186 @MessageParam("violationCount")
187 public final int getViolationCount()
188 {
189 return propertyViolations != null ? propertyViolations.size() : 0;
190 }
191
192
193
194
195
196
197 @MessageParam("mandatoryProperties")
198 public final String getMandatoryPropertiesAsText()
199 {
200 final StringBuilder buffer = new StringBuilder();
201 if (mandatoryProperties != null && !mandatoryProperties.isEmpty())
202 {
203 for (final PropertyDescriptor descriptor : mandatoryProperties)
204 {
205 buffer.append(" ").append(descriptor.getKey()).append('\n');
206 }
207 }
208 return StringUtils.chomp(buffer.toString());
209 }
210
211
212
213
214
215
216 @MessageParam("mandatoryPropertiesCount")
217 public final int getMandatoryPropertiesCount()
218 {
219 return mandatoryProperties != null ? mandatoryProperties.size() : 0;
220 }
221
222
223
224
225
226
227 @MessageParam("unknownProperties")
228 public final String getUnknownPropertiesAsText()
229 {
230 final StringBuilder buffer = new StringBuilder();
231 if (unknownProperties != null && !unknownProperties.isEmpty())
232 {
233 for (final Property property : unknownProperties.getProperties())
234 {
235 buffer.append(" ").append(property).append('\n');
236 }
237 }
238 return StringUtils.chomp(buffer.toString());
239 }
240
241
242
243
244
245
246 @MessageParam("unknownPropertiesCount")
247 public final int getUnknownPropertiesCount()
248 {
249 return unknownProperties != null ? unknownProperties.getProperties().size()
250 : 0;
251 }
252
253
254 }