001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.spy;
011:
012: import java.io.DataInputStream;
013: import java.io.DataOutputStream;
014: import java.io.IOException;
015: import java.lang.reflect.Field;
016: import java.lang.reflect.Modifier;
017: import java.util.HashMap;
018: import java.util.Map;
019:
020: /**
021: * This class implements the corresponding Java Debug Wire Protocol (JDWP) packet
022: * declared by the JDWP specification.
023: *
024: */
025: public class JdwpReplyPacket extends JdwpPacket {
026: /** Error code constants. */
027: public static final short NONE = 0;
028: public static final short INVALID_THREAD = 10;
029: public static final short INVALID_THREAD_GROUP = 11;
030: public static final short INVALID_PRIORITY = 12;
031: public static final short THREAD_NOT_SUSPENDED = 13;
032: public static final short THREAD_SUSPENDED = 14;
033: public static final short INVALID_OBJECT = 20;
034: public static final short INVALID_CLASS = 21;
035: public static final short CLASS_NOT_PREPARED = 22;
036: public static final short INVALID_METHODID = 23;
037: public static final short INVALID_LOCATION = 24;
038: public static final short INVALID_FIELDID = 25;
039: public static final short INVALID_FRAMEID = 30;
040: public static final short NO_MORE_FRAMES = 31;
041: public static final short OPAQUE_FRAME = 32;
042: public static final short NOT_CURRENT_FRAME = 33;
043: public static final short TYPE_MISMATCH = 34;
044: public static final short INVALID_SLOT = 35;
045: public static final short DUPLICATE = 40;
046: public static final short NOT_FOUND = 41;
047: public static final short INVALID_MONITOR = 50;
048: public static final short NOT_MONITOR_OWNER = 51;
049: public static final short INTERRUPT = 52;
050: public static final short INVALID_CLASS_FORMAT = 60;
051: public static final short CIRCULAR_CLASS_DEFINITION = 61;
052: public static final short FAILS_VERIFICATION = 62;
053: public static final short ADD_METHOD_NOT_IMPLEMENTED = 63;
054: public static final short SCHEMA_CHANGE_NOT_IMPLEMENTED = 64;
055: public static final short INVALID_TYPESTATE = 65;
056: public static final short HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66;
057: public static final short DELETE_METHOD_NOT_IMPLEMENTED = 67;
058: public static final short UNSUPPORTED_VERSION = 68;
059: public static final short NAMES_DONT_MATCH = 69;
060: public static final short CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70;
061: public static final short METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71;
062: public static final short NOT_IMPLEMENTED = 99;
063: public static final short NULL_POINTER = 100;
064: public static final short ABSENT_INFORMATION = 101;
065: public static final short INVALID_EVENT_TYPE = 102;
066: public static final short ILLEGAL_ARGUMENT = 103;
067: public static final short OUT_OF_MEMORY = 110;
068: public static final short ACCESS_DENIED = 111;
069: public static final short VM_DEAD = 112;
070: public static final short INTERNAL = 113;
071: public static final short UNATTACHED_THREAD = 115;
072: public static final short INVALID_TAG = 500;
073: public static final short ALREADY_INVOKING = 502;
074: public static final short INVALID_INDEX = 503;
075: public static final short INVALID_LENGTH = 504;
076: public static final short INVALID_STRING = 506;
077: public static final short INVALID_CLASS_LOADER = 507;
078: public static final short INVALID_ARRAY = 508;
079: public static final short TRANSPORT_LOAD = 509;
080: public static final short TRANSPORT_INIT = 510;
081: public static final short NATIVE_METHOD = 511;
082: public static final short INVALID_COUNT = 512;
083: public static final short HCR_OPERATION_REFUSED = 900; // HCR specific.
084:
085: /** Mapping of error codes to strings. */
086: private static HashMap fErrorMap = null;
087:
088: /** JDWP Error code. */
089: private short fErrorCode;
090:
091: /**
092: * Creates new JdwpReplyPacket.
093: */
094: public JdwpReplyPacket() {
095: setFlags(FLAG_REPLY_PACKET);
096: }
097:
098: /**
099: * @return Returns JDWP Error code.
100: */
101: public short errorCode() {
102: return fErrorCode;
103: }
104:
105: /**
106: * Assigns JDWP Error code.
107: */
108: public void setErrorCode(short newValue) {
109: fErrorCode = newValue;
110: }
111:
112: /**
113: * Reads header fields that are specific for this type of packet.
114: */
115: protected void readSpecificHeaderFields(DataInputStream dataInStream)
116: throws IOException {
117: fErrorCode = dataInStream.readShort();
118: }
119:
120: /**
121: * Writes header fields that are specific for this type of packet.
122: */
123: protected void writeSpecificHeaderFields(
124: DataOutputStream dataOutStream) throws IOException {
125: dataOutStream.writeShort(fErrorCode);
126: }
127:
128: /**
129: * Retrieves constant mappings.
130: */
131: public static void getConstantMaps() {
132: if (fErrorMap != null) {
133: return;
134: }
135:
136: Field[] fields = JdwpReplyPacket.class.getDeclaredFields();
137: fErrorMap = new HashMap(fields.length);
138: for (int i = 0; i < fields.length; i++) {
139: Field field = fields[i];
140: if ((field.getModifiers() & Modifier.PUBLIC) == 0
141: || (field.getModifiers() & Modifier.STATIC) == 0
142: || (field.getModifiers() & Modifier.FINAL) == 0)
143: continue;
144:
145: try {
146: Integer intValue = new Integer(field.getInt(null));
147: fErrorMap.put(intValue, field.getName());
148: } catch (IllegalAccessException e) {
149: // Will not occur for own class.
150: } catch (IllegalArgumentException e) {
151: // Should not occur.
152: // We should take care that all public static final constants
153: // in this class are numbers that are convertible to int.
154: }
155: }
156: }
157:
158: /**
159: * @return Returns a map with string representations of error codes.
160: */
161: public static Map errorMap() {
162: getConstantMaps();
163: return fErrorMap;
164: }
165: }
|