1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.agent;
22
23 /***
24 * TODO Add docs
25 * Created on 02.12.2004
26 *
27 * Contributing Author(s):
28 *
29 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
30 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
31 *
32 * @author vlads
33 * @version $Revision: 1.5 $ ($Author: vlads $) $Date: 2004/12/12 01:51:24 $
34 */
35 public class MapedEventID implements EventIdentifier {
36
37 /***
38 * Stable <code>serialVersionUID</code>.
39 */
40 private static final long serialVersionUID = 39132123L;
41
42 public static final int ID_DISPATCH_QUEUE = -1;
43
44 long id;
45
46 final static int INIT = 0;
47 final static int METHOD = 1;
48 final static int FINALIZE = 2;
49
50 int methodType;
51 transient private String methodName;
52 transient private String className;
53 transient private String methodSignature;
54
55 private MapedEventID() {
56 this.id = 0;
57 this.methodType = METHOD;
58 }
59
60 public MapedEventID(long id) {
61 this.id = id;
62 this.methodType = METHOD;
63 }
64
65 public MapedEventID(long id, int methodType) {
66 this.id = id;
67 this.methodType = methodType;
68 }
69
70 public MapedEventID(String className, String methodName, String methodSignature) {
71 this.id = InstrumentationMap.instance().getID(className, methodName, methodSignature);
72 this.methodName = methodName;
73 this.className = className;
74 this.methodSignature = methodSignature;
75 }
76
77 public boolean isConstruction() {
78 return (this.methodType == INIT);
79 }
80
81 public boolean isDeletion() {
82 return (this.methodType == FINALIZE);
83 }
84
85
86
87
88 public boolean equals(EventIdentifier obj) {
89 if (!(obj instanceof MapedEventID)) {
90 return false;
91 }
92 return (this.id == ((MapedEventID)obj).id);
93 }
94
95 private void unMap() {
96 if (this.id <= 0) {
97
98 switch ((int)this.id) {
99 case ID_DISPATCH_QUEUE:
100 this.methodName = "dispatchQueue";
101 this.methodSignature = "";
102 this.className = "jour";
103 break;
104 }
105 return;
106 }
107
108 String name = InstrumentationMap.instance().getName(this.id);
109 int idx = name.indexOf(InstrumentationMap.separator);
110 if (idx >= 0) {
111 this.className = name.substring(0, idx);
112 String s = name.substring(idx + 1);
113 int idx2 = s.indexOf(InstrumentationMap.separator);
114 this.methodName = s.substring(0, idx2);
115 this.methodSignature = s.substring(idx2 + 1);
116 } else {
117 this.methodName = name;
118 this.methodSignature = "";
119 this.className = "n/a";
120 }
121 }
122
123 public long getID() {
124 return this.id;
125 }
126
127 public Object getKey() {
128 return new Long(this.id);
129 }
130
131
132
133
134 public String getClassName() {
135 if (this.className == null) {
136 unMap();
137 }
138 return this.className;
139 }
140
141
142
143
144 public String getMethodName() {
145 if (this.methodName == null) {
146 unMap();
147 }
148 return this.methodName;
149 }
150
151 public String getMethodSignature() {
152 if (this.methodSignature == null) {
153 unMap();
154 }
155 return this.methodSignature;
156 }
157 }