1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.common.collection;
25
26 import java.util.Collections;
27 import java.util.Iterator;
28 import java.util.List;
29 import org.modeshape.common.i18n.I18n;
30
31
32
33
34
35 public abstract class AbstractProblems implements Problems {
36 private static final long serialVersionUID = 1L;
37
38 protected static final List<Problem> EMPTY_PROBLEMS = Collections.emptyList();
39
40 public void addError( I18n message,
41 Object... params ) {
42 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, null));
43 }
44
45 public void addError( Throwable throwable,
46 I18n message,
47 Object... params ) {
48 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, null, null, throwable));
49 }
50
51 public void addError( String resource,
52 String location,
53 I18n message,
54 Object... params ) {
55 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, null));
56 }
57
58 public void addError( Throwable throwable,
59 String resource,
60 String location,
61 I18n message,
62 Object... params ) {
63 addProblem(new Problem(Problem.Status.ERROR, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
64 }
65
66 public void addError( int code,
67 I18n message,
68 Object... params ) {
69 addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, null));
70 }
71
72 public void addError( Throwable throwable,
73 int code,
74 I18n message,
75 Object... params ) {
76 addProblem(new Problem(Problem.Status.ERROR, code, message, params, null, null, throwable));
77 }
78
79 public void addError( int code,
80 String resource,
81 String location,
82 I18n message,
83 Object... params ) {
84 addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, null));
85 }
86
87 public void addError( Throwable throwable,
88 int code,
89 String resource,
90 String location,
91 I18n message,
92 Object... params ) {
93 addProblem(new Problem(Problem.Status.ERROR, code, message, params, resource, location, throwable));
94 }
95
96 public void addWarning( I18n message,
97 Object... params ) {
98 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, null));
99 }
100
101 public void addWarning( Throwable throwable,
102 I18n message,
103 Object... params ) {
104 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, null, null, throwable));
105 }
106
107 public void addWarning( String resource,
108 String location,
109 I18n message,
110 Object... params ) {
111 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, null));
112 }
113
114 public void addWarning( Throwable throwable,
115 String resource,
116 String location,
117 I18n message,
118 Object... params ) {
119 addProblem(new Problem(Problem.Status.WARNING, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
120 }
121
122 public void addWarning( int code,
123 I18n message,
124 Object... params ) {
125 addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, null));
126 }
127
128 public void addWarning( Throwable throwable,
129 int code,
130 I18n message,
131 Object... params ) {
132 addProblem(new Problem(Problem.Status.WARNING, code, message, params, null, null, throwable));
133 }
134
135 public void addWarning( int code,
136 String resource,
137 String location,
138 I18n message,
139 Object... params ) {
140 addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, null));
141 }
142
143 public void addWarning( Throwable throwable,
144 int code,
145 String resource,
146 String location,
147 I18n message,
148 Object... params ) {
149 addProblem(new Problem(Problem.Status.WARNING, code, message, params, resource, location, throwable));
150 }
151
152 public void addInfo( I18n message,
153 Object... params ) {
154 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, null));
155 }
156
157 public void addInfo( Throwable throwable,
158 I18n message,
159 Object... params ) {
160 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, null, null, throwable));
161 }
162
163 public void addInfo( String resource,
164 String location,
165 I18n message,
166 Object... params ) {
167 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, null));
168 }
169
170 public void addInfo( Throwable throwable,
171 String resource,
172 String location,
173 I18n message,
174 Object... params ) {
175 addProblem(new Problem(Problem.Status.INFO, Problem.DEFAULT_CODE, message, params, resource, location, throwable));
176 }
177
178 public void addInfo( int code,
179 I18n message,
180 Object... params ) {
181 addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, null));
182 }
183
184 public void addInfo( Throwable throwable,
185 int code,
186 I18n message,
187 Object... params ) {
188 addProblem(new Problem(Problem.Status.INFO, code, message, params, null, null, throwable));
189 }
190
191 public void addInfo( int code,
192 String resource,
193 String location,
194 I18n message,
195 Object... params ) {
196 addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, null));
197 }
198
199 public void addInfo( Throwable throwable,
200 int code,
201 String resource,
202 String location,
203 I18n message,
204 Object... params ) {
205 addProblem(new Problem(Problem.Status.INFO, code, message, params, resource, location, throwable));
206 }
207
208 public boolean hasProblems() {
209 return getProblems().size() > 0;
210 }
211
212 public boolean hasErrors() {
213 for (Problem problem : this.getProblems()) {
214 if (problem.getStatus() == Problem.Status.ERROR) return true;
215 }
216 return false;
217 }
218
219 public boolean hasWarnings() {
220 for (Problem problem : this.getProblems()) {
221 if (problem.getStatus() == Problem.Status.WARNING) return true;
222 }
223 return false;
224 }
225
226 public boolean hasInfo() {
227 for (Problem problem : this.getProblems()) {
228 if (problem.getStatus() == Problem.Status.INFO) return true;
229 }
230 return false;
231 }
232
233 public boolean isEmpty() {
234 return getProblems().isEmpty();
235 }
236
237 public int size() {
238 return getProblems().size();
239 }
240
241
242
243
244
245
246 public Iterator<Problem> iterator() {
247 return getProblems().iterator();
248 }
249
250 protected abstract void addProblem( Problem problem );
251
252 protected abstract List<Problem> getProblems();
253 }