KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > spy > JdwpReplyPacket


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.spy;
12
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.DataOutputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.lang.reflect.Field JavaDoc;
18 import java.lang.reflect.Modifier JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  * This class implements the corresponding Java Debug Wire Protocol (JDWP) packet
24  * declared by the JDWP specification.
25  *
26  */

27 public class JdwpReplyPacket extends JdwpPacket {
28     /** Error code constants. */
29     public static final short NONE = 0;
30     public static final short INVALID_THREAD = 10;
31     public static final short INVALID_THREAD_GROUP = 11;
32     public static final short INVALID_PRIORITY = 12;
33     public static final short THREAD_NOT_SUSPENDED = 13;
34     public static final short THREAD_SUSPENDED = 14;
35     public static final short INVALID_OBJECT = 20;
36     public static final short INVALID_CLASS = 21;
37     public static final short CLASS_NOT_PREPARED = 22;
38     public static final short INVALID_METHODID = 23;
39     public static final short INVALID_LOCATION = 24;
40     public static final short INVALID_FIELDID = 25;
41     public static final short INVALID_FRAMEID = 30;
42     public static final short NO_MORE_FRAMES = 31;
43     public static final short OPAQUE_FRAME = 32;
44     public static final short NOT_CURRENT_FRAME = 33;
45     public static final short TYPE_MISMATCH = 34;
46     public static final short INVALID_SLOT = 35;
47     public static final short DUPLICATE = 40;
48     public static final short NOT_FOUND = 41;
49     public static final short INVALID_MONITOR = 50;
50     public static final short NOT_MONITOR_OWNER = 51;
51     public static final short INTERRUPT = 52;
52     public static final short INVALID_CLASS_FORMAT = 60;
53     public static final short CIRCULAR_CLASS_DEFINITION = 61;
54     public static final short FAILS_VERIFICATION = 62;
55     public static final short ADD_METHOD_NOT_IMPLEMENTED = 63;
56     public static final short SCHEMA_CHANGE_NOT_IMPLEMENTED = 64;
57     public static final short INVALID_TYPESTATE = 65;
58     public static final short HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66;
59     public static final short DELETE_METHOD_NOT_IMPLEMENTED = 67;
60     public static final short UNSUPPORTED_VERSION = 68;
61     public static final short NAMES_DONT_MATCH = 69;
62     public static final short CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70;
63     public static final short METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71;
64     public static final short NOT_IMPLEMENTED = 99;
65     public static final short NULL_POINTER = 100;
66     public static final short ABSENT_INFORMATION = 101;
67     public static final short INVALID_EVENT_TYPE = 102;
68     public static final short ILLEGAL_ARGUMENT = 103;
69     public static final short OUT_OF_MEMORY = 110;
70     public static final short ACCESS_DENIED = 111;
71     public static final short VM_DEAD = 112;
72     public static final short INTERNAL = 113;
73     public static final short UNATTACHED_THREAD = 115;
74     public static final short INVALID_TAG = 500;
75     public static final short ALREADY_INVOKING = 502;
76     public static final short INVALID_INDEX = 503;
77     public static final short INVALID_LENGTH = 504;
78     public static final short INVALID_STRING = 506;
79     public static final short INVALID_CLASS_LOADER = 507;
80     public static final short INVALID_ARRAY = 508;
81     public static final short TRANSPORT_LOAD = 509;
82     public static final short TRANSPORT_INIT = 510;
83     public static final short NATIVE_METHOD = 511;
84     public static final short INVALID_COUNT = 512;
85     public static final short HCR_OPERATION_REFUSED = 900; // HCR specific.
86

87     /** Mapping of error codes to strings. */
88     private static HashMap JavaDoc fErrorMap = null;
89
90     /** JDWP Error code. */
91     private short fErrorCode;
92     /**
93      * Creates new JdwpReplyPacket.
94      */

95     public JdwpReplyPacket() {
96         setFlags(FLAG_REPLY_PACKET);
97     }
98     
99     /**
100      * @return Returns JDWP Error code.
101      */

102     public short errorCode() {
103         return fErrorCode;
104     }
105     
106     /**
107      * Assigns JDWP Error code.
108      */

109     public void setErrorCode(short newValue) {
110         fErrorCode = newValue;
111     }
112
113     /**
114      * Reads header fields that are specific for this type of packet.
115      */

116     protected void readSpecificHeaderFields(DataInputStream JavaDoc dataInStream) throws IOException JavaDoc {
117         fErrorCode = dataInStream.readShort();
118     }
119
120     /**
121      * Writes header fields that are specific for this type of packet.
122      */

123     protected void writeSpecificHeaderFields(DataOutputStream JavaDoc dataOutStream) throws IOException JavaDoc {
124         dataOutStream.writeShort(fErrorCode);
125     }
126
127     /**
128      * Retrieves constant mappings.
129      */

130     public static void getConstantMaps() {
131         if (fErrorMap != null) {
132             return;
133         }
134         
135         Field JavaDoc[] fields = JdwpReplyPacket.class.getDeclaredFields();
136         fErrorMap = new HashMap JavaDoc(fields.length);
137         for (int i = 0; i < fields.length; i++) {
138             Field JavaDoc field = fields[i];
139             if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0)
140                 continue;
141                 
142             try {
143                 Integer JavaDoc intValue = new Integer JavaDoc(field.getInt(null));
144                 fErrorMap.put(intValue, field.getName());
145             } catch (IllegalAccessException JavaDoc e) {
146                 // Will not occur for own class.
147
} catch (IllegalArgumentException JavaDoc e) {
148                 // Should not occur.
149
// We should take care that all public static final constants
150
// in this class are numbers that are convertible to int.
151
}
152         }
153     }
154
155     /**
156      * @return Returns a map with string representations of error codes.
157      */

158     public static Map JavaDoc errorMap() {
159         getConstantMaps();
160         return fErrorMap;
161     }
162 }
163
Popular Tags