001: /*
002: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.example.debug.bdi;
027:
028: import com.sun.jdi.*;
029: import com.sun.jdi.request.*;
030:
031: import java.util.*;
032:
033: class EventRequestSpecList {
034:
035: // all specs
036: private List<EventRequestSpec> eventRequestSpecs = Collections
037: .synchronizedList(new ArrayList<EventRequestSpec>());
038:
039: final ExecutionManager runtime;
040:
041: EventRequestSpecList(ExecutionManager runtime) {
042: this .runtime = runtime;
043: }
044:
045: /**
046: * Resolve all deferred eventRequests waiting for 'refType'.
047: */
048: void resolve(ReferenceType refType) {
049: synchronized (eventRequestSpecs) {
050: Iterator iter = eventRequestSpecs.iterator();
051: while (iter.hasNext()) {
052: ((EventRequestSpec) iter.next())
053: .attemptResolve(refType);
054: }
055: }
056: }
057:
058: void install(EventRequestSpec ers, VirtualMachine vm) {
059: synchronized (eventRequestSpecs) {
060: eventRequestSpecs.add(ers);
061: }
062: if (vm != null) {
063: ers.attemptImmediateResolve(vm);
064: }
065: }
066:
067: BreakpointSpec createClassLineBreakpoint(String classPattern,
068: int line) {
069: ReferenceTypeSpec refSpec = new PatternReferenceTypeSpec(
070: classPattern);
071: return new LineBreakpointSpec(this , refSpec, line);
072: }
073:
074: BreakpointSpec createSourceLineBreakpoint(String sourceName,
075: int line) {
076: ReferenceTypeSpec refSpec = new SourceNameReferenceTypeSpec(
077: sourceName, line);
078: return new LineBreakpointSpec(this , refSpec, line);
079: }
080:
081: BreakpointSpec createMethodBreakpoint(String classPattern,
082: String methodId, List methodArgs) {
083: ReferenceTypeSpec refSpec = new PatternReferenceTypeSpec(
084: classPattern);
085: return new MethodBreakpointSpec(this , refSpec, methodId,
086: methodArgs);
087: }
088:
089: ExceptionSpec createExceptionIntercept(String classPattern,
090: boolean notifyCaught, boolean notifyUncaught) {
091: ReferenceTypeSpec refSpec = new PatternReferenceTypeSpec(
092: classPattern);
093: return new ExceptionSpec(this , refSpec, notifyCaught,
094: notifyUncaught);
095: }
096:
097: AccessWatchpointSpec createAccessWatchpoint(String classPattern,
098: String fieldId) {
099: ReferenceTypeSpec refSpec = new PatternReferenceTypeSpec(
100: classPattern);
101: return new AccessWatchpointSpec(this , refSpec, fieldId);
102: }
103:
104: ModificationWatchpointSpec createModificationWatchpoint(
105: String classPattern, String fieldId) {
106: ReferenceTypeSpec refSpec = new PatternReferenceTypeSpec(
107: classPattern);
108: return new ModificationWatchpointSpec(this , refSpec, fieldId);
109: }
110:
111: void delete(EventRequestSpec ers) {
112: EventRequest request = ers.getEventRequest();
113: synchronized (eventRequestSpecs) {
114: eventRequestSpecs.remove(ers);
115: }
116: if (request != null) {
117: request.virtualMachine().eventRequestManager()
118: .deleteEventRequest(request);
119: }
120: notifyDeleted(ers);
121: //### notify delete - here?
122: }
123:
124: List<EventRequestSpec> eventRequestSpecs() {
125: // We need to make a copy to avoid synchronization problems
126: synchronized (eventRequestSpecs) {
127: return new ArrayList<EventRequestSpec>(eventRequestSpecs);
128: }
129: }
130:
131: // -------- notify routines --------------------
132:
133: private Vector specListeners() {
134: return (Vector) runtime.specListeners.clone();
135: }
136:
137: void notifySet(EventRequestSpec spec) {
138: Vector l = specListeners();
139: SpecEvent evt = new SpecEvent(spec);
140: for (int i = 0; i < l.size(); i++) {
141: spec.notifySet((SpecListener) l.elementAt(i), evt);
142: }
143: }
144:
145: void notifyDeferred(EventRequestSpec spec) {
146: Vector l = specListeners();
147: SpecEvent evt = new SpecEvent(spec);
148: for (int i = 0; i < l.size(); i++) {
149: spec.notifyDeferred((SpecListener) l.elementAt(i), evt);
150: }
151: }
152:
153: void notifyDeleted(EventRequestSpec spec) {
154: Vector l = specListeners();
155: SpecEvent evt = new SpecEvent(spec);
156: for (int i = 0; i < l.size(); i++) {
157: spec.notifyDeleted((SpecListener) l.elementAt(i), evt);
158: }
159: }
160:
161: void notifyResolved(EventRequestSpec spec) {
162: Vector l = specListeners();
163: SpecEvent evt = new SpecEvent(spec);
164: for (int i = 0; i < l.size(); i++) {
165: spec.notifyResolved((SpecListener) l.elementAt(i), evt);
166: }
167: }
168:
169: void notifyError(EventRequestSpec spec, Exception exc) {
170: Vector l = specListeners();
171: SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
172: for (int i = 0; i < l.size(); i++) {
173: spec.notifyError((SpecListener) l.elementAt(i), evt);
174: }
175: }
176: }
|