KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > avk > report > model > ReportModel


1 /*
2  * ReportModel.java
3  *
4  * Created on April 11, 2006, 4:38 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.j2ee.sun.ide.avk.report.model;
11
12 import java.io.File JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  *
18  * @author bshankar@sun.com
19  */

20 public class ReportModel {
21     
22     private static ReportModel reportModel = null;
23     private String JavaDoc resultXML;
24     
25     public synchronized static ReportModel getInstance() {
26         if(reportModel == null) {
27             reportModel = new ReportModel();
28         }
29         return reportModel;
30     }
31     
32     private AppVerification resultDocument;
33     
34     /**
35      * Generate the result document for the given result.xml file.
36      */

37     public boolean init(String JavaDoc resultXML) {
38         this.resultXML = resultXML;
39         try {
40             resultDocument = AppVerification.createGraph(new File JavaDoc(resultXML));
41         } catch(Throwable JavaDoc t) {
42             return false;
43         }
44         return true;
45     }
46     
47     public String JavaDoc getResultsDir() {
48         File JavaDoc f = new File JavaDoc(resultXML);
49         return f.getParent();
50     }
51     
52     public List JavaDoc<WebComponent> getWebComponentsSuccessfullyCalled() {
53         List JavaDoc<WebComponent> webCompsSuccessfullyCalled = new ArrayList JavaDoc<WebComponent>();
54         if(resultDocument != null) {
55             WebComponent[] webComps = resultDocument.getWebComponent();
56             for(WebComponent webComp : webComps) {
57                 WebEntity[] webEntities = webComp.getWebEntity();
58                 for(WebEntity webEntity : webEntities) {
59                     AppVerificationException[] exceptions = webEntity.getAppVerificationException();
60                     String JavaDoc invocations = webEntity.getCounter();
61                     if((exceptions == null || exceptions.length == 0) && !("0".equals(invocations))) {
62                         WebComponent newWebComp = new WebComponent();
63                         newWebComp.setContext(webComp.getContext());
64                         newWebComp.setWebEntity(new WebEntity[]{webEntity});
65                         webCompsSuccessfullyCalled.add(newWebComp);
66                     }
67                 }
68             }
69         }
70         return webCompsSuccessfullyCalled;
71     }
72     
73     public List JavaDoc<WebComponent> getWebComponentsUnSuccessfullyCalled() {
74         List JavaDoc<WebComponent> webCompsUnSuccessfullyCalled = new ArrayList JavaDoc<WebComponent>();
75         if(resultDocument != null) {
76             WebComponent[] webComps = resultDocument.getWebComponent();
77             for(WebComponent webComp : webComps) {
78                 WebEntity[] webEntities = webComp.getWebEntity();
79                 for(WebEntity webEntity : webEntities) {
80                     AppVerificationException[] exceptions = webEntity.getAppVerificationException();
81                     String JavaDoc invocations = webEntity.getCounter();
82                     if((exceptions != null && exceptions.length != 0)) {
83                         WebComponent newWebComp = new WebComponent();
84                         newWebComp.setContext(webComp.getContext());
85                         newWebComp.setWebEntity(new WebEntity[]{webEntity});
86                         webCompsUnSuccessfullyCalled.add(newWebComp);
87                     }
88                 }
89             }
90         }
91         return webCompsUnSuccessfullyCalled;
92     }
93     
94     public List JavaDoc<WebComponent> getWebComponentsNotCalled() {
95         List JavaDoc<WebComponent> webCompsNotCalled = new ArrayList JavaDoc<WebComponent>();
96         if(resultDocument != null) {
97             WebComponent[] webComps = resultDocument.getWebComponent();
98             for(WebComponent webComp : webComps) {
99                 WebEntity[] webEntities = webComp.getWebEntity();
100                 for(WebEntity webEntity : webEntities) {
101                     String JavaDoc invocations = webEntity.getCounter();
102                     if(("0".equals(invocations))) {
103                         WebComponent newWebComp = new WebComponent();
104                         newWebComp.setContext(webComp.getContext());
105                         newWebComp.setWebEntity(new WebEntity[]{webEntity});
106                         webCompsNotCalled.add(newWebComp);
107                     }
108                 }
109             }
110         }
111         return webCompsNotCalled;
112     }
113     
114     public List JavaDoc<EnterpriseBean> getEJBComponentsSuccessfullyCalled() {
115         List JavaDoc<EnterpriseBean> ejbCompsSuccessfullyCalled = new ArrayList JavaDoc<EnterpriseBean>();
116         if(resultDocument != null) {
117             EnterpriseBean[] ejbs = resultDocument.getEnterpriseBean();
118             for(EnterpriseBean ejb : ejbs) {
119                 Method[] ejbMethods = ejb.getMethod();
120                 for(Method ejbMethod : ejbMethods) {
121                     AppVerificationException[] exceptions = ejbMethod.getAppVerificationException();
122                     String JavaDoc invocations = ejbMethod.getCounter();
123                     if((exceptions == null || exceptions.length == 0) && !("0".equals(invocations))) {
124                         EnterpriseBean newEJB = new EnterpriseBean();
125                         newEJB.setBeanName(ejb.getBeanName());
126                         newEJB.setAppName(ejb.getAppName());
127                         newEJB.setMethod(new Method[]{ejbMethod});
128                         ejbCompsSuccessfullyCalled.add(newEJB);
129                     }
130                 }
131             }
132         }
133         return ejbCompsSuccessfullyCalled;
134     }
135     
136     public List JavaDoc<EnterpriseBean> getEJBComponentsUnSuccessfullyCalled() {
137         List JavaDoc<EnterpriseBean> ejbCompsUnSuccessfullyCalled = new ArrayList JavaDoc<EnterpriseBean>();
138         if(resultDocument != null) {
139             EnterpriseBean[] ejbs = resultDocument.getEnterpriseBean();
140             for(EnterpriseBean ejb : ejbs) {
141                 Method[] ejbMethods = ejb.getMethod();
142                 for(Method ejbMethod : ejbMethods) {
143                     AppVerificationException[] exceptions = ejbMethod.getAppVerificationException();
144                     String JavaDoc invocations = ejbMethod.getCounter();
145                     if((exceptions != null && exceptions.length != 0)) {
146                         EnterpriseBean newEJB = new EnterpriseBean();
147                         newEJB.setBeanName(ejb.getBeanName());
148                         newEJB.setAppName(ejb.getAppName());
149                         newEJB.setMethod(new Method[]{ejbMethod});
150                         ejbCompsUnSuccessfullyCalled.add(newEJB);
151                     }
152                 }
153             }
154         }
155         return ejbCompsUnSuccessfullyCalled;
156     }
157     
158     public List JavaDoc<EnterpriseBean> getEJBComponentsNotCalled() {
159         List JavaDoc<EnterpriseBean> ejbCompsNotCalled = new ArrayList JavaDoc<EnterpriseBean>();
160         if(resultDocument != null) {
161             EnterpriseBean[] ejbs = resultDocument.getEnterpriseBean();
162             for(EnterpriseBean ejb : ejbs) {
163                 Method[] ejbMethods = ejb.getMethod();
164                 for(Method ejbMethod : ejbMethods) {
165                     String JavaDoc invocations = ejbMethod.getCounter();
166                     if("0".equals(invocations)) {
167                         EnterpriseBean newEJB = new EnterpriseBean();
168                         newEJB.setBeanName(ejb.getBeanName());
169                         newEJB.setAppName(ejb.getAppName());
170                         newEJB.setMethod(new Method[]{ejbMethod});
171                         ejbCompsNotCalled.add(newEJB);
172                     }
173                 }
174             }
175         }
176         return ejbCompsNotCalled;
177     }
178     
179     
180     public String JavaDoc getWebCompCoverage() {
181         String JavaDoc webCompPercentage = "N.A";
182         try {
183             webCompPercentage = resultDocument.getPercentage().getWebPercentage();
184             if (webCompPercentage != null && webCompPercentage.trim().length() != 0) {
185                 webCompPercentage += "%";
186             } else {
187                 webCompPercentage = "N.A";
188             }
189         } catch(Throwable JavaDoc t) {}
190         return webCompPercentage;
191     }
192     
193     public String JavaDoc getEJBCompCoverage() {
194         String JavaDoc ejbCompPercentage = "N.A";
195         try {
196             ejbCompPercentage = resultDocument.getPercentage().getBeanPercentage(0).getEjbPercentage();
197             if (ejbCompPercentage != null && ejbCompPercentage.trim().length() != 0) {
198                 ejbCompPercentage += "%";
199             } else {
200                 ejbCompPercentage = "N.A";
201             }
202         } catch(Throwable JavaDoc t) {}
203         return ejbCompPercentage;
204     }
205     
206     public String JavaDoc getApplicationName() {
207         String JavaDoc applicationName = "NONE";
208         try {
209             applicationName = resultDocument.getPercentage().getBeanPercentage(0).getAppName();
210             if (applicationName == null || applicationName.trim().length() == 0) {
211                 applicationName = "NONE";
212             }
213         } catch(Throwable JavaDoc t) {}
214         return applicationName;
215     }
216 }
217
Popular Tags