1 5 package org.hammurapi.inspectors.metrics; 6 7 import java.util.Date ; 8 9 import org.w3c.dom.Document ; 10 import org.w3c.dom.Element ; 11 12 15 public class JarFile { 16 private String name = "undefined"; 17 18 private String version = "undefined"; 19 20 private long size = 0; 21 private Date lastChanged = new Date (); 22 public boolean isUsed = false; 23 24 public JarFile(String _name, long _size, long _lastChanged) { 25 super(); 26 name = _name; 27 version = "NA"; 28 size = _size; 29 lastChanged = new Date ( _lastChanged ); 30 } 31 public JarFile(Element jarNode) { 32 super(); 33 name = (String )jarNode.getAttribute("name"); 34 version = (String )jarNode.getAttribute("version"); 35 36 String sSize = jarNode.getAttribute("size"); 37 if( sSize == null || "".equals( sSize) ){ 38 size = 0; 39 } else { 40 size = new Long (sSize).longValue(); 41 }; 42 } 43 public void setIsUsed(boolean _b){ 44 isUsed = _b; 45 } 46 47 public Element toDom(Document document){ 48 49 Element ret=document.createElement("JarFile"); 50 ret.setAttribute("name", this.getJarNameWithoutPath() ); 51 ret.setAttribute("path", this.name ); 52 53 ret.setAttribute("version", this.version ); 54 ret.setAttribute("size", Long.toString(this.size) ); 55 ret.setAttribute("lastChanged", this.lastChanged.toString() ); 56 ret.setAttribute("isUsed", Boolean.toString(isUsed) ); 57 ret.setAttribute("size", Double.toString(this.size )); 58 return ret; 59 } 60 61 62 public String toString(){ 63 64 StringBuffer sb = new StringBuffer (); 65 sb.append( this.name ); 66 sb.append( "\t"); 67 sb.append( this.size ); 68 sb.append( "\t"); 69 sb.append( this.version ); 70 sb.append( "\t"); 71 sb.append( this.lastChanged.toString() ); 72 73 return sb.toString(); 74 } 75 78 public String getName() { 79 return name; 80 } 81 public String getJarNameWithoutPath(){ 82 int lastSlash = getName().lastIndexOf('/'); 83 int lastBackSlash = getName().lastIndexOf('\\'); 84 int index =0; 85 if( lastSlash > lastBackSlash){ 86 index = lastSlash+1; 87 }else{ 88 index = lastBackSlash+1; 89 } 90 91 return getName().substring(index); 92 } 93 96 public void setName(String name) { 97 this.name = name; 98 } 99 } | Popular Tags |