001: /*
002: * Created on Mar 14, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.hammurapi.inspectors.metrics;
008:
009: import java.util.Iterator;
010: import java.util.Vector;
011:
012: import org.w3c.dom.Document;
013: import org.w3c.dom.Element;
014:
015: /**
016: * @author mucbj0
017: *
018: * To change the template for this generated type comment go to
019: * Window - Preferences - Java - Code Generation - Code and Comments
020: */
021: public class CodeMetric {
022:
023: // private SourceMarker srcCodeMarker;
024: public String source_url = "";
025: public int source_line = 0;
026: public int source_col = 0;
027:
028: private String descriptonEntity = "NA";
029: private String name = "NA";
030: private String sourceURL;
031: private int number = 0;
032: private int ncss = 0;
033: private int function = 0;
034: private double functionAverage = 0.0;
035: private double classAverage = 0.0;
036: private Vector children = new Vector();
037:
038: public Element toDom(Document document) {
039:
040: Element ret = document.createElement("SourceCodeMetric"
041: + descriptonEntity);
042: ret.setAttribute("name", name);
043: try {
044: if (source_url != null && !"".equals(source_url)) {
045:
046: // packageName.replace('.','/')+compilationUnit.getName()
047: ret.setAttribute("source-url", source_url);
048: ret.setAttribute("line", String.valueOf(source_line));
049: ret.setAttribute("col", String.valueOf(source_col));
050: } else {
051: ret.setAttribute("line", "0");
052: ret.setAttribute("col", "0");
053:
054: }
055: } catch (Exception e) {
056: e.printStackTrace();
057: }
058:
059: Element entities = document.createElement("Entities");
060: ret.appendChild(entities);
061: entities.setAttribute("number", String.valueOf(number));
062:
063: Element ncssE = document.createElement("NCSS");
064: ret.appendChild(ncssE);
065: ncssE.setAttribute("number", String.valueOf(this .ncss));
066:
067: Element functions = document.createElement("Functions");
068: ret.appendChild(functions);
069: functions.setAttribute("number", String.valueOf(function));
070:
071: Iterator it = children.iterator();
072: while (it.hasNext()) {
073: CodeMetric cm = (CodeMetric) it.next();
074: ret.appendChild(cm.toDom(document));
075: }
076:
077: return ret;
078: }
079:
080: public String toString() {
081: StringBuffer sb = new StringBuffer();
082: sb.append(descriptonEntity);
083: sb.append(" - ");
084: sb.append(this .name);
085: return sb.toString();
086: }
087:
088: /**
089: * @return Returns the children.
090: */
091: public Vector getChildren() {
092: return children;
093: }
094:
095: /**
096: * @param children The children to set.
097: */
098: public void setChildren(Vector children) {
099: this .children = children;
100: }
101:
102: /**
103: * @return Returns the descriptonEntity.
104: */
105: public String getDescriptonEntity() {
106: return descriptonEntity;
107: }
108:
109: /**
110: * @param descriptonEntity The descriptonEntity to set.
111: */
112: public void setDescriptonEntity(String descriptonEntity) {
113: this .descriptonEntity = descriptonEntity;
114: }
115:
116: /**
117: * @return Returns the function.
118: */
119: public int getFunction() {
120: return function;
121: }
122:
123: /**
124: * @param function The function to set.
125: */
126: public void setFunction(int function) {
127: this .function = function;
128: }
129:
130: /**
131: * @return Returns the name.
132: */
133: public String getName() {
134: return name;
135: }
136:
137: /**
138: * @param name The name to set.
139: */
140: public void setName(String name) {
141: this .name = name;
142: }
143:
144: /**
145: * @return Returns the ncss.
146: */
147: public int getNcss() {
148: return ncss;
149: }
150:
151: /**
152: * @param ncss The ncss to set.
153: */
154: public void setNcss(int ncss) {
155: this .ncss = ncss;
156: }
157:
158: /**
159: * @return Returns the number.
160: */
161: public int getNumber() {
162: return number;
163: }
164:
165: /**
166: * @param number The number to set.
167: */
168: public void setNumber(int number) {
169: this .number = number;
170: }
171:
172: /**
173: * @return Returns the srcCodeMarker.
174: */
175: public String getSrcCodeUrl() {
176: return source_url;
177: }
178:
179: }
|