KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jdepend > xmlui > JDepend


1 package jdepend.xmlui;
2
3 import java.io.*;
4 import java.util.*;
5
6 import java.text.NumberFormat JavaDoc;
7
8 import jdepend.framework.JavaClass;
9 import jdepend.framework.JavaPackage;
10
11 /**
12  * The <code>JDepend</code> class analyzes directories of Java class files,
13  * generates metrics for each Java package, and reports the metrics in an XML
14  * format.
15  *
16  * @author <b>Mike Clark</b>
17  * @author Clarkware Consulting, Inc.
18  */

19
20 public class JDepend extends jdepend.textui.JDepend {
21
22     /**
23      * Constructs a <code>JDepend</code> instance using standard output.
24      */

25     public JDepend() {
26         this(new PrintWriter(System.out));
27     }
28
29     /**
30      * Constructs a <code>JDepend</code> instance with the specified writer.
31      *
32      * @param writer Writer.
33      */

34     public JDepend(PrintWriter writer) {
35         super(writer);
36
37         formatter = NumberFormat.getInstance(Locale.ENGLISH);
38         formatter.setMaximumFractionDigits(2);
39     }
40
41     protected void printHeader() {
42         getWriter().println("<?xml version=\"1.0\"?>");
43         getWriter().println("<JDepend>");
44     }
45
46     protected void printFooter() {
47         getWriter().println("</JDepend>");
48     }
49
50     protected void printPackagesHeader() {
51         getWriter().println(tab() + "<Packages>");
52     }
53
54     protected void printPackagesFooter() {
55         getWriter().println(tab() + "</Packages>");
56     }
57
58     protected void printPackageHeader(JavaPackage jPackage) {
59         printSectionBreak();
60         getWriter().println(
61                 tab(2) + "<Package name=\"" + jPackage.getName() + "\">");
62     }
63
64     protected void printPackageFooter(JavaPackage jPackage) {
65         getWriter().println(tab(2) + "</Package>");
66     }
67
68     protected void printNoStats() {
69         getWriter().println(
70                 tab(3) + "<error>No stats available: "
71                         + "package referenced, but not analyzed.</error>");
72     }
73
74     protected void printStatistics(JavaPackage jPackage) {
75         getWriter().println(tab(3) + "<Stats>");
76         getWriter().println(
77                 tab(4) + "<TotalClasses>" + jPackage.getClassCount()
78                         + "</TotalClasses>");
79         getWriter().println(
80                 tab(4) + "<ConcreteClasses>" + jPackage.getConcreteClassCount()
81                         + "</ConcreteClasses>");
82         getWriter().println(
83                 tab(4) + "<AbstractClasses>" + jPackage.getAbstractClassCount()
84                         + "</AbstractClasses>");
85         getWriter().println(
86                 tab(4) + "<Ca>" + jPackage.afferentCoupling() + "</Ca>");
87         getWriter().println(
88                 tab(4) + "<Ce>" + jPackage.efferentCoupling() + "</Ce>");
89         getWriter().println(
90                 tab(4) + "<A>" + toFormattedString(jPackage.abstractness())
91                         + "</A>");
92         getWriter().println(
93                 tab(4) + "<I>" + toFormattedString(jPackage.instability())
94                         + "</I>");
95         getWriter().println(
96                 tab(4) + "<D>" + toFormattedString(jPackage.distance())
97                         + "</D>");
98         getWriter().println(tab(4) + "<V>" + jPackage.getVolatility() + "</V>");
99         getWriter().println(tab(3) + "</Stats>");
100     }
101
102     protected void printClassName(JavaClass jClass) {
103         getWriter().println(
104                 tab(4) + "<Class sourceFile=\"" + jClass.getSourceFile()
105                         + "\">");
106         getWriter().println(tab(5) + jClass.getName());
107         getWriter().println(tab(4) + "</Class>");
108     }
109
110     protected void printPackageName(JavaPackage jPackage) {
111         getWriter().println(
112                 tab(4) + "<Package>" + jPackage.getName() + "</Package>");
113     }
114
115     protected void printAbstractClassesHeader() {
116         getWriter().println(tab(3) + "<AbstractClasses>");
117     }
118
119     protected void printAbstractClassesFooter() {
120         getWriter().println(tab(3) + "</AbstractClasses>");
121     }
122
123     protected void printConcreteClassesHeader() {
124         getWriter().println(tab(3) + "<ConcreteClasses>");
125     }
126
127     protected void printConcreteClassesFooter() {
128         getWriter().println(tab(3) + "</ConcreteClasses>");
129     }
130
131     protected void printEfferentsHeader() {
132         getWriter().println(tab(3) + "<DependsUpon>");
133     }
134
135     protected void printEfferentsFooter() {
136         getWriter().println(tab(3) + "</DependsUpon>");
137     }
138
139     protected void printEfferentsError() {
140         // do nothing
141
}
142
143     protected void printAfferentsHeader() {
144         getWriter().println(tab(3) + "<UsedBy>");
145     }
146
147     protected void printAfferentsFooter() {
148         getWriter().println(tab(3) + "</UsedBy>");
149     }
150
151     protected void printAfferentsError() {
152         // do nothing
153
}
154
155     protected void printCyclesHeader() {
156         printSectionBreak();
157         getWriter().println(tab() + "<Cycles>");
158     }
159
160     protected void printCyclesFooter() {
161         getWriter().println(tab() + "</Cycles>");
162     }
163
164     protected void printCycleHeader(JavaPackage jPackage) {
165         getWriter().println(
166                 tab(2) + "<Package Name=\"" + jPackage.getName() + "\">");
167     }
168
169     protected void printCycleFooter() {
170         getWriter().println(tab(2) + "</Package>");
171         printSectionBreak();
172     }
173
174     protected void printCycleTarget(JavaPackage jPackage) {
175         printCycleContributor(jPackage);
176     }
177
178     protected void printCycleContributor(JavaPackage jPackage) {
179         getWriter().println(
180                 tab(3) + "<Package>" + jPackage.getName() + "</Package>");
181     }
182
183     protected void printSummary(Collection packages) {
184         // do nothing
185
}
186
187     /**
188      * Main.
189      */

190     public static void main(String JavaDoc args[]) {
191         new JDepend().instanceMain(args);
192     }
193 }
Popular Tags