01: package jdepend.framework;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: /**
07: * The <code>AbstractParser</code> class is the base class
08: * for classes capable of parsing files to create a
09: * <code>JavaClass</code> instance.
10: *
11: * @author <b>Mike Clark</b>
12: * @author Clarkware Consulting, Inc.
13: */
14:
15: public abstract class AbstractParser {
16:
17: private ArrayList parseListeners;
18: private PackageFilter filter;
19: public static boolean DEBUG = false;
20:
21: public AbstractParser() {
22: this (new PackageFilter());
23: }
24:
25: public AbstractParser(PackageFilter filter) {
26: setFilter(filter);
27: parseListeners = new ArrayList();
28: }
29:
30: public void addParseListener(ParserListener listener) {
31: parseListeners.add(listener);
32: }
33:
34: /**
35: * Registered parser listeners are informed that the resulting
36: * <code>JavaClass</code> was parsed.
37: */
38: public abstract JavaClass parse(InputStream is) throws IOException;
39:
40: /**
41: * Informs registered parser listeners that the specified
42: * <code>JavaClass</code> was parsed.
43: *
44: * @param jClass Parsed Java class.
45: */
46: protected void onParsedJavaClass(JavaClass jClass) {
47: for (Iterator i = parseListeners.iterator(); i.hasNext();) {
48: ((ParserListener) i.next()).onParsedJavaClass(jClass);
49: }
50: }
51:
52: protected PackageFilter getFilter() {
53: if (filter == null) {
54: setFilter(new PackageFilter());
55: }
56: return filter;
57: }
58:
59: protected void setFilter(PackageFilter filter) {
60: this .filter = filter;
61: }
62:
63: protected void debug(String message) {
64: if (DEBUG) {
65: System.err.println(message);
66: }
67: }
68: }
|