KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RequestAction.java
34  *
35  *
36  * Created: Wed Aug 23 11:03:01 2000
37  *
38  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
39  */

40
41 public abstract class RequestAction extends RequestActionSupport implements ClassListener {
42
43     public RequestAction(Debugger debugger) {
44         super(debugger);
45     }
46     
47     void resolveAll() {
48         resolveAgainstAllClasses();
49     }
50
51     protected void addListeners() {
52         super.addListeners();
53         debugger.addClassListener(this);
54     }
55
56     protected void removeListeners() {
57         super.removeListeners();
58         debugger.removeClassListener(this);
59     }
60
61     public void removeFromDebugger(Debugger debugger) {
62         removeListeners();
63     }
64
65     abstract EventRequest resolve(ReferenceType refType)
66         throws MultipleLocationsException,
67                UnableToSetRequestException;
68
69     protected boolean resolveAgainstAllClasses() {
70         try {
71             Iterator iter = debugger.getVM().allClasses().iterator();
72             while (iter.hasNext()) {
73                 EventRequest request = resolve((ReferenceType) iter.next());
74                 if (request != null) {
75                     setRequest(request);
76                     return success();
77                 }
78             }
79         } catch (NoVMException e) {
80         } catch (MultipleLocationsException mle) {
81             return failure(true);
82         } catch (UnableToSetRequestException utsre) {
83             return failure(true);
84         }
85         return defer();
86     }
87     
88     protected boolean resolveAgainstClass(ReferenceType refType) {
89         try {
90             EventRequest request = resolve(refType);
91             if (request != null) {
92                 setRequest(request);
93                 return success();
94             }
95         } catch (MultipleLocationsException mle) {
96             return failure(true);
97         } catch (UnableToSetRequestException utsre) {
98             return failure(true);
99         }
100         return failure(false);
101     }
102
103     /* ClassListener */
104     public void classPrepareEvent(ClassPrepareEvent e) {
105         if (!isSet) {
106             resolveAgainstClass(e.referenceType());
107         }
108     }
109     public void classUnloadEvent(ClassUnloadEvent e) {
110     }
111 }
112
Popular Tags