1:
38:
39:
40: package ;
41:
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: import ;
58: import ;
59: import ;
60: import ;
61:
62:
67: public class ReferenceTypeCommandSet
68: extends CommandSet
69: {
70: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
71: throws JdwpException
72: {
73: try
74: {
75: switch (command)
76: {
77: case JdwpConstants.CommandSet.ReferenceType.SIGNATURE:
78: executeSignature(bb, os);
79: break;
80: case JdwpConstants.CommandSet.ReferenceType.CLASS_LOADER:
81: executeClassLoader(bb, os);
82: break;
83: case JdwpConstants.CommandSet.ReferenceType.MODIFIERS:
84: executeModifiers(bb, os);
85: break;
86: case JdwpConstants.CommandSet.ReferenceType.FIELDS:
87: executeFields(bb, os);
88: break;
89: case JdwpConstants.CommandSet.ReferenceType.METHODS:
90: executeMethods(bb, os);
91: break;
92: case JdwpConstants.CommandSet.ReferenceType.GET_VALUES:
93: executeGetValues(bb, os);
94: break;
95: case JdwpConstants.CommandSet.ReferenceType.SOURCE_FILE:
96: executeSourceFile(bb, os);
97: break;
98: case JdwpConstants.CommandSet.ReferenceType.NESTED_TYPES:
99: executeNestedTypes(bb, os);
100: break;
101: case JdwpConstants.CommandSet.ReferenceType.STATUS:
102: executeStatus(bb, os);
103: break;
104: case JdwpConstants.CommandSet.ReferenceType.INTERFACES:
105: executeInterfaces(bb, os);
106: break;
107: case JdwpConstants.CommandSet.ReferenceType.CLASS_OBJECT:
108: executeClassObject(bb, os);
109: break;
110: case JdwpConstants.CommandSet.ReferenceType.SOURCE_DEBUG_EXTENSION:
111: executeSourceDebugExtension(bb, os);
112: break;
113: case JdwpConstants.CommandSet.ReferenceType.SIGNATURE_WITH_GENERIC:
114: executeSignatureWithGeneric(bb, os);
115: break;
116: case JdwpConstants.CommandSet.ReferenceType.FIELDS_WITH_GENERIC:
117: executeFieldWithGeneric(bb, os);
118: break;
119: case JdwpConstants.CommandSet.ReferenceType.METHODS_WITH_GENERIC:
120: executeMethodsWithGeneric(bb, os);
121: break;
122: default:
123: throw new NotImplementedException("Command " + command +
124: " not found in ReferenceType Command Set.");
125: }
126: }
127: catch (IOException ex)
128: {
129:
130:
131: throw new JdwpInternalErrorException(ex);
132: }
133:
134: return false;
135: }
136:
137: private void executeSignature(ByteBuffer bb, DataOutputStream os)
138: throws JdwpException, IOException
139: {
140: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
141: String sig = Signature.computeClassSignature(refId.getType());
142: JdwpString.writeString(os, sig);
143: }
144:
145: private void executeClassLoader(ByteBuffer bb, DataOutputStream os)
146: throws JdwpException, IOException
147: {
148: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
149:
150: Class clazz = refId.getType();
151: ClassLoader loader = clazz.getClassLoader();
152: ObjectId oid = idMan.getObjectId(loader);
153: oid.write(os);
154: }
155:
156: private void executeModifiers(ByteBuffer bb, DataOutputStream os)
157: throws JdwpException, IOException
158: {
159: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
160:
161: Class clazz = refId.getType();
162: os.writeInt(clazz.getModifiers());
163: }
164:
165: private void executeFields(ByteBuffer bb, DataOutputStream os)
166: throws JdwpException, IOException
167: {
168: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
169: Class clazz = refId.getType();
170:
171: Field[] fields = clazz.getFields();
172: os.writeInt(fields.length);
173: for (int i = 0; i < fields.length; i++)
174: {
175: Field field = fields[i];
176: idMan.getObjectId(field).write(os);
177: JdwpString.writeString(os, field.getName());
178: JdwpString.writeString(os, Signature.computeFieldSignature(field));
179: os.writeInt(field.getModifiers());
180: }
181: }
182:
183: private void executeMethods(ByteBuffer bb, DataOutputStream os)
184: throws JdwpException, IOException
185: {
186: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
187: Class clazz = refId.getType();
188:
189: VMMethod[] methods = VMVirtualMachine.getAllClassMethods(clazz);
190: os.writeInt (methods.length);
191: for (int i = 0; i < methods.length; i++)
192: {
193: VMMethod method = methods[i];
194: method.writeId(os);
195: JdwpString.writeString(os, method.getName());
196: JdwpString.writeString(os, method.getSignature());
197: os.writeInt(method.getModifiers());
198: }
199: }
200:
201: private void executeGetValues(ByteBuffer bb, DataOutputStream os)
202: throws JdwpException, IOException
203: {
204: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
205: Class clazz = refId.getType();
206:
207: int numFields = bb.getInt();
208: os.writeInt(numFields);
209: for (int i = 0; i < numFields; i++)
210: {
211: ObjectId fieldId = idMan.readObjectId(bb);
212: Field field = (Field) (fieldId.getObject());
213: Class fieldClazz = field.getDeclaringClass();
214:
215:
216:
217: if (fieldClazz.isAssignableFrom(clazz))
218: {
219: try
220: {
221: field.setAccessible(true);
222: Object value = field.get(null);
223: Value val = ValueFactory.createFromObject(value,
224: field.getType());
225: val.writeTagged(os);
226: }
227: catch (IllegalArgumentException ex)
228: {
229:
230: throw new InvalidFieldException(ex);
231: }
232: catch (IllegalAccessException ex)
233: {
234:
235: throw new JdwpInternalErrorException(ex);
236: }
237: }
238: else
239: throw new InvalidFieldException(fieldId.getId());
240: }
241: }
242:
243: private void executeSourceFile(ByteBuffer bb, DataOutputStream os)
244: throws JdwpException, IOException
245: {
246: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
247: Class clazz = refId.getType();
248:
249:
250: String sourceFileName = VMVirtualMachine.getSourceFile(clazz);
251: JdwpString.writeString(os, sourceFileName);
252:
253: }
254:
255: private void executeNestedTypes(ByteBuffer bb, DataOutputStream os)
256: throws JdwpException, IOException
257: {
258: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
259: Class clazz = refId.getType();
260: Class[] declaredClazzes = clazz.getDeclaredClasses();
261: os.writeInt(declaredClazzes.length);
262: for (int i = 0; i < declaredClazzes.length; i++)
263: {
264: Class decClazz = declaredClazzes[i];
265: ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz);
266: clazzId.writeTagged(os);
267: }
268: }
269:
270: private void executeStatus(ByteBuffer bb, DataOutputStream os)
271: throws JdwpException, IOException
272: {
273: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
274: Class clazz = refId.getType();
275:
276:
277: int status = VMVirtualMachine.getClassStatus(clazz);
278: os.writeInt(status);
279: }
280:
281: private void executeInterfaces(ByteBuffer bb, DataOutputStream os)
282: throws JdwpException, IOException
283: {
284: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
285: Class clazz = refId.getType();
286: Class[] interfaces = clazz.getInterfaces();
287: os.writeInt(interfaces.length);
288: for (int i = 0; i < interfaces.length; i++)
289: {
290: Class interfaceClass = interfaces[i];
291: ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass);
292: intId.write(os);
293: }
294: }
295:
296: private void executeClassObject(ByteBuffer bb, DataOutputStream os)
297: throws JdwpException, IOException
298: {
299: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
300: Class clazz = refId.getType();
301: ObjectId clazzObjectId = idMan.getObjectId(clazz);
302: clazzObjectId.write(os);
303: }
304:
305: private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os)
306: throws JdwpException, IOException
307: {
308: if (!VMVirtualMachine.canGetSourceDebugExtension)
309: {
310: String msg = "source debug extension is not supported";
311: throw new NotImplementedException(msg);
312: }
313:
314: ReferenceTypeId id = idMan.readReferenceTypeId(bb);
315: String ext = VMVirtualMachine.getSourceDebugExtension (id.getType());
316: JdwpString.writeString(os, ext);
317: }
318:
319: private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os)
320: throws JdwpException, IOException
321: {
322:
323: throw new NotImplementedException(
324: "Command SignatureWithGeneric not implemented.");
325: }
326:
327: private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os)
328: throws JdwpException, IOException
329: {
330:
331: throw new NotImplementedException(
332: "Command executeFieldWithGeneric not implemented.");
333: }
334:
335: private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os)
336: throws JdwpException, IOException
337: {
338:
339: throw new NotImplementedException(
340: "Command executeMethodsWithGeneric not implemented.");
341: }
342: }