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 Apr 10, 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: /**
038: * @author Johannes Bellert
039: *
040: */
041: public class ListOfLayers {
042:
043: private Hashtable layers = new Hashtable();
044:
045: public ListOfLayers(Hashtable allCategorizedPackages) {
046:
047: Vector alreadyVisitedPackages = new Vector();
048: Enumeration enumKeys = allCategorizedPackages.keys();
049: while (enumKeys.hasMoreElements()) {
050: String key = (String) enumKeys.nextElement();
051: //!! job: not all packages are reported in Tiers
052:
053: ListOfPackageCategories lopc = (ListOfPackageCategories) allCategorizedPackages
054: .get(key);
055: HashSet lopcVec = lopc.getLayers();
056: Iterator it = lopcVec.iterator();
057: while (it.hasNext()) {
058: String layStr = (String) it.next();
059:
060: Vector packageList = (Vector) layers.get(layStr);
061: if (packageList == null) {
062: packageList = new Vector();
063: }
064: PackageOccuranceInLayer poil = new PackageOccuranceInLayer(
065: lopc.getAPackage());
066: if (alreadyVisitedPackages.contains(poil)) {
067: int i = alreadyVisitedPackages.indexOf(poil);
068:
069: PackageOccuranceInLayer this Poil = (PackageOccuranceInLayer) alreadyVisitedPackages
070: .elementAt(i);
071: this Poil.setOccurance(((int) this Poil
072: .getOccurance()) + 1);
073: this Poil.getLayerList().add(layStr);
074: packageList.add(this Poil);
075: } else {
076: packageList.add(poil);
077: alreadyVisitedPackages.add(poil);
078: poil.getLayerList().add(layStr);
079: }
080:
081: layers.put(layStr, packageList);
082: }
083: }
084: }
085:
086: public Element toDom(Document document){
087:
088: Element ret=document.createElement("ListOfLayers");
089: ret.setAttribute("size", String.valueOf(this.layers.size()));
090: Enumeration enum = this.layers.keys();
091: while (enum.hasMoreElements()) {
092: String layerKey = (String) enum.nextElement();
093: Element layer=document.createElement("Tier");
094: layer.setAttribute("name", layerKey );
095: ret.appendChild(layer);
096:
097: Vector packages = (Vector)layers.get( layerKey );
098: for(int i=0; i<packages.size(); i++ ){
099: Element pack=document.createElement("Package");
100: PackageOccuranceInLayer poil = ((PackageOccuranceInLayer)packages.elementAt(i));
101: pack.setAttribute("name", poil.getPackageName() );
102: for(int j=0; j<poil.getLayerList().size(); j++ ){
103: String myLayer = (String)poil.getLayerList().elementAt(j);
104: if( !layerKey.equals(myLayer) ){
105: pack.setAttribute("occurance", String.valueOf(poil.getOccurance() ) );
106:
107: Element poilList=document.createElement("PoilLayerOccurance");
108: poilList.setAttribute("name", (String)poil.getLayerList().elementAt(j) );
109: pack.appendChild(poilList);
110: }}
111: layer.appendChild(pack);
112: }
113: }
114: return ret;
115:
116: }
117: }
|