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.Enumeration;
029: import java.util.HashSet;
030: import java.util.Hashtable;
031: import java.util.Iterator;
032: import java.util.Vector;
033:
034: import org.w3c.dom.Document;
035: import org.w3c.dom.Element;
036:
037: public class ListOfPackageCategories extends Hashtable {
038: private String aPackage = "<not-defined>";
039: private Vector violations = new Vector();
040: private HashSet layers = new HashSet();
041:
042: public ListOfPackageCategories(String _aPackage) {
043: super ();
044: if ("".equals(_aPackage)) {
045: this .aPackage = "(default package)";
046: } else {
047: this .aPackage = _aPackage;
048: }
049: }
050:
051: public void addAll(Hashtable ht) {
052: Enumeration enumk = ht.keys();
053: Enumeration enumv = ht.elements();
054: while (enumv.hasMoreElements()) {
055: Object k = enumk.nextElement();
056: com.pavelvlasov.jsel.Package p = (com.pavelvlasov.jsel.Package) enumv
057: .nextElement();
058: this .put(k, p);
059:
060: }
061: }
062:
063: public boolean contains(String search) {
064: return super .containsKey(search);
065: }
066:
067: public ArchitecturalCategoryPackage get(String key) {
068: if (key != null) {
069: return (ArchitecturalCategoryPackage) super .get(key);
070: } else {
071: throw new NullPointerException();
072: // return null;
073: }
074:
075: }
076:
077: public static String getWithClassFcn(String keyFcn) {
078: if (keyFcn != null) {
079: int lastI = keyFcn.lastIndexOf(".");
080: if (lastI == -1) {
081: return "<default>";
082: } else {
083: String l = keyFcn.substring(0, lastI);
084: return l;
085: }
086: }
087: return "";
088: }
089:
090: public String toKey() {
091: if (this .aPackage != null) {
092:
093: return this .aPackage;
094: } else {
095: return "undefinedRoot com.pavelvlasov.jsel.PackageName";
096: }
097: }
098:
099: public Element toDom(Document document){
100:
101: Element ret=document.createElement("ListOfPackageCategories");
102: ret.setAttribute("package", this .toKey());
103: ret.setAttribute("size", String.valueOf(this .size()));
104:
105: Enumeration enum = this .elements();
106: while (enum.hasMoreElements()) {
107: ArchitecturalCategoryPackage ac = (ArchitecturalCategoryPackage) enum.nextElement();
108: ret.appendChild(ac.toDom(document));
109: }
110:
111: Element layerLst=document.createElement("LayerList");
112: ret.appendChild(layerLst);
113: Iterator it = this .layers.iterator();
114:
115: int j = 1;
116: while(it.hasNext()){
117: Element layer=document.createElement("Layer");
118: layer.setAttribute("id", String.valueOf( j ) );
119: layer.setAttribute("name", (String) it.next() );
120: layerLst.appendChild(layer);
121: j++;
122: }
123:
124: Element violaLst=document.createElement("Violation");
125: ret.appendChild(violaLst);
126:
127:
128: for (int i = 0; i < this .violations.size(); i++) {
129: Element viol=document.createElement("Layer");
130: viol.setAttribute("id", String.valueOf( (i+1) ) );
131: viol.setAttribute("name", (String) this .violations.elementAt(i) );
132: violaLst.appendChild(viol);
133: }
134:
135:
136: return ret;
137:
138: }
139:
140: /**
141: * @return
142: */
143: public Vector getViolations() {
144: return violations;
145: }
146:
147: /**
148: * @param vector
149: */
150: public void setViolations(Vector vector) {
151: violations = vector;
152: }
153:
154: /**
155: * @return
156: */
157: public HashSet getLayers() {
158: return layers;
159: }
160:
161: /**
162: * @param set
163: */
164: public void setLayers(HashSet set) {
165: layers = set;
166: }
167:
168: /**
169: * @return Returns the aPackage.
170: */
171: public String getAPackage() {
172: return aPackage;
173: }
174: }
|