1 7 package org.hammurapi.inspectors.metrics.callertrace; 8 9 import java.util.Iterator ; 10 import java.util.Set ; 11 import java.util.SortedMap ; 12 import java.util.TreeMap ; 13 14 import org.w3c.dom.Document ; 15 import org.w3c.dom.Element ; 16 17 23 public class TracedMethod { 24 private MethodWrapper method = null; 25 private SortedMap keyMethodList = new TreeMap (new TracedMethodLocComparator()); 26 27 private String searchKey =""; 28 private boolean endpoint = false; 29 private boolean key = false; 30 31 public TracedMethod( MethodWrapper mw){ 32 super(); 33 method = mw; 34 } 35 36 37 40 public MethodWrapper getMethod() { 41 return method; 42 } 43 44 45 48 public void setMethod(MethodWrapper method) { 49 this.method = method; 50 } 51 52 53 public String toString(){ 54 55 if ( method != null ){ 56 return method.toString(); 57 } else { 59 return searchKey; 60 } 61 } 62 63 64 public Element toDom(Document document, int id) { 65 Element ret = document.createElement("TracedMethod"); 66 ret.setAttribute("id", String.valueOf(id)); 67 Set s = this.getKeyMethodList().keySet(); 68 for (Iterator it = s.iterator(); it.hasNext();) { 69 MethodWrapper m = (MethodWrapper) it.next(); 70 Element ret2 = document.createElement("Inside"); 71 ret.appendChild(ret2); 72 73 74 if (this.getMethod().equals(m)) { 75 if (this.isKey()) { 76 ret2.setAttribute("type", "key"); 77 } else { 78 ret2.setAttribute("type", "mother"); 79 } 80 } else { 81 ret2.setAttribute("type", "sibling"); 82 }; 83 84 if (this.getMethod() != null) { 85 Element ret3 = document.createElement("Method"); 86 ret3.setAttribute("key", m.printMethodName()); 87 if ( m instanceof MethodWrapperDeclaration ){ 88 ret3.setAttribute("Ma", String.valueOf(((MethodWrapperDeclaration) m).afferentMethodCoupling)); 89 ret3.setAttribute("Me", String.valueOf(((MethodWrapperDeclaration) m).getInvokedMethods().size())); 90 } else{ 91 ret3.setAttribute("Ma", ""); 92 ret3.setAttribute("Me", ""); 93 94 } 95 ret3.setAttribute("source-url", m.getSrcURL()); 96 ret3.setAttribute("line", String.valueOf(m.getSrcLine())); 97 98 ret2.appendChild(ret3); 99 } 100 } 101 return ret; 102 } 103 104 public String toXml(int id) { 105 StringBuffer sb = new StringBuffer (); 106 Set s = this.getKeyMethodList().keySet(); 107 sb.append("<TracedMethod id=\"" + id + "\">"); 108 109 for (Iterator it=s.iterator(); it.hasNext();){ 110 MethodWrapper m= (MethodWrapper) it.next(); 111 112 sb.append("<Inside "); 113 114 sb.append( "type=\"" ); 115 if ( this.getMethod().equals( m )){ 116 sb.append( "mother"); }else{ sb.append( "sibling"); }; 117 sb.append( "\">\n"); 118 if ( this.getMethod() != null ){ 119 sb.append(m.getMethodKey()); 120 sb.append(m.getLine()); 121 sb.append(m.getSrcURL()); 122 } 123 sb.append("</Inside>\n"); 124 } 125 sb.append("</TracedMethod>\n"); 126 return sb.toString(); 127 } 128 129 130 131 134 public String getSearchKey() { 135 return searchKey; 136 } 137 138 141 public void setSearchKey(String string) { 142 searchKey = string; 143 } 144 145 148 public boolean isEndpoint() { 149 150 return endpoint; 151 } 152 155 public boolean isKey() { 156 157 return key; 158 } 159 162 public void setIsKeyTrue() { 163 key = true; 164 165 } 166 169 public void setEndpointTrue() { 170 endpoint = true; 171 172 } 173 174 public String toKey(){ 175 if ( this.method != null ){ 176 return ((MethodWrapper)this.method).toSearchKey(); 177 } else { 178 return getSearchKey(); 179 } 180 } 181 184 public SortedMap getKeyMethodList() { 185 return keyMethodList; 186 } 187 188 191 public void setKeyMethodList(SortedMap headKeyMethodList) { 192 this.keyMethodList = headKeyMethodList; 193 } 194 195 196 200 public void innerCheckForSiblings(String [] key) { 201 if (getMethod() != null) { 202 getKeyMethodList().put(getMethod(), getMethod()); 203 204 208 MethodWrapperDeclaration methodImpl = null; 209 if (getMethod() instanceof MethodWrapperInvoked) { 210 methodImpl = ((MethodWrapperInvoked) getMethod()) 212 .getCallerMethod(); 213 } else { 214 methodImpl = (MethodWrapperDeclaration) getMethod(); 215 } 216 if (methodImpl != null && methodImpl.getInvokedMethods() != null) { 217 for (Iterator it = methodImpl.getInvokedMethods().iterator(); it 218 .hasNext();) { 219 MethodWrapperInvoked method = (MethodWrapperInvoked) it 220 .next(); 221 222 for (int j = 0; j < key.length; j++) { 223 if (method.printMethodName().equals(key[j])) { 226 getKeyMethodList().put(method, method); 229 } 230 } 231 } 234 } } } 238 239 240 } 241 242 243 | Popular Tags |