1 9 10 package org.netbeans.modules.j2ee.sun.ide.avk.report.model; 11 12 import java.io.File ; 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 20 public class ReportModel { 21 22 private static ReportModel reportModel = null; 23 private String 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 37 public boolean init(String resultXML) { 38 this.resultXML = resultXML; 39 try { 40 resultDocument = AppVerification.createGraph(new File (resultXML)); 41 } catch(Throwable t) { 42 return false; 43 } 44 return true; 45 } 46 47 public String getResultsDir() { 48 File f = new File (resultXML); 49 return f.getParent(); 50 } 51 52 public List <WebComponent> getWebComponentsSuccessfullyCalled() { 53 List <WebComponent> webCompsSuccessfullyCalled = new ArrayList <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 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 <WebComponent> getWebComponentsUnSuccessfullyCalled() { 74 List <WebComponent> webCompsUnSuccessfullyCalled = new ArrayList <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 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 <WebComponent> getWebComponentsNotCalled() { 95 List <WebComponent> webCompsNotCalled = new ArrayList <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 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 <EnterpriseBean> getEJBComponentsSuccessfullyCalled() { 115 List <EnterpriseBean> ejbCompsSuccessfullyCalled = new ArrayList <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 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 <EnterpriseBean> getEJBComponentsUnSuccessfullyCalled() { 137 List <EnterpriseBean> ejbCompsUnSuccessfullyCalled = new ArrayList <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 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 <EnterpriseBean> getEJBComponentsNotCalled() { 159 List <EnterpriseBean> ejbCompsNotCalled = new ArrayList <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 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 getWebCompCoverage() { 181 String 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 t) {} 190 return webCompPercentage; 191 } 192 193 public String getEJBCompCoverage() { 194 String 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 t) {} 203 return ejbCompPercentage; 204 } 205 206 public String getApplicationName() { 207 String 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 t) {} 214 return applicationName; 215 } 216 } 217 | Popular Tags |