AccumulatingVisitorExceptionSink.java

biz/hammurapi/util/AccumulatingVisitorExceptionSink.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 38:9
Java Inspector 068 Do not use System.out and System.err to output logging messages. Use loggers instead. 2 87:43
Java Inspector 068 Do not use System.out and System.err to output logging messages. Use loggers instead. 2 88:43
Java Inspector 068 Do not use System.out and System.err to output logging messages. Use loggers instead. 2 89:43
Java Inspector 089 Type is not documented 2 35:1
Java Inspector 089 Non-private, non-local types shall be documented 2 38:9
Java Inspector 089 Undocumented method 2 51:17
Java Inspector 089 Undocumented method 2 55:17
Java Inspector 089 Undocumented method 2 59:17
Java Inspector 089 Undocumented method 2 63:17
Java Inspector 089 Undocumented method 2 68:9
Java Inspector 089 Undocumented method 2 72:9
Java Inspector 089 Undocumented method 2 76:9
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 87:44
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 88:44
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 89:44
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 44:17

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.lang.reflect.Method;
26import java.util.Collections;
27import java.util.Iterator;
28import java.util.LinkedList;
29import java.util.List;
30
31/**
32 * @author Pavel Vlasov
33 * @version $Revision: 1.1 $
34 */
35public class AccumulatingVisitorExceptionSink implements VisitorExceptionSink {
36 private List exceptions=new LinkedList();
37
38 public class Entry {
39 private Object visitor;
40 private Exception exception;
41 private Object visitee;
42 private Method method;
43
44 Entry(Object visitor, Method method, Object visitee, Exception exception) {
45 this.visitor = visitor;
46 this.exception = exception;
47 this.visitee = visitee;
48 this.method = method;
49 }
50
51 public Exception getException() {
52 return exception;
53 }
54
55 public Method getMethod() {
56 return method;
57 }
58
59 public Object getVisitee() {
60 return visitee;
61 }
62
63 public Object getVisitor() {
64 return visitor;
65 }
66 }
67
68 public void consume(DispatchingVisitor dispatcher, Object visitor, Method method, Object visitee, Exception e) {
69 exceptions.add(new Entry(visitor, method, visitee, e));
70 }
71
72 public synchronized List getExceptions() {
73 return Collections.unmodifiableList(exceptions);
74 }
75
76 public synchronized void reset() {
77 exceptions.clear();
78 }
79
80 /**
81 * Invokes printStackTrace() for all accumulated exceptions
82 */
83 public synchronized void dump() {
84 Iterator it=exceptions.iterator();
85 while (it.hasNext()) {
86 Entry entry=(Entry) it.next();
87 System.err.println("Visitor: "+entry.getVisitor());
88 System.err.println("Method: "+entry.getMethod());
89 System.err.println("Visitee: "+entry.getVisitee());
90 entry.getException().printStackTrace();
91 }
92 }
93}
94