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:
56: import ;
57: import ;
58: import ;
59: import ;
60:
61:
66: public class ReferenceTypeCommandSet
67: extends CommandSet
68: {
69: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
70: throws JdwpException
71: {
72: try
73: {
74: switch (command)
75: {
76: case JdwpConstants.CommandSet.ReferenceType.SIGNATURE:
77: executeSignature(bb, os);
78: break;
79: case JdwpConstants.CommandSet.ReferenceType.CLASS_LOADER:
80: executeClassLoader(bb, os);
81: break;
82: case JdwpConstants.CommandSet.ReferenceType.MODIFIERS:
83: executeModifiers(bb, os);
84: break;
85: case JdwpConstants.CommandSet.ReferenceType.FIELDS:
86: executeFields(bb, os);
87: break;
88: case JdwpConstants.CommandSet.ReferenceType.METHODS:
89: executeMethods(bb, os);
90: break;
91: case JdwpConstants.CommandSet.ReferenceType.GET_VALUES:
92: executeGetValues(bb, os);
93: break;
94: case JdwpConstants.CommandSet.ReferenceType.SOURCE_FILE:
95: executeSourceFile(bb, os);
96: break;
97: case JdwpConstants.CommandSet.ReferenceType.NESTED_TYPES:
98: executeNestedTypes(bb, os);
99: break;
100: case JdwpConstants.CommandSet.ReferenceType.STATUS:
101: executeStatus(bb, os);
102: break;
103: case JdwpConstants.CommandSet.ReferenceType.INTERFACES:
104: executeInterfaces(bb, os);
105: break;
106: case JdwpConstants.CommandSet.ReferenceType.CLASS_OBJECT:
107: executeClassObject(bb, os);
108: break;
109: case JdwpConstants.CommandSet.ReferenceType.SOURCE_DEBUG_EXTENSION:
110: executeSourceDebugExtension(bb, os);
111: break;
112: case JdwpConstants.CommandSet.ReferenceType.SIGNATURE_WITH_GENERIC:
113: executeSignatureWithGeneric(bb, os);
114: break;
115: case JdwpConstants.CommandSet.ReferenceType.FIELDS_WITH_GENERIC:
116: executeFieldWithGeneric(bb, os);
117: break;
118: case JdwpConstants.CommandSet.ReferenceType.METHODS_WITH_GENERIC:
119: executeMethodsWithGeneric(bb, os);
120: break;
121: default:
122: throw new NotImplementedException("Command " + command +
123: " not found in ReferenceType Command Set.");
124: }
125: }
126: catch (IOException ex)
127: {
128:
129:
130: throw new JdwpInternalErrorException(ex);
131: }
132:
133: return false;
134: }
135:
136: private void executeSignature(ByteBuffer bb, DataOutputStream os)
137: throws JdwpException, IOException
138: {
139: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
140: String sig = Signature.computeClassSignature(refId.getType());
141: JdwpString.writeString(os, sig);
142: }
143:
144: private void executeClassLoader(ByteBuffer bb, DataOutputStream os)
145: throws JdwpException, IOException
146: {
147: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
148:
149: Class clazz = refId.getType();
150: ClassLoader loader = clazz.getClassLoader();
151: ObjectId oid = idMan.getObjectId(loader);
152: oid.write(os);
153: }
154:
155: private void executeModifiers(ByteBuffer bb, DataOutputStream os)
156: throws JdwpException, IOException
157: {
158: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
159:
160: Class clazz = refId.getType();
161: os.writeInt(clazz.getModifiers());
162: }
163:
164: private void executeFields(ByteBuffer bb, DataOutputStream os)
165: throws JdwpException, IOException
166: {
167: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
168: Class clazz = refId.getType();
169:
170: Field[] fields = clazz.getFields();
171: os.writeInt(fields.length);
172: for (int i = 0; i < fields.length; i++)
173: {
174: Field field = fields[i];
175: idMan.getObjectId(field).write(os);
176: JdwpString.writeString(os, field.getName());
177: JdwpString.writeString(os, Signature.computeFieldSignature(field));
178: os.writeInt(field.getModifiers());
179: }
180: }
181:
182: private void executeMethods(ByteBuffer bb, DataOutputStream os)
183: throws JdwpException, IOException
184: {
185: ClassReferenceTypeId refId
186: = (ClassReferenceTypeId) 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.writeTaggedValue(os, value);
224: }
225: catch (IllegalArgumentException ex)
226: {
227:
228: throw new InvalidFieldException(ex);
229: }
230: catch (IllegalAccessException ex)
231: {
232:
233: throw new JdwpInternalErrorException(ex);
234: }
235: }
236: else
237: throw new InvalidFieldException(fieldId.getId());
238: }
239: }
240:
241: private void executeSourceFile(ByteBuffer bb, DataOutputStream os)
242: throws JdwpException, IOException
243: {
244: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
245: Class clazz = refId.getType();
246:
247:
248: String sourceFileName = VMVirtualMachine.getSourceFile(clazz);
249: JdwpString.writeString(os, sourceFileName);
250:
251: }
252:
253: private void executeNestedTypes(ByteBuffer bb, DataOutputStream os)
254: throws JdwpException, IOException
255: {
256: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
257: Class clazz = refId.getType();
258: Class[] declaredClazzes = clazz.getDeclaredClasses();
259: os.writeInt(declaredClazzes.length);
260: for (int i = 0; i < declaredClazzes.length; i++)
261: {
262: Class decClazz = declaredClazzes[i];
263: ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz);
264: clazzId.writeTagged(os);
265: }
266: }
267:
268: private void executeStatus(ByteBuffer bb, DataOutputStream os)
269: throws JdwpException, IOException
270: {
271: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
272: Class clazz = refId.getType();
273:
274:
275: int status = VMVirtualMachine.getClassStatus(clazz);
276: os.writeInt(status);
277: }
278:
279: private void executeInterfaces(ByteBuffer bb, DataOutputStream os)
280: throws JdwpException, IOException
281: {
282: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
283: Class clazz = refId.getType();
284: Class[] interfaces = clazz.getInterfaces();
285: os.writeInt(interfaces.length);
286: for (int i = 0; i < interfaces.length; i++)
287: {
288: Class interfaceClass = interfaces[i];
289: ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass);
290: intId.write(os);
291: }
292: }
293:
294: private void executeClassObject(ByteBuffer bb, DataOutputStream os)
295: throws JdwpException, IOException
296: {
297: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
298: Class clazz = refId.getType();
299: ObjectId clazzObjectId = idMan.getObjectId(clazz);
300: clazzObjectId.write(os);
301: }
302:
303: private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os)
304: throws JdwpException, IOException
305: {
306:
307:
308: throw new NotImplementedException(
309: "Command SourceDebugExtension not implemented.");
310: }
311:
312: private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os)
313: throws JdwpException, IOException
314: {
315:
316: throw new NotImplementedException(
317: "Command SourceDebugExtension not implemented.");
318: }
319:
320: private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os)
321: throws JdwpException, IOException
322: {
323:
324: throw new NotImplementedException(
325: "Command SourceDebugExtension not implemented.");
326: }
327:
328: private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os)
329: throws JdwpException, IOException
330: {
331:
332: throw new NotImplementedException(
333: "Command SourceDebugExtension not implemented.");
334: }
335: }