1 /*
2 * $Id: Sequencer.java,v 1.2 2003/04/02 19:48:47 austvold Exp $
3 * Copyright 2003 OErjan Nygaard Austvold. All rights reserved.
4 */
5
6 package org.jdiseq;
7
8 import com.zanthan.sequence.SequenceAcessor;
9
10 import java.util.*;
11
12 /***
13 *
14 * <p>Changelog:
15 * <pre>
16 * $Log: Sequencer.java,v $
17 * Revision 1.2 2003/04/02 19:48:47 austvold
18 * Minor updates. Mostly adaptation to new event and eventlistener name.
19 * General brush-up on javadoc comments.
20 * Removal of auto-added revision and date-of-commit members.
21 *
22 * Revision 1.1.1.1 2003/03/28 08:18:23 austvold
23 * Initial import.
24 *
25 * </pre>
26 *
27 * @author Ørjan Nygaard Austvold <austvold@acm.org>
28 * @version $Id: Sequencer.java,v 1.2 2003/04/02 19:48:47 austvold Exp $
29 */
30 public class Sequencer implements JdiEventListener {
31 public static final String RCS_REVISION = "$Revision: 1.2 $";
32 public static final String RCS_DATE = "$Date: 2003/04/02 19:48:47 $";
33
34 private boolean useBaseName = true; // strip package-part of classname
35
36 private Map traces;
37 private Map objects;
38 private int depth;
39
40 private int objectIdCounter;
41
42 public Sequencer() {
43 // launch gui
44 SequenceAcessor.launchSequence();
45 traces = new HashMap();
46 objects = new HashMap();
47 }
48
49 public void methodEntered(JdiEvent e) {
50 logMethodCall(e);
51 }
52
53 public void methodExited(JdiEvent e) {
54 logMethodCall(e);
55 }
56
57 private void logMethodCall(JdiEvent e) {
58 Integer objectId = (Integer) objects.get(e.getObjectReference());
59 if (objectId == null) {
60 objectId = new Integer(objectIdCounter++);
61 objects.put(e.getObjectReference(), objectId);
62 }
63
64 String thread = e.getThreadReference().name();
65 StringBuffer trace = (StringBuffer) traces.get(thread);
66
67 if (trace == null) {
68 trace = new StringBuffer(" ");
69 traces.put(thread, trace);
70 }
71
72 String className = e.getDeclaringType().name();
73 int n = className.lastIndexOf('.');
74 if (n != -1 && useBaseName) {
75 className = className.substring(n + 1);
76 }
77 String objectName = className + ":" + objectId;
78 String methodName = e.getMethod().name();
79
80 if (e.isMethodEntry()) {
81 trace.append("(" + objectName + " " + methodName + " ");
82 depth++;
83 } else {
84 depth--;
85 trace.append(")");
86 }
87
88 if (depth == 0) {
89 System.out.println("Thread: " + thread + "\n" + trace);
90 if (thread.equals("Dummy thread 0") && trace.length() > 1) {
91 SequenceAcessor.appendModelText(trace.toString());
92 }
93 traces.put(thread, new StringBuffer(" "));
94 }
95 }
96 }
This page was automatically generated by Maven