KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > event > AbstractEventSet


1 /*
2  * @(#)AbstractEventSet.java 1.12 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.event;
36
37 import com.sun.jdi.*;
38 import com.sun.jdi.event.*;
39 import com.sun.jdi.request.*;
40
41 import java.util.*;
42
43 public abstract class AbstractEventSet extends EventObject implements EventSet {
44     
45     private final EventSet jdiEventSet;
46     final Event oneEvent;
47
48     /**
49      */

50     AbstractEventSet(EventSet jdiEventSet) {
51         super(jdiEventSet.virtualMachine());
52         this.jdiEventSet = jdiEventSet;
53         this.oneEvent = eventIterator().nextEvent();
54     }
55
56     public static AbstractEventSet toSpecificEventSet(EventSet jdiEventSet) {
57         Event evt = jdiEventSet.eventIterator().nextEvent();
58         if (evt instanceof LocatableEvent) {
59             if (evt instanceof ExceptionEvent) {
60                 return new ExceptionEventSet(jdiEventSet);
61             } else if (evt instanceof WatchpointEvent) {
62                 if (evt instanceof AccessWatchpointEvent) {
63                     return new AccessWatchpointEventSet(jdiEventSet);
64                 } else {
65                     return new ModificationWatchpointEventSet(jdiEventSet);
66                 }
67             } else {
68                 return new LocationTriggerEventSet(jdiEventSet);
69             }
70         } else if (evt instanceof ClassPrepareEvent) {
71             return new ClassPrepareEventSet(jdiEventSet);
72         } else if (evt instanceof ClassUnloadEvent) {
73             return new ClassUnloadEventSet(jdiEventSet);
74         } else if (evt instanceof ThreadDeathEvent) {
75             return new ThreadDeathEventSet(jdiEventSet);
76         } else if (evt instanceof ThreadStartEvent) {
77             return new ThreadStartEventSet(jdiEventSet);
78         } else if (evt instanceof VMDeathEvent) {
79             return new VMDeathEventSet(jdiEventSet);
80         } else if (evt instanceof VMDisconnectEvent) {
81             return new VMDisconnectEventSet(jdiEventSet);
82         } else if (evt instanceof VMStartEvent) {
83             return new VMStartEventSet(jdiEventSet);
84         } else {
85             throw new IllegalArgumentException JavaDoc("Unknown event " + evt);
86         }
87     }
88
89     public abstract void notify(JDIListener listener);
90
91     // Implement Mirror
92

93     public VirtualMachine virtualMachine() {
94         return jdiEventSet.virtualMachine();
95     }
96
97     public VirtualMachine getVirtualMachine() {
98         return jdiEventSet.virtualMachine();
99     }
100
101     // Implement EventSet
102

103     /**
104      * Returns the policy used to suspend threads in the target VM
105      * for this event set. This policy is selected from the suspend
106      * policies for each event's request. The one that suspends the
107      * most threads is chosen when the event occurs in the target VM
108      * and that policy is returned here. See
109      * com.sun.jdi.request.EventRequest for the possible policy values.
110      *
111      * @return the integer suspendPolicy
112      */

113     public int getSuspendPolicy() {
114         return jdiEventSet.suspendPolicy();
115     }
116
117     public void resume() {
118         jdiEventSet.resume();
119     }
120
121     public int suspendPolicy() {
122         return jdiEventSet.suspendPolicy();
123     }
124
125     public boolean suspendedAll() {
126         return jdiEventSet.suspendPolicy() == EventRequest.SUSPEND_ALL;
127     }
128
129     public boolean suspendedEventThread() {
130         return jdiEventSet.suspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD;
131     }
132
133     public boolean suspendedNone() {
134         return jdiEventSet.suspendPolicy() == EventRequest.SUSPEND_NONE;
135     }
136
137     /**
138      * Return an iterator specific to {@link Event} objects.
139      */

140     public EventIterator eventIterator() {
141         return jdiEventSet.eventIterator();
142     }
143
144
145     // Implement java.util.Set (by pass through)
146

147     /**
148      * Returns the number of elements in this set (its cardinality). If this
149      * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
150      * <tt>Integer.MAX_VALUE</tt>.
151      *
152      * @return the number of elements in this set (its cardinality).
153      */

154     public int size() {
155         return jdiEventSet.size();
156     }
157
158     /**
159      * Returns <tt>true</tt> if this set contains no elements.
160      *
161      * @return <tt>true</tt> if this set contains no elements.
162      */

163     public boolean isEmpty() {
164         return jdiEventSet.isEmpty();
165     }
166
167     /**
168      * Returns <tt>true</tt> if this set contains the specified element. More
169      * formally, returns <tt>true</tt> if and only if this set contains an
170      * element <code>e</code> such that <code>(o==null ? e==null :
171      * o.equals(e))</code>.
172      *
173      * @return <tt>true</tt> if this set contains the specified element.
174      */

175     public boolean contains(Object JavaDoc o) {
176         return jdiEventSet.contains(o);
177     }
178
179     /**
180      * Returns an iterator over the elements in this set. The elements are
181      * returned in no particular order (unless this set is an instance of some
182      * class that provides a guarantee).
183      *
184      * @return an iterator over the elements in this set.
185      */

186     public Iterator<Event> iterator() {
187         return jdiEventSet.iterator();
188     }
189
190     /**
191      * Returns an array containing all of the elements in this set.
192      * Obeys the general contract of the <tt>Collection.toArray</tt> method.
193      *
194      * @return an array containing all of the elements in this set.
195      */

196     public Object JavaDoc[] toArray() {
197         return jdiEventSet.toArray();
198     }
199
200     /**
201      * Returns an array containing all of the elements in this set whose
202      * runtime type is that of the specified array. Obeys the general
203      * contract of the <tt>Collection.toArray(Object[])</tt> method.
204      *
205      * @param a the array into which the elements of this set are to
206      * be stored, if it is big enough {
207         return jdiEventSet.XXX();
208     } otherwise, a new array of the
209      * same runtime type is allocated for this purpose.
210      * @return an array containing the elements of this set.
211      * @throws ArrayStoreException the runtime type of a is not a supertype
212      * of the runtime type of every element in this set.
213      */

214     public <T> T[] toArray(T a[]) {
215         return jdiEventSet.toArray(a);
216     }
217
218     // Bulk Operations
219

220     /**
221      * Returns <tt>true</tt> if this set contains all of the elements of the
222      * specified collection. If the specified collection is also a set, this
223      * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
224      *
225      * @param c collection to be checked for containment in this set.
226      * @return <tt>true</tt> if this set contains all of the elements of the
227      * specified collection.
228      */

229     public boolean containsAll(Collection<?> c) {
230         return jdiEventSet.containsAll(c);
231     }
232
233
234     // Make the rest of Set unmodifiable
235

236     public boolean add(Event e){
237         throw new UnsupportedOperationException JavaDoc();
238     }
239     public boolean remove(Object JavaDoc o) {
240         throw new UnsupportedOperationException JavaDoc();
241     }
242     public boolean addAll(Collection<? extends Event> coll) {
243         throw new UnsupportedOperationException JavaDoc();
244     }
245     public boolean removeAll(Collection<?> coll) {
246         throw new UnsupportedOperationException JavaDoc();
247     }
248     public boolean retainAll(Collection<?> coll) {
249         throw new UnsupportedOperationException JavaDoc();
250     }
251     public void clear() {
252         throw new UnsupportedOperationException JavaDoc();
253     }
254 }
255
256
Popular Tags