1 7 package org.hammurapi.inspectors.metrics.callertrace; 8 9 import java.util.Vector ; 10 11 import org.w3c.dom.Document ; 12 import org.w3c.dom.Element ; 13 14 20 public class TraceList extends Vector { 21 private String searchMethodSignature = "<not defined>"; 22 private TracedMethod endpoint = null; 23 24 28 29 public TraceList(Object key ){ 30 super(); 31 searchMethodSignature = key.toString(); 32 } 33 34 public Trace traceElementAt(int index) { 35 return (Trace) super.elementAt(index); 36 } 37 38 public void setEndpointMethod ( MethodWrapper aMethods, String key ){ 39 TracedMethod tm = new TracedMethod(aMethods); 40 41 endpoint = tm; 42 endpoint.setSearchKey(key); 43 44 } 45 46 47 public Trace retrieveTraceFor( Trace searchTrace ){ 48 49 Trace returnTrace = null; 51 for (int i=0; i<this.size(); i++){ 52 53 Trace t = (Trace)this.elementAt(i); 54 if (t.equals(searchTrace) ){ 55 } else if ( t.sameNameAndSizeButNotEqual( searchTrace ) ) { 57 return t; 58 } 59 } 60 return returnTrace; 61 } 62 63 public Trace cloneTraceFor( Trace searchTrace ){ 64 65 return (Trace)searchTrace.clone(); 66 67 } 68 69 public Element toDom(Document document){ 70 71 Element ret=document.createElement("TraceList"); 72 ret.setAttribute("size", String.valueOf( this.size() )); 73 String str = "Not Given"; 74 if (endpoint != null){ str = endpoint.getSearchKey(); }; 75 ret.setAttribute("methodName", str); 76 77 78 for (int i = 0; i < this.size(); i++) { 79 Element trc=document.createElement("Trace"); 80 trc.setAttribute("id", String.valueOf( (i+1) )); 81 ret.appendChild(trc); 82 Trace t = (Trace) this.traceElementAt(i); 83 for (int j = t.size() - 1; j > -1; j--) { 84 TracedMethod tm = t.traceElementAt(j); 85 trc.appendChild( tm.toDom( document, (((t.size()-1) - j)))); 86 } 87 } 88 return ret; 89 } 90 91 public String toXml() { 92 StringBuffer sb = new StringBuffer (); 93 String str = "Not Given"; 94 if (endpoint != null){ str = endpoint.getSearchKey(); }; 95 sb.append("<TraceList size=\"" + this.size() + "\" methodName=\"" + str + "\">\n"); 96 for (int i = 0; i < this.size(); i++) { 99 sb.append("<Trace id=\"" + (i+1) + "\">"); 100 Trace t = (Trace) this.traceElementAt(i); 101 102 for (int j = t.size() - 1; j > -1; j--) { 103 TracedMethod tm = t.traceElementAt(j); 105 sb.append(tm.toXml((((t.size()-1) - j)))); 106 } 107 sb.append("</Trace>\n"); 108 } 109 sb.append("</TraceList>\n"); 110 return sb.toString(); 111 } 112 113 } 114 115 | Popular Tags |