001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.pavelvlasov.com/pv/content/menu.show?id=products.jtaste
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: *
023: * * Created on Mar 20, 2004
024: *
025: */
026: package org.hammurapi.inspectors.metrics;
027:
028: import java.util.Vector;
029:
030: import org.w3c.dom.DOMException;
031: import org.w3c.dom.Document;
032: import org.w3c.dom.Element;
033:
034: public class ListOfCategories extends Vector {
035: //!! no hard references to JSel Classes
036: //!! refactor
037: private String type = "";
038: private String source_url = "";
039: private int source_line = 0;
040: private int source_col = 0;
041:
042: private String aPackage = null;
043: private Vector violations = new Vector();
044:
045: public ListOfCategories(String typeName, String source_url,
046: int line, int col) {
047: super ();
048:
049: this .type = typeName;
050: this .source_url = source_url;
051: this .source_col = col;
052: this .source_line = line;
053: }
054:
055: public boolean contains(String search) {
056: boolean found = false;
057: for (int i = 0; i < this .size(); i++) {
058: ArchitecturalCategory ac = (ArchitecturalCategory) this
059: .elementAt(i);
060: if (search != null && ac.categoryType != null
061: && ac.categoryType.equals(search)) {
062: return true;
063: }
064: }
065: return found;
066: }
067:
068: public String toKey() {
069: if (this .getType() != null) {
070: return this .getType();
071: } else {
072: return "unDefinedKey";
073: }
074: }
075:
076: public Element toDom(Document document) {
077:
078: Element ret = document.createElement("ListOfClassCategories");
079: Element typ = document.createElement("SourceMarker");
080: if (this .type != null) {
081: try {
082: ret.setAttribute("class", this .type);
083:
084: typ.setAttribute("source-url", source_url);
085: typ.setAttribute("line", String.valueOf(source_line));
086: typ.setAttribute("col", String.valueOf(source_col));
087:
088: } catch (DOMException e) {
089: // TODO Auto-generated catch block
090: e.printStackTrace();
091: }
092: }
093: ret.setAttribute("size", String.valueOf(this .size()));
094: ret.appendChild(typ);
095:
096: for (int i = 0; i < this .size(); i++) {
097: ArchitecturalCategory ac = (ArchitecturalCategory) this
098: .elementAt(i);
099: ret.appendChild(ac.toDom(document));
100: }
101:
102: Element violaLst = document.createElement("LayerList");
103: ret.appendChild(violaLst);
104:
105: for (int i = 0; i < this .violations.size(); i++) {
106: Element viol = document.createElement("Layer");
107: viol.setAttribute("id", String.valueOf((i + 1)));
108: viol.setAttribute("name", (String) this .violations
109: .elementAt(i));
110: violaLst.appendChild(viol);
111: }
112: return ret;
113: }
114:
115: public StringBuffer toXml() {
116: StringBuffer sb = new StringBuffer();
117:
118: sb.append("<ListOfCategories class=\"");
119: sb.append(this .getType());
120:
121: sb.append("\" size=\"");
122: sb.append(this .size());
123: sb.append("\">");
124:
125: sb.append("<Violations>");
126: for (int i = 0; i < this .violations.size(); i++) {
127: sb.append("<Violation id=\"" + (i + 1) + "\">");
128: sb.append((String) this .violations.elementAt(i));
129: sb.append("</Violation>");
130: }
131:
132: sb.append("</Violations>");
133:
134: for (int i = 0; i < this .size(); i++) {
135: ArchitecturalCategory ac = (ArchitecturalCategory) this
136: .elementAt(i);
137: // sb.append(ac.toXml());
138: }
139: sb.append("</ListOfCategories>");
140: return sb;
141: }
142:
143: /**
144: * @return
145: */
146: public String getType() {
147:
148: return type;
149: }
150:
151: /**
152: * @param type
153: */
154: public void setType(String type) {
155: this .type = type;
156: }
157:
158: /**
159: * @return
160: */
161: public Vector getViolations() {
162: return violations;
163: }
164:
165: /**
166: * @param vector
167: */
168: public void setViolations(Vector vector) {
169: violations = vector;
170: }
171:
172: /**
173: * @return Returns the source_url.
174: */
175: public String getSourceURL() {
176: return source_url;
177: }
178:
179: /**
180: * @param source_url The source_url to set.
181: */
182: public void setSourceURL(String source_url) {
183: this.source_url = source_url;
184: }
185: }
|