KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependencyfinder > cli > VerboseListener


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependencyfinder.cli;
34
35 import java.io.*;
36
37 import com.jeantessier.classreader.*;
38 import com.jeantessier.dependency.*;
39 import com.jeantessier.dependencyfinder.*;
40 import com.jeantessier.metrics.*;
41
42 public class VerboseListener extends VerboseListenerBase implements DependencyListener, MetricsListener {
43     private PrintWriter writer = new NullPrintWriter();
44     
45     public PrintWriter getWriter() {
46         return writer;
47     }
48
49     public void setWriter(OutputStream stream) {
50         setWriter(new PrintWriter(stream));
51     }
52
53     public void setWriter(Writer writer) {
54         setWriter(new PrintWriter(writer));
55     }
56
57     public void setWriter(PrintWriter writer) {
58         this.writer = writer;
59     }
60
61     public void close() {
62         getWriter().close();
63     }
64     
65     public void print(String JavaDoc s) {
66         getWriter().println(s);
67     }
68     
69     public void beginSession(LoadEvent event) {
70         super.beginSession(event);
71         
72         getWriter().print("Searching for classes ...");
73         getWriter().println();
74         getWriter().flush();
75     }
76     
77     public void beginGroup(LoadEvent event) {
78         super.beginGroup(event);
79         
80         getWriter().print("Searching ");
81         getWriter().print(event.getGroupName());
82
83         switch (getCurrentGroup().getSize()) {
84             case -1:
85                 break;
86
87             case 0:
88             case 1:
89                 getWriter().print(" (");
90                 getWriter().print(getCurrentGroup().getSize());
91                 getWriter().print(" file)");
92                 break;
93
94             default:
95                 getWriter().print(" (");
96                 getWriter().print(getCurrentGroup().getSize());
97                 getWriter().print(" files)");
98                 break;
99         }
100         
101         getWriter().print(" ...");
102         getWriter().println();
103         getWriter().flush();
104     }
105
106     public void endClassfile(LoadEvent event) {
107         super.endClassfile(event);
108
109         getWriter().print("Loading ");
110         getWriter().print(event.getClassfile());
111         getWriter().print(" ...");
112         getWriter().println();
113         getWriter().flush();
114     }
115     
116     public void endFile(LoadEvent event) {
117         super.endFile(event);
118         
119         if (!getVisitedFiles().contains(event.getFilename())) {
120             getWriter().print("Skipping ");
121             getWriter().print(event.getFilename());
122             getWriter().print(" ...");
123             getWriter().println();
124             getWriter().flush();
125         }
126     }
127     
128     public void beginSession(DependencyEvent event) {
129         // Do nothing
130
}
131
132     public void beginClass(DependencyEvent event) {
133         getWriter().print("Getting dependencies from ");
134         getWriter().print(event.getClassName());
135         getWriter().print(" ...");
136         getWriter().println();
137         getWriter().flush();
138     }
139     
140     public void dependency(DependencyEvent event) {
141         // Do nothing
142
}
143     
144     public void endClass(DependencyEvent event) {
145         // Do nothing
146
}
147     
148     public void endSession(DependencyEvent event) {
149         // Do nothing
150
}
151
152     public void beginSession(MetricsEvent event) {
153         // Do nothing
154
}
155
156     public void beginClass(MetricsEvent event) {
157         getWriter().print("Computing metrics for ");
158         getWriter().print(event.getClassfile());
159         getWriter().print(" ...");
160         getWriter().println();
161         getWriter().flush();
162     }
163     
164     public void beginMethod(MetricsEvent event) {
165         // Do nothing
166
}
167     
168     public void endMethod(MetricsEvent event) {
169         // Do nothing
170
}
171     
172     public void endClass(MetricsEvent event) {
173         // Do nothing
174
}
175     
176     public void endSession(MetricsEvent event) {
177         // Do nothing
178
}
179 }
180
Popular Tags