01: /*
02: * hgcommons 7
03: * Hammurapi Group Common Library
04: * Copyright (C) 2003 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: */
23: package biz.hammurapi.util;
24:
25: import java.lang.reflect.Method;
26: import java.util.Collections;
27: import java.util.Iterator;
28: import java.util.LinkedList;
29: import java.util.List;
30:
31: /**
32: * @author Pavel Vlasov
33: * @version $Revision: 1.1 $
34: */
35: public class AccumulatingVisitorExceptionSink implements
36: VisitorExceptionSink {
37: private List exceptions = new LinkedList();
38:
39: public class Entry {
40: private Object visitor;
41: private Exception exception;
42: private Object visitee;
43: private Method method;
44:
45: Entry(Object visitor, Method method, Object visitee,
46: Exception exception) {
47: this .visitor = visitor;
48: this .exception = exception;
49: this .visitee = visitee;
50: this .method = method;
51: }
52:
53: public Exception getException() {
54: return exception;
55: }
56:
57: public Method getMethod() {
58: return method;
59: }
60:
61: public Object getVisitee() {
62: return visitee;
63: }
64:
65: public Object getVisitor() {
66: return visitor;
67: }
68: }
69:
70: public void consume(DispatchingVisitor dispatcher, Object visitor,
71: Method method, Object visitee, Exception e) {
72: exceptions.add(new Entry(visitor, method, visitee, e));
73: }
74:
75: public synchronized List getExceptions() {
76: return Collections.unmodifiableList(exceptions);
77: }
78:
79: public synchronized void reset() {
80: exceptions.clear();
81: }
82:
83: /**
84: * Invokes printStackTrace() for all accumulated exceptions
85: */
86: public synchronized void dump() {
87: Iterator it = exceptions.iterator();
88: while (it.hasNext()) {
89: Entry entry = (Entry) it.next();
90: System.err.println("Visitor: " + entry.getVisitor());
91: System.err.println("Method: " + entry.getMethod());
92: System.err.println("Visitee: " + entry.getVisitee());
93: entry.getException().printStackTrace();
94: }
95: }
96: }
|