001: /*
002: * ResolvableBreakpoint.java
003: *
004: * Copyright (C) 2002-2003 Peter Graves
005: * $Id: ResolvableBreakpoint.java,v 1.3 2003/05/15 01:17:05 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.jdb;
023:
024: import com.sun.jdi.ReferenceType;
025: import com.sun.jdi.VirtualMachine;
026: import com.sun.jdi.request.EventRequest;
027: import com.sun.jdi.request.EventRequestManager;
028: import java.util.Iterator;
029: import org.armedbear.j.Annotation;
030: import org.armedbear.j.File;
031: import org.armedbear.j.Line;
032: import org.armedbear.j.Log;
033:
034: public abstract class ResolvableBreakpoint {
035: protected final Jdb jdb;
036:
037: protected String className;
038: protected File file;
039: protected Line line;
040: protected EventRequest eventRequest;
041:
042: private boolean temporary;
043:
044: protected ResolvableBreakpoint(Jdb jdb) {
045: this .jdb = jdb;
046: }
047:
048: public final String getClassName() {
049: return className;
050: }
051:
052: public final File getFile() {
053: return file;
054: }
055:
056: public final Line getLine() {
057: return line;
058: }
059:
060: public final EventRequest getEventRequest() {
061: return eventRequest;
062: }
063:
064: public boolean isTemporary() {
065: return temporary;
066: }
067:
068: public void setTemporary() {
069: temporary = true;
070: }
071:
072: public final void clear() {
073: if (eventRequest != null) {
074: eventRequest.disable();
075: VirtualMachine vm = eventRequest.virtualMachine();
076: EventRequestManager mgr = vm.eventRequestManager();
077: mgr.deleteEventRequest(eventRequest);
078: eventRequest = null;
079: }
080: if (line != null) {
081: Annotation annotation = line.getAnnotation();
082: if (annotation instanceof BreakpointAnnotation)
083: if (((BreakpointAnnotation) annotation).getBreakpoint() == this )
084: line.setAnnotation(null);
085: }
086: }
087:
088: public final boolean isResolved() {
089: return eventRequest != null;
090: }
091:
092: public EventRequest resolveAgainstPreparedClasses()
093: throws Exception {
094: Log.debug("resolveAgainstPreparedClasses className = |"
095: + className + "|");
096: Iterator iter = jdb.getVM().allClasses().iterator();
097: while (eventRequest == null && iter.hasNext()) {
098: ReferenceType refType = (ReferenceType) iter.next();
099: if (refType.isPrepared()
100: && refType.name().equals(className)) {
101: eventRequest = resolveEventRequest(refType);
102: if (eventRequest != null) {
103: Log.debug("resolved!");
104: resolved();
105: jdb.fireBreakpointChanged();
106: return eventRequest;
107: }
108: }
109: }
110: Log.debug("*** not resolved");
111: return null;
112: }
113:
114: public abstract EventRequest resolveEventRequest(
115: ReferenceType refType) throws Exception;
116:
117: public abstract void resolved();
118:
119: public abstract String getLocationString();
120: }
|