1 26 package org.hammurapi.inspectors.metrics; 27 28 import java.util.Vector ; 29 30 import org.w3c.dom.DOMException ; 31 import org.w3c.dom.Document ; 32 import org.w3c.dom.Element ; 33 34 public class ListOfCategories extends Vector { 35 private String type = ""; 38 private String source_url = ""; 39 private int source_line = 0; 40 private int source_col = 0; 41 42 private String aPackage = null; 43 private Vector violations = new Vector (); 44 45 public ListOfCategories( String typeName, String 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 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 toKey() { 66 if (this.getType() != null ) { 67 return this.getType(); 68 } else { 69 return "unDefinedKey"; 70 } 71 } 72 73 public Element toDom(Document document){ 74 75 Element ret=document.createElement("ListOfClassCategories"); 76 Element 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 e) { 86 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 violaLst=document.createElement("LayerList"); 99 ret.appendChild(violaLst); 100 101 for (int i = 0; i < this.violations.size(); i++) { 102 Element viol=document.createElement("Layer"); 103 viol.setAttribute("id", String.valueOf( (i+1) ) ); 104 viol.setAttribute("name", (String ) this.violations.elementAt(i) ); 105 violaLst.appendChild(viol); 106 } 107 return ret; 108 } 109 110 public StringBuffer toXml() { 111 StringBuffer sb = new StringBuffer (); 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 ) 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 } 134 sb.append("</ListOfCategories>"); 135 return sb; 136 } 137 138 141 public String getType() { 142 143 return type; 144 } 145 146 149 public void setType(String type) { 150 this.type = type; 151 } 152 153 156 public Vector getViolations() { 157 return violations; 158 } 159 160 163 public void setViolations(Vector vector) { 164 violations = vector; 165 } 166 167 170 public String getSourceURL() { 171 return source_url; 172 } 173 176 public void setSourceURL(String source_url) { 177 this.source_url = source_url; 178 } 179 } 180 | Popular Tags |