KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.jdi.event.*;
30 import java.util.*;
31
32 /**
33  * RequestActionSupport.java
34  *
35  *
36  * Created: Mon Aug 28 09:45:12 2000
37  *
38  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
39  */

40
41 public abstract class RequestActionSupport extends Request implements VMListener, StopListener {
42
43     protected boolean isSet = false;
44     protected EventRequest request;
45     protected String JavaDoc text;
46     public RequestActionSupport setText(String JavaDoc text) {
47         this.text = text;
48         return this;
49     }
50     
51     private boolean isDeferred = false;
52     private SourceManager.SourceLine sourceLine;
53
54     /* Make sure we disable ourselves when we remove ourselves. */
55     protected boolean isEnabled = true;
56     public boolean isEnabled() { return isEnabled; }
57
58     public RequestActionSupport(Debugger debugger, String JavaDoc text) {
59         super(debugger);
60         if (/*false && */text != null && !text.trim().equals("")) debugger.addStopListener(this);
61         setText(text);
62     }
63
64     public RequestActionSupport(Debugger debugger) {
65         this(debugger, null);
66     }
67
68     abstract void resolveAll();
69
70     public boolean isSetting() {
71         return true;
72     }
73
74     public boolean isBreakpoint() {
75         return false;
76     }
77
78     public boolean isSet() {
79         return isSet;
80     }
81
82     public EventRequest setRequest(EventRequest request) {
83         return (this.request = request);
84     }
85
86     protected EventRequest set() {
87         add();
88         try {
89             resolveAll();
90         } catch (VMDisconnectedException e) {
91         }
92         return getRequest();
93     }
94
95     protected EventRequest unset() {
96         //List requests = debugger.getRequests();
97
RequestAction request = remove(); //System.out.println(">>> request:" + request);
98
EventRequest req = null;
99         if (request != null) {
100             try {
101                 req = request.getRequest(); //System.out.println(">>> req.request:" + req);
102
if (req != null) {
103                     vm().eventRequestManager().deleteEventRequest(req);
104                 }
105             } catch (NoVMException e) {
106             }
107         } else {
108             try {
109                 req = getRequest(); req = getRequest(); //System.out.println(">>> getRequest:" + req);
110
if (req != null) {
111                     vm().eventRequestManager().deleteEventRequest(req);
112                     
113                 }
114             } catch (NoVMException e) {
115             }
116         }
117         return req; //getRequest();
118
}
119
120     public static String JavaDoc f(BreakpointRequest req) {
121         String JavaDoc str = req + "";
122         str += ", suspendPolicy=" + req.suspendPolicy();
123         str += ", enabled=" + req.isEnabled();
124         str += ", location=" + req.location();
125         return str;
126     }
127
128     public EventRequest getRequest() {
129         return request;
130     }
131
132     public boolean isDeferred() {
133         return isDeferred;
134     }
135
136     protected void setDeferred(boolean isDeferred) {
137         this.isDeferred = isDeferred;
138     }
139
140     protected VirtualMachine vm() throws NoVMException {
141         return debugger.getVM();
142     }
143
144     protected void addListeners() {
145         debugger.addVMListener(this);
146     }
147
148     protected void add() {
149         addListeners();
150         debugger.addRequest(this);
151         isEnabled = true;
152     }
153
154     protected void removeListeners() {
155         debugger.removeVMListener(this);
156     }
157
158     protected RequestAction remove() {
159         removeListeners();
160         RequestAction req = debugger.removeRequest(this);
161         isEnabled = false;
162         if (req != null) {
163             dbg().fireRequestClearEvent(new RequestEvent(this, true));
164         }
165         return req;
166     }
167
168     public SourceManager.SourceLine getSourceLine() {
169         return this.sourceLine;
170     }
171
172     public void setSourceLine(SourceManager.SourceLine sourceLine) {
173         this.sourceLine = sourceLine;
174     }
175
176     protected boolean success() {
177         if (isSetting()) {
178             dbg().setStatus("Set " + this);
179             dbg().fireRequestSetEvent(new RequestEvent(this, true));
180         } else {
181             dbg().setStatus("Clear " + this);
182             dbg().fireRequestClearEvent(new RequestEvent(this, true));
183         }
184         return (isSet = true);
185     }
186
187     protected boolean defer() {
188         setDeferred(true);
189         dbg().fireRequestDeferredEvent(new RequestEvent(this, false));
190         return (isSet = false);
191     }
192
193     protected boolean failure(boolean verbose) {
194         dbg().setStatus("Deferring " + this);
195         if (verbose) {
196             dbg().fireRequestFailedEvent(new RequestEvent(this, false));
197         }
198         return (isSet = false);
199     }
200
201     private void reset() {
202         isSet = false;
203         request = null;
204     }
205
206     /* VMListener */
207     public void vmStartEvent(VMStartEvent e) {
208         if (!isSet()) {
209             resolveAll();
210         }
211     }
212     public void vmDeathEvent(VMDeathEvent e) {}
213     public void vmDisconnectEvent(VMDisconnectEvent e) {}
214
215     /* Stop Listener */
216     public void breakpointEvent(BreakpointEvent e) { }
217     public void exceptionEvent(ExceptionEvent e) { }
218     public void accessWatchpointEvent(AccessWatchpointEvent e) { }
219     public void modificationWatchpointEvent(ModificationWatchpointEvent e) { }
220     public void stepEvent(StepEvent e) { }
221
222     protected String JavaDoc format(String JavaDoc str) { return str; }
223     protected void print(Event e) {
224         if (isEnabled() && text != null && e != null && e.request().equals(request)) {
225             debugger.app().outln(format(text));
226         }
227     }
228 }
229
Popular Tags