001: /*
002: * Created on Dec 10, 2004
003: *
004: */
005: package org.hammurapi.inspectors.metrics;
006:
007: import java.util.Date;
008:
009: import org.w3c.dom.Document;
010: import org.w3c.dom.Element;
011:
012: /**
013: * @author 111001082
014: */
015: public class JarFile {
016: private String name = "undefined";
017:
018: private String version = "undefined";
019:
020: private long size = 0;
021: private Date lastChanged = new Date();
022: public boolean isUsed = false;
023:
024: public JarFile(String _name, long _size, long _lastChanged) {
025: super ();
026: name = _name;
027: version = "NA";
028: size = _size;
029: lastChanged = new Date(_lastChanged);
030: }
031:
032: public JarFile(Element jarNode) {
033: super ();
034: name = (String) jarNode.getAttribute("name");
035: version = (String) jarNode.getAttribute("version");
036:
037: String sSize = jarNode.getAttribute("size");
038: if (sSize == null || "".equals(sSize)) {
039: size = 0;
040: } else {
041: size = new Long(sSize).longValue();
042: }
043: ;
044: }
045:
046: public void setIsUsed(boolean _b) {
047: isUsed = _b;
048: }
049:
050: public Element toDom(Document document) {
051:
052: Element ret = document.createElement("JarFile");
053: ret.setAttribute("name", this .getJarNameWithoutPath());
054: ret.setAttribute("path", this .name);
055:
056: ret.setAttribute("version", this .version);
057: ret.setAttribute("size", Long.toString(this .size));
058: ret.setAttribute("lastChanged", this .lastChanged.toString());
059: ret.setAttribute("isUsed", Boolean.toString(isUsed));
060: ret.setAttribute("size", Double.toString(this .size));
061: return ret;
062: }
063:
064: public String toString() {
065:
066: StringBuffer sb = new StringBuffer();
067: sb.append(this .name);
068: sb.append("\t");
069: sb.append(this .size);
070: sb.append("\t");
071: sb.append(this .version);
072: sb.append("\t");
073: sb.append(this .lastChanged.toString());
074:
075: return sb.toString();
076: }
077:
078: /**
079: * @return Returns the name.
080: */
081: public String getName() {
082: return name;
083: }
084:
085: public String getJarNameWithoutPath() {
086: int lastSlash = getName().lastIndexOf('/');
087: int lastBackSlash = getName().lastIndexOf('\\');
088: int index = 0;
089: if (lastSlash > lastBackSlash) {
090: index = lastSlash + 1;
091: } else {
092: index = lastBackSlash + 1;
093: }
094:
095: return getName().substring(index);
096: }
097:
098: /**
099: * @param name The name to set.
100: */
101: public void setName(String name) {
102: this.name = name;
103: }
104: }
|