KickJava   Java API By Example, From Geeks To Geeks.

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


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.request.*;
29 import java.util.*;
30
31 /**
32  * EventRequestWrapper.java
33  *
34  *
35  * Created: Tue Aug 22 10:48:34 2000
36  *
37  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
38  */

39
40 public abstract class EventRequestWrapper {
41
42     /** The debugger from which we can get information. */
43     protected Debugger debugger;
44
45     public EventRequestWrapper(Debugger debugger) {
46         this.debugger = debugger;
47     }
48
49     /**
50      * When a request is made it will be compared against all loaded classes.
51      * If <code>refType</code> doesn't resolve then this method returns null.
52      * If no loaded classes resolve with this request it is put on a queue and
53      * compared to classes as they are loaded. Once resolved the wrapper is pulled
54      * from the queue and the request is set.
55      */

56     public abstract EventRequest resolve(ReferenceType refType);
57
58     protected VirtualMachine vm() throws NoVMException {
59         return debugger.getVM();
60     }
61 }
62
63 class ClassLineBreakpointRequestWrapper extends EventRequestWrapper {
64
65     /** The String rep of the className on which this breakpoint should occur. */
66     private String JavaDoc className;
67
68     /** The line at which this breakpoint should occur. */
69     private int line;
70
71     ClassLineBreakpointRequestWrapper(Debugger debugger, String JavaDoc className, int line) {
72         super(debugger);
73         this.className = className;
74         this.line = line;
75     }
76
77     public EventRequest resolve(ReferenceType refType) {
78         BreakpointRequest request = null;
79         try {
80             if (refType.name().equals(className)) {
81                 EventRequestManager em = vm().eventRequestManager();
82                 Location location = findLocation();
83                 if (location == null) {
84                     return null;
85                 }
86                 request = em.createBreakpointRequest(location);
87                 request.enable();
88                 request.setSuspendPolicy(EventRequest.SUSPEND_NONE); //TODO: Change this to SUSPEND_ALL
89
}
90         } catch (NoVMException e) {
91         }
92         return request;
93     }
94
95     public String JavaDoc toString() {
96         return "breakpoint " + className + ":" + line;
97     }
98
99     private Location findLocation() throws NoVMException {
100         Location location = null;
101         Iterator iter = vm().classesByName(className).iterator();
102         while (iter.hasNext()) {
103             ReferenceType refType = (ReferenceType) iter.next();
104             if (refType.name().equals(className)) {
105                 try {
106                     Iterator linesIter = refType.locationsOfLine(line).iterator();
107                     while (linesIter.hasNext()) {
108                         return (Location) linesIter.next();
109                     }
110                 } catch (AbsentInformationException e) {
111                     return null;
112                 }
113             }
114         }
115         return location;
116     }
117 }
118
Popular Tags