KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > request > RequestList


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.request;
24
25 import org.aspectj.debugger.base.*;
26
27 import com.sun.jdi.*;
28 import com.sun.jdi.event.*;
29 import java.util.*;
30
31 /**
32  * RequestList.java
33  *
34  *
35  * Created: Tue Aug 22 10:42:55 2000
36  *
37  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
38  */

39
40 public class RequestList
41     implements ClassListener, VMListener {
42
43     /** The list of events. */
44     private List requests;
45     
46     /** The debugger that will generate the events. */
47     private Debugger debugger;
48     
49     public RequestList(Debugger debugger) {
50         this.debugger = debugger;
51         debugger.addClassListener(this);
52         debugger.addVMListener(this);
53         requests = Collections.synchronizedList(new Vector());
54     }
55
56     private void add(EventRequestWrapper wrapper) {
57         System.out.println("Adding wrapper=" + wrapper);
58         requests.add(wrapper);
59     }
60     
61     public EventRequestWrapper remove(EventRequestWrapper wrapper) {
62         if (requests.remove(wrapper)) {
63             return wrapper;
64         }
65         return null;
66     }
67
68     /* Requests */
69     public /*private*/ ClassLineBreakpointRequestWrapper createBreakpointRequest(String JavaDoc className, int line) {
70         ClassLineBreakpointRequestWrapper wrapper =
71             new ClassLineBreakpointRequestWrapper(debugger, className, line);
72         add(wrapper);
73         resolveAgainstAllClasses(wrapper);
74         return wrapper;
75     }
76
77     boolean resolveAgainstAllClasses(EventRequestWrapper wrapper) {
78         try {
79             Iterator iter = debugger.getVM().allClasses().iterator();
80             while (iter.hasNext()) {
81                 if (wrapper.resolve((ReferenceType) iter.next()) != null) {
82                     remove(wrapper);
83                     return true;
84                 }
85             }
86         } catch (NoVMException e) {
87         }
88         return false;
89     }
90
91     boolean resolveAgainstClass(EventRequestWrapper wrapper, ReferenceType refType) {
92         if (wrapper.resolve(refType) != null) {
93             remove(wrapper);
94             return true;
95         }
96         return false;
97     }
98
99
100     /* ClassListener */
101     public void classPrepareEvent(ClassPrepareEvent e) {
102         for (int i = 0; i < requests.size(); i++) {
103             resolveAgainstClass((EventRequestWrapper) requests.get(i), e.referenceType());
104         }
105     }
106     public void classUnloadEvent(ClassUnloadEvent e) {
107     }
108
109     /* VMListener */
110     public void vmStartEvent(VMStartEvent e) {
111         for (int i = 0; i < requests.size(); i++) {
112             resolveAgainstAllClasses((EventRequestWrapper) requests.get(i));
113         }
114     }
115     public void vmDeathEvent(VMDeathEvent e) {
116     }
117     public void vmDisconnectEvent(VMDisconnectEvent e) {
118     }
119
120 }
121
Popular Tags