Source Code Cross Referenced for XMLUISummary.java in  » Code-Analyzer » JarAnalyzer » com » kirkk » analyzer » textui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » JarAnalyzer » com.kirkk.analyzer.textui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.kirkk.analyzer.textui;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import com.kirkk.analyzer.framework.*;
006:        import com.kirkk.analyzer.*;
007:
008:        /*
009:         * Modified version of XMLUISummary
010:         * http://www.kirkk.com/wiki/wiki.php/Main/JarAnalyzer
011:         *
012:         * This class takes the input directory and output file
013:         * from the command line or from System.in. It is also
014:         * usable directly from Java and can be called from
015:         * an ant task
016:         */
017:        public class XMLUISummary implements  Summary {
018:            private PrintWriter writer;
019:
020:            public static void main(String args[]) throws Exception {
021:                new XMLUISummary().instanceMain(args);
022:            }
023:
024:            public void instanceMain(String args[]) throws Exception {
025:                File scrDir = (args.length > 0) ? new File(args[0]) : null;
026:                File destFile = (args.length > 1) ? new File(args[1]) : null;
027:                if (scrDir == null) {
028:                    System.out.print("Please enter input directory name: ");
029:                    scrDir = getFile();
030:                }
031:                if (destFile == null) {
032:                    System.out.print("Please enter output file name: ");
033:                    destFile = getFile();
034:                }
035:                createSummary(scrDir, destFile);
036:            }
037:
038:            public void createSummary(File srcDir, File destFile)
039:                    throws Exception {
040:                Analyzer analyzer = new Analyzer();
041:                Jar jarBundle[] = analyzer.analyze(srcDir);
042:                outputAll(jarBundle, destFile);
043:            }
044:
045:            public void createSummary(File srcDir, File destFile,
046:                    String packageFilter, String jarFilter) throws Exception {
047:                Analyzer analyzer = new Analyzer();
048:                Configuration.initialize(packageFilter, jarFilter);
049:                Jar jarBundle[] = analyzer.analyze(srcDir);
050:                outputAll(jarBundle, destFile);
051:            }
052:
053:            private File getFile() throws IOException {
054:                try {
055:                    InputStreamReader streamReader = new InputStreamReader(
056:                            System.in);
057:                    BufferedReader reader = new BufferedReader(streamReader);
058:                    String fileName = reader.readLine();
059:                    File file = new File(fileName);
060:                    return file;
061:                } catch (IOException e) {
062:                    throw e;
063:                }
064:            }
065:
066:            private void outputAll(Jar[] jarBundle, File file) {
067:                try {
068:                    FileWriter fileWriter = new FileWriter(file);
069:                    writer = new PrintWriter(fileWriter);
070:                } catch (IOException e) {
071:                    System.out
072:                            .println("IOException - Redirecting to System.out");
073:                    System.out.println(e);
074:                    OutputStreamWriter outputWriter = new OutputStreamWriter(
075:                            System.out);
076:                    writer = new PrintWriter(outputWriter);
077:                }
078:                this .printHeader();
079:                this .output(jarBundle);
080:                this .printFooter();
081:                writer.flush();
082:                writer.close();
083:            }
084:
085:            private void printHeader() {
086:                writer.println("<?xml version=\"1.0\"?>");
087:                writer.println("<JarAnalyzer>");
088:            }
089:
090:            private void printFooter() {
091:                writer.println("</JarAnalyzer>");
092:            }
093:
094:            private void output(Jar[] jarBundles) {
095:                writer.println(tab() + "<Jars>");
096:                writer.println();
097:                for (int i = 0; i < jarBundles.length; i++) {
098:                    String jar = jarBundles[i].getJarFileName()
099:                            .substring(
100:                                    jarBundles[i].getJarFileName().lastIndexOf(
101:                                            "\\") + 1,
102:                                    jarBundles[i].getJarFileName().length());
103:                    writer.println(tab(2) + "<Jar name=\"" + jar + "\">");
104:                    writer.println(tab(3) + "<Summary>");
105:                    this .statistics(jarBundles[i]);
106:                    writer.println();
107:                    this .metrics(jarBundles[i].calculateMetrics());
108:                    writer.println();
109:                    this .jarPackages(jarBundles[i]);
110:                    writer.println();
111:                    this .outgoingDependencies(jarBundles[i]);
112:                    this .incomingDependencies(jarBundles[i]);
113:                    this .cycles(jarBundles[i]);
114:                    this .unresolveableDependencies(jarBundles[i]);
115:                    writer.println(tab(3) + "</Summary>");
116:                    writer.println();
117:                    writer.println(tab(2) + "</Jar>");
118:                    writer.println();
119:                }
120:                writer.println(tab() + "</Jars>");
121:            }
122:
123:            private void statistics(Jar jarBundle) {
124:                writer.println(tab(4) + "<Statistics>");
125:                writer.println(tab(5) + "<ClassCount>"
126:                        + jarBundle.getClassCount() + "</ClassCount>");
127:                writer.println(tab(5) + "<AbstractClassCount>"
128:                        + jarBundle.getAbstractClassCount()
129:                        + "</AbstractClassCount>");
130:                writer.println(tab(5) + "<PackageCount>"
131:                        + jarBundle.getPackageCount() + "</PackageCount>");
132:                //writer.println(tab(5)+"<Level>" + jarBundle.getLevel() + "</Level>");
133:                writer.println(tab(4) + "</Statistics>");
134:            }
135:
136:            private void metrics(JarMetrics jarMetrics) {
137:                writer.println(tab(4) + "<Metrics>");
138:                writer.println(tab(5) + "<Abstractness>"
139:                        + jarMetrics.calculateAbstractness().toString()
140:                        + "</Abstractness>");
141:                writer.println(tab(5) + "<Efferent>"
142:                        + jarMetrics.calculateEfferentCoupling()
143:                        + "</Efferent>");
144:                writer.println(tab(5) + "<Afferent>"
145:                        + jarMetrics.calculateAfferentCoupling()
146:                        + "</Afferent>");
147:                writer.println(tab(5) + "<Instability>"
148:                        + jarMetrics.calculateInstability().toString()
149:                        + "</Instability>");
150:                writer.println(tab(5) + "<Distance>"
151:                        + jarMetrics.calculateDistance().toString()
152:                        + "</Distance>");
153:                writer.println(tab(4) + "</Metrics>");
154:            }
155:
156:            private void cycles(Jar jarBundle) {
157:                writer.println(tab(4) + "<Cycles>");
158:                if (jarBundle.hasCycles()) {
159:                    Iterator cyclicJars = jarBundle.getCyclicJars().iterator();
160:                    while (cyclicJars.hasNext()) {
161:                        Jar cyclicBundle = (Jar) cyclicJars.next();
162:                        String jarName = cyclicBundle.getJarFileName();
163:                        writer.println(tab(5) + "<Cycle>" + jarName
164:                                + "</Cycle>");
165:                    }
166:                }
167:                writer.println(tab(4) + "</Cycles>");
168:                writer.println();
169:            }
170:
171:            private void outgoingDependencies(Jar jarBundle) {
172:                writer.println(tab(4) + "<OutgoingDependencies>");
173:                Iterator jarDependencies = jarBundle.getOutgoingDependencies()
174:                        .iterator();
175:                while (jarDependencies.hasNext()) {
176:                    Jar dependentBundle = (Jar) jarDependencies.next();
177:                    //String jar2 = dependentBundle.getJarFileName().substring(dependentBundle.getJarFileName().lastIndexOf("\\") + 1,
178:                    //												dependentBundle.getJarFileName().length());
179:                    String jar2 = dependentBundle.getJarFileName();
180:                    writer.println(tab(5) + "<Jar>" + jar2 + "</Jar>");
181:                }
182:                writer.println(tab(4) + "</OutgoingDependencies>");
183:                writer.println();
184:            }
185:
186:            private void incomingDependencies(Jar jarBundle) {
187:                writer.println(tab(4) + "<IncomingDependencies>");
188:                Iterator jarDependencies = jarBundle.getIncomingDependencies()
189:                        .iterator();
190:                while (jarDependencies.hasNext()) {
191:                    Jar dependentBundle = (Jar) jarDependencies.next();
192:                    //String jar2 = dependentBundle.getJarFileName().substring(dependentBundle.getJarFileName().lastIndexOf("\\") + 1,
193:                    //												dependentBundle.getJarFileName().length());
194:                    String jar2 = dependentBundle.getJarFileName();
195:                    writer.println(tab(5) + "<Jar>" + jar2 + "</Jar>");
196:                }
197:                writer.println(tab(4) + "</IncomingDependencies>");
198:                writer.println();
199:            }
200:
201:            private void externalDependencies(Jar jarBundle) {
202:                Iterator allPackages = jarBundle
203:                        .getAllExternallyReferencedPackages().iterator();
204:                while (allPackages.hasNext()) {
205:                    String javaPackage = (String) allPackages.next();
206:                    writer.println(tab(5) + "<Package>" + javaPackage
207:                            + "</Package>");
208:                }
209:            }
210:
211:            private void unresolveableDependencies(Jar jarBundle) {
212:                writer.println(tab(4) + "<UnresolvedDependencies>");
213:                Iterator unresolvedPackages = jarBundle
214:                        .getAllUnidentifiableExternallyReferencedPackages()
215:                        .iterator();
216:                while (unresolvedPackages.hasNext()) {
217:                    String packageName = (String) unresolvedPackages.next();
218:                    writer.println(tab(5) + "<Package>" + packageName
219:                            + "</Package>");
220:                }
221:                writer.println(tab(4) + "</UnresolvedDependencies>");
222:            }
223:
224:            private void jarPackages(Jar jarBundle) {
225:                writer.println(tab(4) + "<Packages>");
226:                Iterator allPackages = jarBundle.getAllContainedPackages()
227:                        .iterator();
228:                while (allPackages.hasNext()) {
229:                    JarPackage javaPackage = (JarPackage) allPackages.next();
230:                    writer.println(tab(5) + "<Package>"
231:                            + javaPackage.getLongName() + "</Package>");
232:                }
233:                writer.println(tab(4) + "</Packages>");
234:            }
235:
236:            private String tab() {
237:                return "    ";
238:            }
239:
240:            private String tab(int i) {
241:                String tab = tab();
242:                for (int j = 0; j < i - 1; j++) {
243:                    tab = tab + tab();
244:                }
245:                return tab;
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.