001: package jdepend.xmlui;
002:
003: import java.io.*;
004: import java.util.*;
005:
006: import java.text.NumberFormat;
007:
008: import jdepend.framework.JavaClass;
009: import jdepend.framework.JavaPackage;
010:
011: /**
012: * The <code>JDepend</code> class analyzes directories of Java class files,
013: * generates metrics for each Java package, and reports the metrics in an XML
014: * format.
015: *
016: * @author <b>Mike Clark</b>
017: * @author Clarkware Consulting, Inc.
018: */
019:
020: public class JDepend extends jdepend.textui.JDepend {
021:
022: /**
023: * Constructs a <code>JDepend</code> instance using standard output.
024: */
025: public JDepend() {
026: this (new PrintWriter(System.out));
027: }
028:
029: /**
030: * Constructs a <code>JDepend</code> instance with the specified writer.
031: *
032: * @param writer Writer.
033: */
034: public JDepend(PrintWriter writer) {
035: super (writer);
036:
037: formatter = NumberFormat.getInstance(Locale.ENGLISH);
038: formatter.setMaximumFractionDigits(2);
039: }
040:
041: protected void printHeader() {
042: getWriter().println("<?xml version=\"1.0\"?>");
043: getWriter().println("<JDepend>");
044: }
045:
046: protected void printFooter() {
047: getWriter().println("</JDepend>");
048: }
049:
050: protected void printPackagesHeader() {
051: getWriter().println(tab() + "<Packages>");
052: }
053:
054: protected void printPackagesFooter() {
055: getWriter().println(tab() + "</Packages>");
056: }
057:
058: protected void printPackageHeader(JavaPackage jPackage) {
059: printSectionBreak();
060: getWriter().println(
061: tab(2) + "<Package name=\"" + jPackage.getName()
062: + "\">");
063: }
064:
065: protected void printPackageFooter(JavaPackage jPackage) {
066: getWriter().println(tab(2) + "</Package>");
067: }
068:
069: protected void printNoStats() {
070: getWriter()
071: .println(
072: tab(3)
073: + "<error>No stats available: "
074: + "package referenced, but not analyzed.</error>");
075: }
076:
077: protected void printStatistics(JavaPackage jPackage) {
078: getWriter().println(tab(3) + "<Stats>");
079: getWriter().println(
080: tab(4) + "<TotalClasses>" + jPackage.getClassCount()
081: + "</TotalClasses>");
082: getWriter().println(
083: tab(4) + "<ConcreteClasses>"
084: + jPackage.getConcreteClassCount()
085: + "</ConcreteClasses>");
086: getWriter().println(
087: tab(4) + "<AbstractClasses>"
088: + jPackage.getAbstractClassCount()
089: + "</AbstractClasses>");
090: getWriter()
091: .println(
092: tab(4) + "<Ca>" + jPackage.afferentCoupling()
093: + "</Ca>");
094: getWriter()
095: .println(
096: tab(4) + "<Ce>" + jPackage.efferentCoupling()
097: + "</Ce>");
098: getWriter().println(
099: tab(4) + "<A>"
100: + toFormattedString(jPackage.abstractness())
101: + "</A>");
102: getWriter().println(
103: tab(4) + "<I>"
104: + toFormattedString(jPackage.instability())
105: + "</I>");
106: getWriter().println(
107: tab(4) + "<D>" + toFormattedString(jPackage.distance())
108: + "</D>");
109: getWriter().println(
110: tab(4) + "<V>" + jPackage.getVolatility() + "</V>");
111: getWriter().println(tab(3) + "</Stats>");
112: }
113:
114: protected void printClassName(JavaClass jClass) {
115: getWriter().println(
116: tab(4) + "<Class sourceFile=\""
117: + jClass.getSourceFile() + "\">");
118: getWriter().println(tab(5) + jClass.getName());
119: getWriter().println(tab(4) + "</Class>");
120: }
121:
122: protected void printPackageName(JavaPackage jPackage) {
123: getWriter().println(
124: tab(4) + "<Package>" + jPackage.getName()
125: + "</Package>");
126: }
127:
128: protected void printAbstractClassesHeader() {
129: getWriter().println(tab(3) + "<AbstractClasses>");
130: }
131:
132: protected void printAbstractClassesFooter() {
133: getWriter().println(tab(3) + "</AbstractClasses>");
134: }
135:
136: protected void printConcreteClassesHeader() {
137: getWriter().println(tab(3) + "<ConcreteClasses>");
138: }
139:
140: protected void printConcreteClassesFooter() {
141: getWriter().println(tab(3) + "</ConcreteClasses>");
142: }
143:
144: protected void printEfferentsHeader() {
145: getWriter().println(tab(3) + "<DependsUpon>");
146: }
147:
148: protected void printEfferentsFooter() {
149: getWriter().println(tab(3) + "</DependsUpon>");
150: }
151:
152: protected void printEfferentsError() {
153: // do nothing
154: }
155:
156: protected void printAfferentsHeader() {
157: getWriter().println(tab(3) + "<UsedBy>");
158: }
159:
160: protected void printAfferentsFooter() {
161: getWriter().println(tab(3) + "</UsedBy>");
162: }
163:
164: protected void printAfferentsError() {
165: // do nothing
166: }
167:
168: protected void printCyclesHeader() {
169: printSectionBreak();
170: getWriter().println(tab() + "<Cycles>");
171: }
172:
173: protected void printCyclesFooter() {
174: getWriter().println(tab() + "</Cycles>");
175: }
176:
177: protected void printCycleHeader(JavaPackage jPackage) {
178: getWriter().println(
179: tab(2) + "<Package Name=\"" + jPackage.getName()
180: + "\">");
181: }
182:
183: protected void printCycleFooter() {
184: getWriter().println(tab(2) + "</Package>");
185: printSectionBreak();
186: }
187:
188: protected void printCycleTarget(JavaPackage jPackage) {
189: printCycleContributor(jPackage);
190: }
191:
192: protected void printCycleContributor(JavaPackage jPackage) {
193: getWriter().println(
194: tab(3) + "<Package>" + jPackage.getName()
195: + "</Package>");
196: }
197:
198: protected void printSummary(Collection packages) {
199: // do nothing
200: }
201:
202: /**
203: * Main.
204: */
205: public static void main(String args[]) {
206: new JDepend().instanceMain(args);
207: }
208: }
|