KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on Mar 14, 2004
3  *
4  * To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */

7 package org.hammurapi.inspectors.metrics;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Vector JavaDoc;
11
12 import org.w3c.dom.Document JavaDoc;
13 import org.w3c.dom.Element JavaDoc;
14
15 /**
16  * @author mucbj0
17  *
18  * To change the template for this generated type comment go to
19  * Window - Preferences - Java - Code Generation - Code and Comments
20  */

21 public class CodeMetric {
22
23     // private SourceMarker srcCodeMarker;
24
public String JavaDoc source_url = "";
25     public int source_line = 0;
26     public int source_col = 0;
27
28     private String JavaDoc descriptonEntity = "NA";
29     private String JavaDoc name = "NA";
30     private String JavaDoc sourceURL;
31     private int number = 0;
32     private int ncss = 0;
33     private int function = 0;
34     private double functionAverage = 0.0;
35     private double classAverage = 0.0;
36     private Vector JavaDoc children = new Vector JavaDoc();
37
38
39     public Element JavaDoc toDom(Document JavaDoc document){
40
41         Element JavaDoc ret=document.createElement("SourceCodeMetric"+descriptonEntity);
42         ret.setAttribute("name", name);
43         try{
44         if ( source_url != null && !"".equals (source_url) ){
45
46             // packageName.replace('.','/')+compilationUnit.getName()
47
ret.setAttribute("source-url", source_url);
48             ret.setAttribute("line", String.valueOf(source_line));
49             ret.setAttribute("col", String.valueOf(source_col));
50         } else {
51             ret.setAttribute("line", "0" );
52             ret.setAttribute("col", "0" );
53
54         }
55         } catch ( Exception JavaDoc e){
56             e.printStackTrace();
57         }
58
59         Element JavaDoc entities=document.createElement("Entities");
60         ret.appendChild(entities);
61         entities.setAttribute("number", String.valueOf(number));
62
63         Element JavaDoc ncssE=document.createElement("NCSS");
64         ret.appendChild(ncssE);
65         ncssE.setAttribute( "number", String.valueOf( this.ncss ) );
66
67
68         Element JavaDoc functions=document.createElement("Functions");
69         ret.appendChild(functions);
70         functions.setAttribute("number", String.valueOf(function));
71
72
73         Iterator JavaDoc it=children.iterator();
74         while (it.hasNext()){
75             CodeMetric cm = (CodeMetric) it.next();
76             ret.appendChild(cm.toDom(document));
77         }
78
79         return ret;
80     }
81
82     public String JavaDoc toString(){
83         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
84         sb.append(descriptonEntity);
85         sb.append(" - ");
86         sb.append(this.name);
87         return sb.toString();
88     }
89
90     /**
91      * @return Returns the children.
92      */

93     public Vector JavaDoc getChildren() {
94         return children;
95     }
96     /**
97      * @param children The children to set.
98      */

99     public void setChildren(Vector JavaDoc children) {
100         this.children = children;
101     }
102     /**
103      * @return Returns the descriptonEntity.
104      */

105     public String JavaDoc getDescriptonEntity() {
106         return descriptonEntity;
107     }
108     /**
109      * @param descriptonEntity The descriptonEntity to set.
110      */

111     public void setDescriptonEntity(String JavaDoc descriptonEntity) {
112         this.descriptonEntity = descriptonEntity;
113     }
114     /**
115      * @return Returns the function.
116      */

117     public int getFunction() {
118         return function;
119     }
120     /**
121      * @param function The function to set.
122      */

123     public void setFunction(int function) {
124         this.function = function;
125     }
126     /**
127      * @return Returns the name.
128      */

129     public String JavaDoc getName() {
130         return name;
131     }
132     /**
133      * @param name The name to set.
134      */

135     public void setName(String JavaDoc name) {
136         this.name = name;
137     }
138     /**
139      * @return Returns the ncss.
140      */

141     public int getNcss() {
142         return ncss;
143     }
144     /**
145      * @param ncss The ncss to set.
146      */

147     public void setNcss(int ncss) {
148         this.ncss = ncss;
149     }
150     /**
151      * @return Returns the number.
152      */

153     public int getNumber() {
154         return number;
155     }
156     /**
157      * @param number The number to set.
158      */

159     public void setNumber(int number) {
160         this.number = number;
161     }
162     
163     /**
164      * @return Returns the srcCodeMarker.
165      */

166     public String JavaDoc getSrcCodeUrl() {
167         return source_url;
168     }
169     
170 }
171
Popular Tags