KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > event > EventImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal.event;
12
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.jdi.internal.MirrorImpl;
20 import org.eclipse.jdi.internal.ThreadReferenceImpl;
21 import org.eclipse.jdi.internal.VirtualMachineImpl;
22 import org.eclipse.jdi.internal.request.RequestID;
23
24 import com.sun.jdi.ThreadReference;
25 import com.sun.jdi.event.Event;
26 import com.sun.jdi.request.EventRequest;
27
28
29 /**
30  * This class implements the corresponding interfaces
31  * declared by the JDI specification. See the com.sun.jdi package
32  * for more information.
33  *
34  */

35 public abstract class EventImpl extends MirrorImpl implements Event {
36     /** Constants for EventKind. */
37     public static final byte EVENT_SINGLE_STEP = 1;
38     public static final byte EVENT_BREAKPOINT = 2;
39     public static final byte EVENT_FRAME_POP = 3;
40     public static final byte EVENT_EXCEPTION = 4;
41     public static final byte EVENT_USER_DEFINED = 5;
42     public static final byte EVENT_THREAD_START = 6;
43     public static final byte EVENT_THREAD_END = 7;
44     public static final byte EVENT_CLASS_PREPARE = 8;
45     public static final byte EVENT_CLASS_UNLOAD = 9;
46     public static final byte EVENT_CLASS_LOAD = 10;
47     public static final byte EVENT_FIELD_ACCESS = 20;
48     public static final byte EVENT_FIELD_MODIFICATION = 21;
49     public static final byte EVENT_EXCEPTION_CATCH = 30;
50     public static final byte EVENT_METHOD_ENTRY = 40;
51     public static final byte EVENT_METHOD_EXIT = 41;
52     public static final byte EVENT_METHOD_EXIT_WITH_RETURN_VALUE = 42;
53     public static final byte EVENT_MONITOR_CONTENDED_ENTER = 43;
54     public static final byte EVENT_MONITOR_CONTENDED_ENTERED = 44;
55     public static final byte EVENT_MONITOR_WAIT = 45;
56     public static final byte EVENT_MONITOR_WAITED = 46;
57     public static final byte EVENT_VM_INIT = 90;
58     public static final byte EVENT_VM_DEATH = 99;
59     public static final byte EVENT_VM_DISCONNECTED = 100; // Never sent by across JDWP.
60
public static final byte EVENT_VM_START = EVENT_VM_INIT;
61     public static final byte EVENT_THREAD_DEATH = EVENT_THREAD_END;
62     
63     /** ThreadReference of thread that generated this event. */
64     protected ThreadReferenceImpl fThreadRef;
65
66     /** Mapping of command codes to strings. */
67     private static HashMap JavaDoc fEventKindMap = null;
68     
69     /** Request ID of event. */
70     private RequestID fRequestID;
71
72     /** The EventRequest that requested this event. */
73     private EventRequest fRequest;
74
75     /**
76      * Creates new EventImpl, only used by subclasses.
77      */

78     protected EventImpl(String JavaDoc description, VirtualMachineImpl vmImpl, RequestID requestID) {
79         super(description, vmImpl);
80         fRequestID = requestID;
81     }
82     
83     /**
84      * @return Returns ThreadReference of thread that generated this event.
85      */

86     public ThreadReference thread() {
87         return fThreadRef;
88     }
89     
90     /**
91      * @return Returns requestID.
92      */

93     public RequestID requestID() {
94         return fRequestID;
95      }
96     
97     /**
98      * @return Returns string representation.
99      */

100     public String JavaDoc toString() {
101         return super.toString() + ": " + fRequestID; //$NON-NLS-1$
102
}
103
104     /**
105      * @return Creates, reads and returns new EventImpl.
106      */

107     public static EventImpl read(MirrorImpl target, DataInputStream JavaDoc dataInStream) throws IOException JavaDoc {
108         byte eventKind = target.readByte("event kind", eventKindMap(), dataInStream); //$NON-NLS-1$
109
RequestID requestID = RequestID.read(target, dataInStream);
110
111         // Create, read and return Event of eventKind.
112
EventImpl result;
113         switch(eventKind) {
114             case 0:
115                 return null;
116             case AccessWatchpointEventImpl.EVENT_KIND:
117                 result = AccessWatchpointEventImpl.read(target, requestID, dataInStream);
118                 break;
119             case BreakpointEventImpl.EVENT_KIND:
120                 result = BreakpointEventImpl.read(target, requestID, dataInStream);
121                 break;
122             case ClassPrepareEventImpl.EVENT_KIND:
123                 result = ClassPrepareEventImpl.read(target, requestID, dataInStream);
124                 break;
125             case ClassUnloadEventImpl.EVENT_KIND:
126                 result = ClassUnloadEventImpl.read(target, requestID, dataInStream);
127                 break;
128             case ExceptionEventImpl.EVENT_KIND:
129                 result = ExceptionEventImpl.read(target, requestID, dataInStream);
130                 break;
131             case MethodEntryEventImpl.EVENT_KIND:
132                 result = MethodEntryEventImpl.read(target, requestID, dataInStream);
133                 break;
134             case MethodExitEventImpl.EVENT_KIND:
135                 result = MethodExitEventImpl.read(target, requestID, dataInStream);
136                 break;
137             case EVENT_METHOD_EXIT_WITH_RETURN_VALUE:
138                 result = MethodExitEventImpl.readWithReturnValue(target, requestID, dataInStream);
139                 break;
140             case MonitorContendedEnteredEventImpl.EVENT_KIND:
141                 result = MonitorContendedEnteredEventImpl.read(target, requestID, dataInStream);
142                 break;
143             case MonitorContendedEnterEventImpl.EVENT_KIND:
144                 result = MonitorContendedEnterEventImpl.read(target, requestID, dataInStream);
145                 break;
146             case MonitorWaitedEventImpl.EVENT_KIND:
147                 result = MonitorWaitedEventImpl.read(target, requestID, dataInStream);
148                 break;
149             case MonitorWaitEventImpl.EVENT_KIND:
150                 result = MonitorWaitEventImpl.read(target, requestID, dataInStream);
151                 break;
152             case ModificationWatchpointEventImpl.EVENT_KIND:
153                 result = ModificationWatchpointEventImpl.read(target, requestID, dataInStream);
154                 break;
155             case StepEventImpl.EVENT_KIND:
156                 result = StepEventImpl.read(target, requestID, dataInStream);
157                 break;
158             case ThreadDeathEventImpl.EVENT_KIND:
159                 result = ThreadDeathEventImpl.read(target, requestID, dataInStream);
160                 break;
161             case ThreadStartEventImpl.EVENT_KIND:
162                 result = ThreadStartEventImpl.read(target, requestID, dataInStream);
163                 break;
164             case VMDeathEventImpl.EVENT_KIND:
165                 result = VMDeathEventImpl.read(target, requestID, dataInStream);
166                 break;
167             case VMDisconnectEventImpl.EVENT_KIND:
168                 result = VMDisconnectEventImpl.read(target, requestID, dataInStream);
169                 break;
170             case VMStartEventImpl.EVENT_KIND:
171                 result = VMStartEventImpl.read(target, requestID, dataInStream);
172                 break;
173             default:
174                 throw new IOException JavaDoc(EventMessages.EventImpl_Read_invalid_EventKind___1 + eventKind);
175         }
176
177         // Find and store original request.
178
if (!requestID.isNull())
179             result.fRequest = target.virtualMachineImpl().eventRequestManagerImpl().findRequest(result);
180
181         return result;
182     }
183     
184     /**
185      * @return Returns EventRequest that caused this event to be generated by the Virtual Machine.
186      */

187     public EventRequest request() {
188         return fRequest;
189     }
190
191     /**
192      * Retrieves constant mappings.
193      */

194     public static void getConstantMaps() {
195         if (fEventKindMap != null)
196             return;
197         
198         java.lang.reflect.Field JavaDoc[] fields = EventImpl.class.getDeclaredFields();
199         fEventKindMap = new HashMap JavaDoc();
200         for (int i = 0; i < fields.length; i++) {
201             java.lang.reflect.Field JavaDoc field = fields[i];
202             if ((field.getModifiers() & java.lang.reflect.Modifier.PUBLIC) == 0 || (field.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0 || (field.getModifiers() & java.lang.reflect.Modifier.FINAL) == 0)
203                 continue;
204                 
205             try {
206                 String JavaDoc name = field.getName();
207                 Integer JavaDoc intValue = new Integer JavaDoc(field.getInt(null));
208
209                 if (name.startsWith("EVENT_")) { //$NON-NLS-1$
210
name = name.substring(6);
211                     fEventKindMap.put(intValue, name);
212                 }
213             } catch (IllegalAccessException JavaDoc e) {
214                 // Will not occur for own class.
215
} catch (IllegalArgumentException JavaDoc e) {
216                 // Should not occur.
217
// We should take care that all public static final constants
218
// in this class are numbers that are convertible to int.
219
}
220         }
221     }
222     
223     /**
224      * @return Returns a map with string representations of tags.
225      */

226      public static Map JavaDoc eventKindMap() {
227         getConstantMaps();
228         return fEventKindMap;
229      }
230 }
231
232
Popular Tags