KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > JarFile


1 /*
2  * Created on Dec 10, 2004
3  *
4  */

5 package org.hammurapi.inspectors.metrics;
6
7 import java.util.Date JavaDoc;
8
9 import org.w3c.dom.Document JavaDoc;
10 import org.w3c.dom.Element JavaDoc;
11
12 /**
13  * @author 111001082
14  */

15 public class JarFile {
16     private String JavaDoc name = "undefined";
17
18     private String JavaDoc version = "undefined";
19
20     private long size = 0;
21     private Date JavaDoc lastChanged = new Date JavaDoc();
22     public boolean isUsed = false;
23
24     public JarFile(String JavaDoc _name, long _size, long _lastChanged) {
25         super();
26         name = _name;
27         version = "NA";
28         size = _size;
29         lastChanged = new Date JavaDoc( _lastChanged );
30     }
31     public JarFile(Element JavaDoc jarNode) {
32         super();
33         name = (String JavaDoc)jarNode.getAttribute("name");
34         version = (String JavaDoc)jarNode.getAttribute("version");
35         
36         String JavaDoc sSize = jarNode.getAttribute("size");
37         if( sSize == null || "".equals( sSize) ){
38             size = 0;
39         } else {
40             size = new Long JavaDoc(sSize).longValue();
41         };
42     }
43     public void setIsUsed(boolean _b){
44         isUsed = _b;
45     }
46
47     public Element JavaDoc toDom(Document JavaDoc document){
48
49         Element JavaDoc 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 JavaDoc toString(){
63
64         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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     /**
76      * @return Returns the name.
77      */

78     public String JavaDoc getName() {
79         return name;
80     }
81     public String JavaDoc 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     /**
94      * @param name The name to set.
95      */

96     public void setName(String JavaDoc name) {
97         this.name = name;
98     }
99 }
Popular Tags