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