KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > EventRequestSpecList


1 /*
2  * @(#)EventRequestSpecList.java 1.10 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import com.sun.jdi.*;
38 import com.sun.jdi.request.*;
39
40 import java.util.*;
41
42 class EventRequestSpecList {
43     
44     // all specs
45
private List eventRequestSpecs = Collections.synchronizedList(
46                                                   new ArrayList());
47
48     final ExecutionManager runtime;
49
50     EventRequestSpecList(ExecutionManager runtime) {
51     this.runtime = runtime;
52     }
53
54     /**
55      * Resolve all deferred eventRequests waiting for 'refType'.
56      */

57     void resolve(ReferenceType refType) {
58         synchronized(eventRequestSpecs) {
59             Iterator iter = eventRequestSpecs.iterator();
60             while (iter.hasNext()) {
61                 ((EventRequestSpec)iter.next()).attemptResolve(refType);
62              }
63         }
64     }
65
66     void install(EventRequestSpec ers, VirtualMachine vm) {
67         synchronized (eventRequestSpecs) {
68             eventRequestSpecs.add(ers);
69         }
70         if (vm != null) {
71             ers.attemptImmediateResolve(vm);
72         }
73     }
74         
75     BreakpointSpec
76     createClassLineBreakpoint(String JavaDoc classPattern, int line) {
77         ReferenceTypeSpec refSpec =
78             new PatternReferenceTypeSpec(classPattern);
79         return new LineBreakpointSpec(this, refSpec, line);
80     }
81         
82     BreakpointSpec
83     createSourceLineBreakpoint(String JavaDoc sourceName, int line) {
84         ReferenceTypeSpec refSpec =
85             new SourceNameReferenceTypeSpec(sourceName, line);
86         return new LineBreakpointSpec(this, refSpec, line);
87     }
88         
89     BreakpointSpec
90     createMethodBreakpoint(String JavaDoc classPattern,
91                            String JavaDoc methodId, List methodArgs) {
92         ReferenceTypeSpec refSpec =
93             new PatternReferenceTypeSpec(classPattern);
94         return new MethodBreakpointSpec(this, refSpec,
95                                         methodId, methodArgs);
96     }
97         
98     ExceptionSpec
99     createExceptionIntercept(String JavaDoc classPattern,
100                              boolean notifyCaught,
101                              boolean notifyUncaught) {
102         ReferenceTypeSpec refSpec =
103             new PatternReferenceTypeSpec(classPattern);
104         return new ExceptionSpec(this, refSpec,
105                                  notifyCaught, notifyUncaught);
106     }
107         
108     AccessWatchpointSpec
109     createAccessWatchpoint(String JavaDoc classPattern, String JavaDoc fieldId) {
110         ReferenceTypeSpec refSpec =
111             new PatternReferenceTypeSpec(classPattern);
112         return new AccessWatchpointSpec(this, refSpec, fieldId);
113     }
114         
115     ModificationWatchpointSpec
116     createModificationWatchpoint(String JavaDoc classPattern, String JavaDoc fieldId) {
117         ReferenceTypeSpec refSpec =
118             new PatternReferenceTypeSpec(classPattern);
119         return new ModificationWatchpointSpec(this, refSpec, fieldId);
120     }
121
122     void delete(EventRequestSpec ers) {
123         EventRequest request = ers.getEventRequest();
124         synchronized (eventRequestSpecs) {
125             eventRequestSpecs.remove(ers);
126         }
127         if (request != null) {
128             request.virtualMachine().eventRequestManager()
129                 .deleteEventRequest(request);
130         }
131         notifyDeleted(ers);
132         //### notify delete - here?
133
}
134
135     List eventRequestSpecs() {
136         // We need to make a copy to avoid synchronization problems
137
synchronized (eventRequestSpecs) {
138             return new ArrayList(eventRequestSpecs);
139         }
140     }
141
142     // -------- notify routines --------------------
143

144     private Vector specListeners() {
145         return (Vector)runtime.specListeners.clone();
146     }
147
148     void notifySet(EventRequestSpec spec) {
149     Vector l = specListeners();
150     SpecEvent evt = new SpecEvent(spec);
151     for (int i = 0; i < l.size(); i++) {
152         spec.notifySet((SpecListener)l.elementAt(i), evt);
153     }
154     }
155
156     void notifyDeferred(EventRequestSpec spec) {
157     Vector l = specListeners();
158     SpecEvent evt = new SpecEvent(spec);
159     for (int i = 0; i < l.size(); i++) {
160         spec.notifyDeferred((SpecListener)l.elementAt(i), evt);
161     }
162     }
163
164     void notifyDeleted(EventRequestSpec spec) {
165     Vector l = specListeners();
166     SpecEvent evt = new SpecEvent(spec);
167     for (int i = 0; i < l.size(); i++) {
168         spec.notifyDeleted((SpecListener)l.elementAt(i), evt);
169     }
170     }
171
172     void notifyResolved(EventRequestSpec spec) {
173     Vector l = specListeners();
174     SpecEvent evt = new SpecEvent(spec);
175     for (int i = 0; i < l.size(); i++) {
176         spec.notifyResolved((SpecListener)l.elementAt(i), evt);
177     }
178     }
179
180     void notifyError(EventRequestSpec spec, Exception JavaDoc exc) {
181     Vector l = specListeners();
182     SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
183     for (int i = 0; i < l.size(); i++) {
184         spec.notifyError((SpecListener)l.elementAt(i), evt);
185     }
186     }
187 }
188
189
190
191
Popular Tags