1 26 package org.hammurapi.inspectors.metrics; 27 28 import java.util.Vector ; 29 30 import org.apache.xpath.CachedXPathAPI; 31 import org.apache.xpath.XPathAPI; 32 import org.hammurapi.HammurapiException; 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.Element ; 35 import org.w3c.dom.Node ; 36 import org.w3c.dom.traversal.NodeIterator; 37 38 42 public class TechStackEntity { 43 44 private String name = ""; 45 private String rating = "<undefined>"; 46 private String complexity = ""; 47 private String homeUrl = "NA"; 48 49 50 51 public boolean markIfPartOfJarFileList(String jarName){ 52 boolean ret = false; 53 int i=0; 54 while( !ret && i<getJarFileList().size()){ 55 JarFile jf = (JarFile)getJarFileList().elementAt(i); 56 System.out.println( jarName +" <> " +jf.getName()); 57 if(jarName.equals(jf.getName()) ){ 58 jf.setIsUsed(true); 59 ret =true; 60 } 61 i++; 62 } 63 return ret; 64 } 65 66 69 public Vector getJarFileList() { 70 return jarFileList; 71 } 72 75 public void setJarFileList(Vector jarFileList) { 76 this.jarFileList = jarFileList; 77 } 78 81 public Vector getLicenseList() { 82 return licenseList; 83 } 84 87 public void setLicenseList(Vector licenseList) { 88 this.licenseList = licenseList; 89 } 90 private Vector licenseList = new Vector (); 91 private Vector jarFileList = new Vector (); 92 private Vector variableMapping = new Vector (); 93 private Vector extensionMapping = new Vector (); 94 95 98 public Vector getExtensionMapping() { 99 return extensionMapping; 100 } 101 104 public void setExtensionMapping(Vector extensionMapping) { 105 this.extensionMapping = extensionMapping; 106 } 107 110 public Vector getVariableMapping() { 111 return variableMapping; 112 } 113 116 public void setVariableMapping(Vector variableMapping) { 117 this.variableMapping = variableMapping; 118 } 119 120 public TechStackEntity(Element holder) throws HammurapiException { 121 super(); 122 try { 123 CachedXPathAPI cxpa=new CachedXPathAPI(); 124 125 name = holder.getAttribute("name") ; 126 127 rating = holder.getAttribute("rating") ; 128 complexity = holder.getAttribute("complexity") ; 129 130 NodeIterator itvmNode=XPathAPI.selectNodeIterator(holder, "VariableMapping"); 131 Node vmNode; 132 while ((vmNode=itvmNode.nextNode())!=null) { 133 if (vmNode instanceof Element ) { 134 this.variableMapping.add( (String )((Element )vmNode).getAttribute("name") ); 136 } 137 } 138 NodeIterator itxmNode=XPathAPI.selectNodeIterator(holder, "ExtensionMapping"); 139 Node xmNode; 140 while ((xmNode=itxmNode.nextNode())!=null) { 141 if (xmNode instanceof Element ) { 142 this.extensionMapping.add( (String )((Element )xmNode).getAttribute("name") ); 144 } 145 } 146 147 NodeIterator itLicNode=XPathAPI.selectNodeIterator(holder, "License"); 148 Node licNode; 149 while ((licNode=itLicNode.nextNode())!=null) { 150 if (licNode instanceof Element ) { 151 this.licenseList.add( (String )((Element )licNode).getAttribute("name") ); 152 } 153 } 154 NodeIterator itJarNode=XPathAPI.selectNodeIterator(holder, "JarFile"); 155 Node jarNode; 156 while ((jarNode=itJarNode.nextNode())!=null) { 157 if (jarNode instanceof Element ) { 158 this.jarFileList.add( new JarFile( (Element )jarNode) ); 159 } 160 } 161 NodeIterator itHome=XPathAPI.selectNodeIterator(holder, "Home"); 162 Node homeNode; 163 while ((homeNode=itHome.nextNode())!=null) { 164 if (homeNode instanceof Element ) { 165 this.homeUrl = (String )((Element )homeNode).getAttribute("url"); 166 } 167 } 168 }catch (Exception e){ 169 throw new HammurapiException(e); 170 } 171 } 172 173 public String toString(){ 174 return name ; 175 } 176 179 public String getComplexity() { 180 return complexity; 181 } 182 185 public void setComplexity(String complexity) { 186 this.complexity = complexity; 187 } 188 191 public String getName() { 192 return name; 193 } 194 197 public void setName(String name) { 198 this.name = name; 199 } 200 203 public String getRating() { 204 return rating; 205 } 206 209 public void setRating(String rating) { 210 this.rating = rating; 211 } 212 public TechStackEntity( String _name, String _rating){ 213 super(); 214 name = _name; 215 rating = _rating; 216 217 } 218 219 public Element toDom(Document document){ 220 221 Element ret=document.createElement("TechStackEntity"); 222 ret.setAttribute("name", this.name ); 223 224 ret.setAttribute("complexity", this.complexity ); 225 ret.setAttribute("rating", this.rating ); 226 227 for(int i=0; i<licenseList.size(); i++){ 228 Element retA=document.createElement("License"); 229 retA.setAttribute("name", (String ) this.licenseList.elementAt(i)); 230 ret.appendChild( retA); 231 } 232 233 for(int i=0; i<jarFileList.size(); i++){ 234 ret.appendChild( ((JarFile)jarFileList.elementAt(i)).toDom(document) ); 235 } 236 Element retURL=document.createElement("Home"); 237 retURL.setAttribute("url", this.homeUrl ); 238 ret.appendChild( retURL); 239 return ret; 240 } 241 242 } 243 | Popular Tags |