1:
38:
39:
40: package ;
41:
42: import ;
43: import ;
44: import ;
45: import ;
46:
47: import ;
48: import ;
49:
50:
59: public class EventRequest
60: {
61:
64:
65:
68: public static final byte EVENT_SINGLE_STEP =
69: JdwpConstants.EventKind.SINGLE_STEP;
70:
71:
74: public static final byte EVENT_BREAKPOINT =
75: JdwpConstants.EventKind.BREAKPOINT;
76:
77:
80: public static final byte EVENT_FRAME_POP =
81: JdwpConstants.EventKind.FRAME_POP;
82:
83:
86: public static final byte EVENT_EXCEPTION =
87: JdwpConstants.EventKind.EXCEPTION;
88:
89:
92: public static final byte EVENT_USER_DEFINED =
93: JdwpConstants.EventKind.USER_DEFINED;
94:
95:
98: public static final byte EVENT_THREAD_START =
99: JdwpConstants.EventKind.THREAD_START;
100:
101:
104: public static final byte EVENT_THREAD_END =
105: JdwpConstants.EventKind.THREAD_END;
106:
107:
110: public static final byte EVENT_CLASS_PREPARE =
111: JdwpConstants.EventKind.CLASS_PREPARE;
112:
113:
116: public static final byte EVENT_CLASS_UNLOAD =
117: JdwpConstants.EventKind.CLASS_UNLOAD;
118:
119:
122: public static final byte EVENT_CLASS_LOAD =
123: JdwpConstants.EventKind.CLASS_LOAD;
124:
125:
128: public static final byte EVENT_FIELD_ACCESS =
129: JdwpConstants.EventKind.FIELD_ACCESS;
130:
131:
134: public static final byte EVENT_FIELD_MODIFY =
135: JdwpConstants.EventKind.FIELD_MODIFICATION;
136:
137:
140: public static final byte EVENT_METHOD_ENTRY =
141: JdwpConstants.EventKind.METHOD_ENTRY;
142:
143:
146: public static final byte EVENT_METHOD_EXIT =
147: JdwpConstants.EventKind.METHOD_EXIT;
148:
149:
152: public static final byte EVENT_VM_INIT =
153: JdwpConstants.EventKind.VM_INIT;
154:
155:
158: public static final byte EVENT_VM_DEATH =
159: JdwpConstants.EventKind.VM_DEATH;
160:
161:
162:
165:
166:
169: public static final byte SUSPEND_NONE =
170: JdwpConstants.SuspendPolicy.NONE;
171:
172:
175: public static final byte SUSPEND_THREAD =
176: JdwpConstants.SuspendPolicy.EVENT_THREAD;
177:
178:
181: public static final byte SUSPEND_ALL =
182: JdwpConstants.SuspendPolicy.ALL;
183:
184:
185: private static int _last_id = 0;
186: private static Object _idLock = new Object ();
187:
188:
189: private LinkedList _filters;
190:
191:
192: private int _id;
193:
194:
195: private byte _suspendPolicy;
196:
197:
198: private byte _kind;
199:
200:
206: public EventRequest (byte kind, byte suspendPolicy)
207: {
208: _filters = new LinkedList ();
209: synchronized (_idLock)
210: {
211: _id = ++_last_id;
212: }
213: _kind = kind;
214: _suspendPolicy = suspendPolicy;
215: }
216:
217:
224: public EventRequest (int id, byte kind, byte suspendPolicy)
225: {
226: _filters = new LinkedList ();
227: _kind = kind;
228: _suspendPolicy = suspendPolicy;
229: }
230:
231:
238: public void addFilter (IEventFilter filter)
239: throws JdwpIllegalArgumentException
240: {
241:
242: boolean valid = true;
243:
244: Class clazz = filter.getClass ();
245: if (clazz == ClassExcludeFilter.class)
246: {
247: if (_kind == EVENT_THREAD_START
248: || _kind == EVENT_THREAD_END)
249: valid = false;
250: }
251: else if (clazz == ClassMatchFilter.class)
252: {
253: if (_kind == EVENT_THREAD_START
254: || _kind == EVENT_THREAD_END)
255: valid = false;
256: }
257: else if (clazz == ClassOnlyFilter.class)
258: {
259: if (_kind == EVENT_CLASS_UNLOAD
260: || _kind == EVENT_THREAD_START
261: || _kind == EVENT_THREAD_END)
262: valid = false;
263: }
264: else if (clazz == ConditionalFilter.class)
265: {
266:
267: }
268: else if (clazz == CountFilter.class)
269: {
270:
271: }
272: else if (clazz == ExceptionOnlyFilter.class)
273: {
274: if (_kind != EVENT_EXCEPTION)
275: valid = false;
276: }
277: else if (clazz == FieldOnlyFilter.class)
278: {
279: if (_kind != EVENT_FIELD_ACCESS
280: && _kind != EVENT_FIELD_MODIFY)
281: valid = false;
282: }
283: else if (clazz == InstanceOnlyFilter.class)
284: {
285: if (_kind == EVENT_CLASS_PREPARE
286: || _kind == EVENT_CLASS_UNLOAD
287: || _kind == EVENT_THREAD_START
288: || _kind == EVENT_THREAD_END)
289: valid = false;
290: }
291: else if (clazz == LocationOnlyFilter.class)
292: {
293: if (_kind != EVENT_BREAKPOINT
294: && _kind != EVENT_FIELD_ACCESS
295: && _kind != EVENT_FIELD_MODIFY
296: && _kind != EVENT_SINGLE_STEP
297: && _kind != EVENT_EXCEPTION)
298: valid = false;
299: }
300: else if (clazz == StepFilter.class)
301: {
302: if (_kind != EVENT_SINGLE_STEP)
303: valid = false;
304: }
305: else if (clazz == ThreadOnlyFilter.class)
306: {
307: if (_kind == EVENT_CLASS_UNLOAD)
308: valid = false;
309: }
310:
311: if (!valid)
312: {
313: String msg = ("cannot use " + filter.getClass ().getName ()
314: + " with class unload events");
315: throw new JdwpIllegalArgumentException (msg);
316: }
317:
318:
319: _filters.add (filter);
320: }
321:
322:
325: public byte getSuspendPolicy ()
326: {
327: return _suspendPolicy;
328: }
329:
330:
333: public int getId ()
334: {
335: return _id;
336: }
337:
338:
341: public void setId (int id)
342: {
343: _id = id;
344: }
345:
346:
349: public byte getEventKind ()
350: {
351: return _kind;
352: }
353:
354:
359: public boolean matches (Event theEvent)
360: {
361: boolean matches = true;
362:
363:
364:
365:
366: ListIterator iter = _filters.listIterator ();
367: while (iter.hasNext ())
368: {
369: IEventFilter filter = (IEventFilter) iter.next ();
370: if (!filter.matches (theEvent))
371: matches = false;
372: }
373:
374: return matches;
375: }
376: }