KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

94     public JdwpReplyPacket() {
95         setFlags(FLAG_REPLY_PACKET);
96     }
97     
98     /**
99      * @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 int readSpecificHeaderFields(byte[] bytes, int index) throws IOException JavaDoc {
116         fErrorCode = (short)((bytes[index] << 8) + (bytes[index+1] << 0));
117         return 2;
118     }
119
120     /**
121      * Writes header fields that are specific for this type of packet.
122      */

123     protected int writeSpecificHeaderFields(byte[] bytes, int index) throws IOException JavaDoc {
124         bytes[index] = (byte) ((fErrorCode >>> 8) & 0xFF);
125         bytes[index+1] = (byte) ((fErrorCode >>> 0) & 0xFF);
126         return 2;
127     }
128
129     /**
130      * Retrieves constant mappings.
131      */

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

160     public static Map JavaDoc errorMap() {
161         getConstantMaps();
162         return fErrorMap;
163     }
164     
165     /* (non-Javadoc)
166      * @see java.lang.Object#toString()
167      */

168     public String JavaDoc toString() {
169         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
170         buffer.append("["); //$NON-NLS-1$
171
buffer.append(getId());
172         buffer.append("] "); //$NON-NLS-1$
173
buffer.append("(reply)"); //$NON-NLS-1$
174
short ec = errorCode();
175         if (ec != NONE) {
176             buffer.append(" ERROR CODE: "); //$NON-NLS-1$
177
buffer.append(ec);
178         }
179         return buffer.toString();
180     }
181 }
182
Popular Tags