KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > callertrace > TracedMethod


1 /*
2  * Created on Nov 4, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.hammurapi.inspectors.metrics.callertrace;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Set JavaDoc;
11 import java.util.SortedMap JavaDoc;
12 import java.util.TreeMap JavaDoc;
13
14 import org.w3c.dom.Document JavaDoc;
15 import org.w3c.dom.Element JavaDoc;
16
17 /**
18  * @author mucbj0
19  *
20  * To change the template for this generated type comment go to
21  * Window>Preferences>Java>Code Generation>Code and Comments
22  */

23 public class TracedMethod {
24     private MethodWrapper method = null;
25     private SortedMap JavaDoc keyMethodList = new TreeMap JavaDoc(new TracedMethodLocComparator());
26
27     private String JavaDoc 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     /**
38      * @return
39      */

40     public MethodWrapper getMethod() {
41         return method;
42     }
43
44
45     /**
46      * @param method
47      */

48     public void setMethod(MethodWrapper method) {
49         this.method = method;
50     }
51
52
53     public String JavaDoc toString(){
54         
55         if ( method != null ){
56             return method.toString();
57             // return method.getMethodKey();
58
} else {
59             return searchKey;
60         }
61     }
62
63     
64     public Element JavaDoc toDom(Document JavaDoc document, int id) {
65         Element JavaDoc ret = document.createElement("TracedMethod");
66         ret.setAttribute("id", String.valueOf(id));
67         Set JavaDoc s = this.getKeyMethodList().keySet();
68         for (Iterator JavaDoc it = s.iterator(); it.hasNext();) {
69             MethodWrapper m = (MethodWrapper) it.next();
70             Element JavaDoc 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 JavaDoc 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 JavaDoc toXml(int id) {
105         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
106         Set JavaDoc s = this.getKeyMethodList().keySet();
107         sb.append("<TracedMethod id=\"" + id + "\">");
108
109         for (Iterator JavaDoc 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     /**
132      * @return
133      */

134     public String JavaDoc getSearchKey() {
135         return searchKey;
136     }
137
138     /**
139      * @param string
140      */

141     public void setSearchKey(String JavaDoc string) {
142         searchKey = string;
143     }
144
145     /**
146      * @return
147      */

148     public boolean isEndpoint() {
149
150         return endpoint;
151     }
152     /**
153      * @return
154      */

155     public boolean isKey() {
156
157         return key;
158     }
159     /**
160      *
161      */

162     public void setIsKeyTrue() {
163         key = true;
164
165     }
166     /**
167      *
168      */

169     public void setEndpointTrue() {
170         endpoint = true;
171
172     }
173
174     public String JavaDoc toKey(){
175         if ( this.method != null ){
176             return ((MethodWrapper)this.method).toSearchKey();
177         } else {
178             return getSearchKey();
179         }
180     }
181     /**
182      * @return Returns the headKeyMethodList.
183      */

184     public SortedMap JavaDoc getKeyMethodList() {
185         return keyMethodList;
186     }
187
188     /**
189      * @param headKeyMethodList The headKeyMethodList to set.
190      */

191     public void setKeyMethodList(SortedMap JavaDoc headKeyMethodList) {
192         this.keyMethodList = headKeyMethodList;
193     }
194
195
196     /**
197      * @param key
198      * @param this
199      */

200     public void innerCheckForSiblings(String JavaDoc[] key) {
201         if (getMethod() != null) {
202             getKeyMethodList().put(getMethod(), getMethod());
203     
204             // System.out.println( "++ " + tm.getMethod().getClass().getName() )
205
// ;
206
//--loockup for implementor of MethodInvoked
207

208             MethodWrapperDeclaration methodImpl = null;
209             if (getMethod() instanceof MethodWrapperInvoked) {
210                 //-- use original Key!
211
methodImpl = ((MethodWrapperInvoked) getMethod())
212                         .getCallerMethod();
213             } else {
214                 methodImpl = (MethodWrapperDeclaration) getMethod();
215             }
216             if (methodImpl != null && methodImpl.getInvokedMethods() != null) {
217                 for (Iterator JavaDoc 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                         // System.out.println("method " +
224
// method.printMethodName() +" $$ " + key[j]);
225
if (method.printMethodName().equals(key[j])) {
226                             // System.out.println(" ** " + method.toSearchKey()
227
// + " ** ");
228
getKeyMethodList().put(method, method);
229                         }
230                     }
231                     // System.out.println("tm.getKeyMethodList() " +
232
// tm.getKeyMethodList());
233
}
234             } //-- fi
235
// } //--fi
236
} //--fi
237
}
238
239
240 }
241
242
243
Popular Tags