AccumulatingExceptionSink.java

biz/hammurapi/util/AccumulatingExceptionSink.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 058 Make inner classes "private" 1 37:9
Java Inspector 068 Do not use System.out and System.err to output logging messages. Use loggers instead. 2 73:43
Java Inspector 089 Type is not documented 2 34:1
Java Inspector 089 Non-private, non-local types shall be documented 2 37:9
Java Inspector 089 Undocumented method 2 46:17
Java Inspector 089 Undocumented method 2 49:17
Java Inspector 089 Undocumented method 2 54:9
Java Inspector 089 Undocumented method 2 58:9
Java Inspector 089 Undocumented method 2 62:9
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 73:44

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.util;
24
25import java.util.Collections;
26import java.util.Iterator;
27import java.util.LinkedList;
28import java.util.List;
29
30/**
31 * @author Pavel Vlasov
32 * @version $Revision: 1.1 $
33 */
34public class AccumulatingExceptionSink implements ExceptionSink {
35 private List exceptions=new LinkedList();
36
37 public class Entry {
38 Entry(Object source, Exception exception) {
39 super();
40 this.source = source;
41 this.exception = exception;
42 }
43 Object source;
44 Exception exception;
45
46 public Exception getException() {
47 return exception;
48 }
49 public Object getSource() {
50 return source;
51 }
52 }
53
54 public synchronized void consume(Object source, Exception e) {
55 exceptions.add(new Entry(source, e));
56 }
57
58 public synchronized List getExceptions() {
59 return Collections.unmodifiableList(exceptions);
60 }
61
62 public synchronized void reset() {
63 exceptions.clear();
64 }
65
66 /**
67 * Invokes printStackTrace() for all accumulated exceptions
68 */
69 public synchronized void dump() {
70 Iterator it=exceptions.iterator();
71 while (it.hasNext()) {
72 Entry entry=(Entry) it.next();
73 System.err.println("Source: "+entry.getSource());
74 entry.getException().printStackTrace();
75 }
76 }
77}
78