001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdi.internal.event;
011:
012: import java.io.DataInputStream;
013: import java.io.IOException;
014: import java.util.HashMap;
015: import java.util.Map;
016:
017: import org.eclipse.jdi.internal.MirrorImpl;
018: import org.eclipse.jdi.internal.ThreadReferenceImpl;
019: import org.eclipse.jdi.internal.VirtualMachineImpl;
020: import org.eclipse.jdi.internal.request.RequestID;
021:
022: import com.sun.jdi.ThreadReference;
023: import com.sun.jdi.event.Event;
024: import com.sun.jdi.request.EventRequest;
025:
026: /**
027: * This class implements the corresponding interfaces
028: * declared by the JDI specification. See the com.sun.jdi package
029: * for more information.
030: *
031: */
032: public abstract class EventImpl extends MirrorImpl implements Event {
033: /** Constants for EventKind. */
034: public static final byte EVENT_SINGLE_STEP = 1;
035: public static final byte EVENT_BREAKPOINT = 2;
036: public static final byte EVENT_FRAME_POP = 3;
037: public static final byte EVENT_EXCEPTION = 4;
038: public static final byte EVENT_USER_DEFINED = 5;
039: public static final byte EVENT_THREAD_START = 6;
040: public static final byte EVENT_THREAD_END = 7;
041: public static final byte EVENT_CLASS_PREPARE = 8;
042: public static final byte EVENT_CLASS_UNLOAD = 9;
043: public static final byte EVENT_CLASS_LOAD = 10;
044: public static final byte EVENT_FIELD_ACCESS = 20;
045: public static final byte EVENT_FIELD_MODIFICATION = 21;
046: public static final byte EVENT_EXCEPTION_CATCH = 30;
047: public static final byte EVENT_METHOD_ENTRY = 40;
048: public static final byte EVENT_METHOD_EXIT = 41;
049: public static final byte EVENT_METHOD_EXIT_WITH_RETURN_VALUE = 42;
050: public static final byte EVENT_MONITOR_CONTENDED_ENTER = 43;
051: public static final byte EVENT_MONITOR_CONTENDED_ENTERED = 44;
052: public static final byte EVENT_MONITOR_WAIT = 45;
053: public static final byte EVENT_MONITOR_WAITED = 46;
054: public static final byte EVENT_VM_INIT = 90;
055: public static final byte EVENT_VM_DEATH = 99;
056: public static final byte EVENT_VM_DISCONNECTED = 100; // Never sent by across JDWP.
057: public static final byte EVENT_VM_START = EVENT_VM_INIT;
058: public static final byte EVENT_THREAD_DEATH = EVENT_THREAD_END;
059:
060: /** ThreadReference of thread that generated this event. */
061: protected ThreadReferenceImpl fThreadRef;
062:
063: /** Mapping of command codes to strings. */
064: private static HashMap fEventKindMap = null;
065:
066: /** Request ID of event. */
067: private RequestID fRequestID;
068:
069: /** The EventRequest that requested this event. */
070: private EventRequest fRequest;
071:
072: /**
073: * Creates new EventImpl, only used by subclasses.
074: */
075: protected EventImpl(String description, VirtualMachineImpl vmImpl,
076: RequestID requestID) {
077: super (description, vmImpl);
078: fRequestID = requestID;
079: }
080:
081: /**
082: * @return Returns ThreadReference of thread that generated this event.
083: */
084: public ThreadReference thread() {
085: return fThreadRef;
086: }
087:
088: /**
089: * @return Returns requestID.
090: */
091: public RequestID requestID() {
092: return fRequestID;
093: }
094:
095: /**
096: * @return Returns string representation.
097: */
098: public String toString() {
099: return super .toString() + ": " + fRequestID; //$NON-NLS-1$
100: }
101:
102: /**
103: * @return Creates, reads and returns new EventImpl.
104: */
105: public static EventImpl read(MirrorImpl target,
106: DataInputStream dataInStream) throws IOException {
107: byte eventKind = target.readByte(
108: "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,
118: dataInStream);
119: break;
120: case BreakpointEventImpl.EVENT_KIND:
121: result = BreakpointEventImpl.read(target, requestID,
122: dataInStream);
123: break;
124: case ClassPrepareEventImpl.EVENT_KIND:
125: result = ClassPrepareEventImpl.read(target, requestID,
126: dataInStream);
127: break;
128: case ClassUnloadEventImpl.EVENT_KIND:
129: result = ClassUnloadEventImpl.read(target, requestID,
130: dataInStream);
131: break;
132: case ExceptionEventImpl.EVENT_KIND:
133: result = ExceptionEventImpl.read(target, requestID,
134: dataInStream);
135: break;
136: case MethodEntryEventImpl.EVENT_KIND:
137: result = MethodEntryEventImpl.read(target, requestID,
138: dataInStream);
139: break;
140: case MethodExitEventImpl.EVENT_KIND:
141: result = MethodExitEventImpl.read(target, requestID,
142: dataInStream);
143: break;
144: case EVENT_METHOD_EXIT_WITH_RETURN_VALUE:
145: result = MethodExitEventImpl.readWithReturnValue(target,
146: requestID, dataInStream);
147: break;
148: case MonitorContendedEnteredEventImpl.EVENT_KIND:
149: result = MonitorContendedEnteredEventImpl.read(target,
150: requestID, dataInStream);
151: break;
152: case MonitorContendedEnterEventImpl.EVENT_KIND:
153: result = MonitorContendedEnterEventImpl.read(target,
154: requestID, dataInStream);
155: break;
156: case MonitorWaitedEventImpl.EVENT_KIND:
157: result = MonitorWaitedEventImpl.read(target, requestID,
158: dataInStream);
159: break;
160: case MonitorWaitEventImpl.EVENT_KIND:
161: result = MonitorWaitEventImpl.read(target, requestID,
162: dataInStream);
163: break;
164: case ModificationWatchpointEventImpl.EVENT_KIND:
165: result = ModificationWatchpointEventImpl.read(target,
166: requestID, dataInStream);
167: break;
168: case StepEventImpl.EVENT_KIND:
169: result = StepEventImpl
170: .read(target, requestID, dataInStream);
171: break;
172: case ThreadDeathEventImpl.EVENT_KIND:
173: result = ThreadDeathEventImpl.read(target, requestID,
174: dataInStream);
175: break;
176: case ThreadStartEventImpl.EVENT_KIND:
177: result = ThreadStartEventImpl.read(target, requestID,
178: dataInStream);
179: break;
180: case VMDeathEventImpl.EVENT_KIND:
181: result = VMDeathEventImpl.read(target, requestID,
182: dataInStream);
183: break;
184: case VMDisconnectEventImpl.EVENT_KIND:
185: result = VMDisconnectEventImpl.read(target, requestID,
186: dataInStream);
187: break;
188: case VMStartEventImpl.EVENT_KIND:
189: result = VMStartEventImpl.read(target, requestID,
190: dataInStream);
191: break;
192: default:
193: throw new IOException(
194: EventMessages.EventImpl_Read_invalid_EventKind___1
195: + eventKind);
196: }
197:
198: // Find and store original request.
199: if (!requestID.isNull())
200: result.fRequest = target.virtualMachineImpl()
201: .eventRequestManagerImpl().findRequest(result);
202:
203: return result;
204: }
205:
206: /**
207: * @return Returns EventRequest that caused this event to be generated by the Virtual Machine.
208: */
209: public EventRequest request() {
210: return fRequest;
211: }
212:
213: /**
214: * Retrieves constant mappings.
215: */
216: public static void getConstantMaps() {
217: if (fEventKindMap != null)
218: return;
219:
220: java.lang.reflect.Field[] fields = EventImpl.class
221: .getDeclaredFields();
222: fEventKindMap = new HashMap();
223: for (int i = 0; i < fields.length; i++) {
224: java.lang.reflect.Field field = fields[i];
225: if ((field.getModifiers() & java.lang.reflect.Modifier.PUBLIC) == 0
226: || (field.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0
227: || (field.getModifiers() & java.lang.reflect.Modifier.FINAL) == 0)
228: continue;
229:
230: try {
231: String name = field.getName();
232: Integer intValue = new Integer(field.getInt(null));
233:
234: if (name.startsWith("EVENT_")) { //$NON-NLS-1$
235: name = name.substring(6);
236: fEventKindMap.put(intValue, name);
237: }
238: } catch (IllegalAccessException e) {
239: // Will not occur for own class.
240: } catch (IllegalArgumentException e) {
241: // Should not occur.
242: // We should take care that all public static final constants
243: // in this class are numbers that are convertible to int.
244: }
245: }
246: }
247:
248: /**
249: * @return Returns a map with string representations of tags.
250: */
251: public static Map eventKindMap() {
252: getConstantMaps();
253: return fEventKindMap;
254: }
255: }
|