KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Johannes Bellert
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.pavelvlasov.com/pv/content/menu.show?id=products.jtaste
21  * e-Mail: Johannes.Bellert@ercgroup.com
22  *
23  * * Created on Mar 20, 2004
24  *
25  */

26 package org.hammurapi.inspectors.metrics;
27
28 import java.util.Vector JavaDoc;
29
30 import org.w3c.dom.DOMException JavaDoc;
31 import org.w3c.dom.Document JavaDoc;
32 import org.w3c.dom.Element JavaDoc;
33
34 public class ListOfCategories extends Vector JavaDoc {
35     //!! no hard references to JSel Classes
36
//!! refactor
37
private String JavaDoc type = "";
38     private String JavaDoc source_url = "";
39     private int source_line = 0;
40     private int source_col = 0;
41     
42     private String JavaDoc aPackage = null;
43     private Vector JavaDoc violations = new Vector JavaDoc();
44
45     public ListOfCategories( String JavaDoc typeName, String JavaDoc source_url, int line, int col){
46         super();
47         
48         this.type = typeName;
49         this.source_url = source_url;
50         this.source_col = col;
51         this.source_line = line;
52     }
53     
54     public boolean contains(String JavaDoc search){
55         boolean found = false;
56         for(int i=0; i< this.size(); i++){
57                 ArchitecturalCategory ac =(ArchitecturalCategory)this.elementAt(i);
58                 if ( search != null && ac.categoryType!= null && ac.categoryType.equals(search)){
59                     return true;
60                 }
61                 }
62         return found;
63     }
64
65     public String JavaDoc toKey() {
66         if (this.getType() != null ) {
67             return this.getType();
68         } else {
69             return "unDefinedKey";
70         }
71     }
72
73     public Element JavaDoc toDom(Document JavaDoc document){
74
75         Element JavaDoc ret=document.createElement("ListOfClassCategories");
76         Element JavaDoc typ=document.createElement("SourceMarker");
77         if(this.type != null){
78             try {
79                 ret.setAttribute("class",this.type );
80                 
81                 typ.setAttribute("source-url", source_url);
82                 typ.setAttribute("line", String.valueOf( source_line ));
83                 typ.setAttribute("col", String.valueOf( source_col ));
84
85             } catch (DOMException JavaDoc e) {
86                 // TODO Auto-generated catch block
87
e.printStackTrace();
88             }
89         }
90         ret.setAttribute("size", String.valueOf(this.size()));
91         ret.appendChild(typ);
92
93         for(int i=0; i< this.size(); i++){
94             ArchitecturalCategory ac =(ArchitecturalCategory)this.elementAt(i);
95             ret.appendChild(ac.toDom(document));
96         }
97
98         Element JavaDoc violaLst=document.createElement("LayerList");
99         ret.appendChild(violaLst);
100
101         for (int i = 0; i < this.violations.size(); i++) {
102             Element JavaDoc viol=document.createElement("Layer");
103             viol.setAttribute("id", String.valueOf( (i+1) ) );
104             viol.setAttribute("name", (String JavaDoc) this.violations.elementAt(i) );
105             violaLst.appendChild(viol);
106         }
107         return ret;
108     }
109
110     public StringBuffer JavaDoc toXml() {
111         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
112
113             sb.append("<ListOfCategories class=\"");
114             sb.append( this.getType() );
115
116         sb.append("\" size=\"");
117         sb.append(this.size());
118         sb.append("\">");
119
120         sb.append("<Violations>");
121         for (int i = 0; i < this.violations.size(); i++) {
122             sb.append("<Violation id=\"" + (i+1) + "\">");
123             sb.append((String JavaDoc) this.violations.elementAt(i));
124             sb.append("</Violation>");
125         }
126
127         sb.append("</Violations>");
128
129
130         for(int i=0; i< this.size(); i++){
131         ArchitecturalCategory ac =(ArchitecturalCategory)this.elementAt(i);
132 // sb.append(ac.toXml());
133
}
134         sb.append("</ListOfCategories>");
135         return sb;
136     }
137
138     /**
139      * @return
140      */

141     public String JavaDoc getType() {
142
143         return type;
144     }
145
146     /**
147      * @param type
148      */

149     public void setType(String JavaDoc type) {
150         this.type = type;
151     }
152
153     /**
154      * @return
155      */

156     public Vector JavaDoc getViolations() {
157         return violations;
158     }
159
160     /**
161      * @param vector
162      */

163     public void setViolations(Vector JavaDoc vector) {
164         violations = vector;
165     }
166
167     /**
168      * @return Returns the source_url.
169      */

170     public String JavaDoc getSourceURL() {
171         return source_url;
172     }
173     /**
174      * @param source_url The source_url to set.
175      */

176     public void setSourceURL(String JavaDoc source_url) {
177         this.source_url = source_url;
178     }
179 }
180
Popular Tags