KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > jdb > ResolvableBreakpoint


1 /*
2  * ResolvableBreakpoint.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: ResolvableBreakpoint.java,v 1.3 2003/05/15 01:17:05 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.jdb;
23
24 import com.sun.jdi.ReferenceType;
25 import com.sun.jdi.VirtualMachine;
26 import com.sun.jdi.request.EventRequest;
27 import com.sun.jdi.request.EventRequestManager;
28 import java.util.Iterator JavaDoc;
29 import org.armedbear.j.Annotation;
30 import org.armedbear.j.File;
31 import org.armedbear.j.Line;
32 import org.armedbear.j.Log;
33
34 public abstract class ResolvableBreakpoint
35 {
36     protected final Jdb jdb;
37
38     protected String JavaDoc className;
39     protected File file;
40     protected Line line;
41     protected EventRequest eventRequest;
42
43     private boolean temporary;
44
45     protected ResolvableBreakpoint(Jdb jdb)
46     {
47         this.jdb = jdb;
48     }
49
50     public final String JavaDoc getClassName()
51     {
52         return className;
53     }
54
55     public final File getFile()
56     {
57         return file;
58     }
59
60     public final Line getLine()
61     {
62         return line;
63     }
64
65     public final EventRequest getEventRequest()
66     {
67         return eventRequest;
68     }
69
70     public boolean isTemporary()
71     {
72         return temporary;
73     }
74
75     public void setTemporary()
76     {
77         temporary = true;
78     }
79
80     public final void clear()
81     {
82         if (eventRequest != null) {
83             eventRequest.disable();
84             VirtualMachine vm = eventRequest.virtualMachine();
85             EventRequestManager mgr = vm.eventRequestManager();
86             mgr.deleteEventRequest(eventRequest);
87             eventRequest = null;
88         }
89         if (line != null) {
90             Annotation annotation = line.getAnnotation();
91             if (annotation instanceof BreakpointAnnotation)
92                 if (((BreakpointAnnotation)annotation).getBreakpoint() == this)
93                     line.setAnnotation(null);
94         }
95     }
96
97     public final boolean isResolved()
98     {
99         return eventRequest != null;
100     }
101
102     public EventRequest resolveAgainstPreparedClasses() throws Exception JavaDoc
103     {
104         Log.debug("resolveAgainstPreparedClasses className = |" + className + "|");
105         Iterator JavaDoc iter = jdb.getVM().allClasses().iterator();
106         while (eventRequest == null && iter.hasNext()) {
107             ReferenceType refType = (ReferenceType) iter.next();
108             if (refType.isPrepared() && refType.name().equals(className)) {
109                 eventRequest = resolveEventRequest(refType);
110                 if (eventRequest != null) {
111                     Log.debug("resolved!");
112                     resolved();
113                     jdb.fireBreakpointChanged();
114                     return eventRequest;
115                 }
116             }
117         }
118         Log.debug("*** not resolved");
119         return null;
120     }
121
122     public abstract EventRequest resolveEventRequest(ReferenceType refType)
123         throws Exception JavaDoc;
124
125     public abstract void resolved();
126
127     public abstract String JavaDoc getLocationString();
128 }
129
Popular Tags