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: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
186: Class clazz = refId.getType();
187:
188: VMMethod[] methods = VMVirtualMachine.getAllClassMethods(clazz);
189: os.writeInt (methods.length);
190: for (int i = 0; i < methods.length; i++)
191: {
192: VMMethod method = methods[i];
193: method.writeId(os);
194: JdwpString.writeString(os, method.getName());
195: JdwpString.writeString(os, method.getSignature());
196: os.writeInt(method.getModifiers());
197: }
198: }
199:
200: private void executeGetValues(ByteBuffer bb, DataOutputStream os)
201: throws JdwpException, IOException
202: {
203: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
204: Class clazz = refId.getType();
205:
206: int numFields = bb.getInt();
207: os.writeInt(numFields);
208: for (int i = 0; i < numFields; i++)
209: {
210: ObjectId fieldId = idMan.readObjectId(bb);
211: Field field = (Field) (fieldId.getObject());
212: Class fieldClazz = field.getDeclaringClass();
213:
214:
215:
216: if (fieldClazz.isAssignableFrom(clazz))
217: {
218: try
219: {
220: field.setAccessible(true);
221: Object value = field.get(null);
222: Value val = ValueFactory.createFromObject(value,
223: field.getType());
224: val.writeTagged(os);
225: }
226: catch (IllegalArgumentException ex)
227: {
228:
229: throw new InvalidFieldException(ex);
230: }
231: catch (IllegalAccessException ex)
232: {
233:
234: throw new JdwpInternalErrorException(ex);
235: }
236: }
237: else
238: throw new InvalidFieldException(fieldId.getId());
239: }
240: }
241:
242: private void executeSourceFile(ByteBuffer bb, DataOutputStream os)
243: throws JdwpException, IOException
244: {
245: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
246: Class clazz = refId.getType();
247:
248:
249: String sourceFileName = VMVirtualMachine.getSourceFile(clazz);
250: JdwpString.writeString(os, sourceFileName);
251:
252: }
253:
254: private void executeNestedTypes(ByteBuffer bb, DataOutputStream os)
255: throws JdwpException, IOException
256: {
257: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
258: Class clazz = refId.getType();
259: Class[] declaredClazzes = clazz.getDeclaredClasses();
260: os.writeInt(declaredClazzes.length);
261: for (int i = 0; i < declaredClazzes.length; i++)
262: {
263: Class decClazz = declaredClazzes[i];
264: ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz);
265: clazzId.writeTagged(os);
266: }
267: }
268:
269: private void executeStatus(ByteBuffer bb, DataOutputStream os)
270: throws JdwpException, IOException
271: {
272: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
273: Class clazz = refId.getType();
274:
275:
276: int status = VMVirtualMachine.getClassStatus(clazz);
277: os.writeInt(status);
278: }
279:
280: private void executeInterfaces(ByteBuffer bb, DataOutputStream os)
281: throws JdwpException, IOException
282: {
283: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
284: Class clazz = refId.getType();
285: Class[] interfaces = clazz.getInterfaces();
286: os.writeInt(interfaces.length);
287: for (int i = 0; i < interfaces.length; i++)
288: {
289: Class interfaceClass = interfaces[i];
290: ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass);
291: intId.write(os);
292: }
293: }
294:
295: private void executeClassObject(ByteBuffer bb, DataOutputStream os)
296: throws JdwpException, IOException
297: {
298: ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
299: Class clazz = refId.getType();
300: ObjectId clazzObjectId = idMan.getObjectId(clazz);
301: clazzObjectId.write(os);
302: }
303:
304: private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os)
305: throws JdwpException, IOException
306: {
307: if (!VMVirtualMachine.canGetSourceDebugExtension)
308: {
309: String msg = "source debug extension is not supported";
310: throw new NotImplementedException(msg);
311: }
312:
313: ReferenceTypeId id = idMan.readReferenceTypeId(bb);
314: String ext = VMVirtualMachine.getSourceDebugExtension (id.getType());
315: JdwpString.writeString(os, ext);
316: }
317:
318: private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os)
319: throws JdwpException, IOException
320: {
321:
322: throw new NotImplementedException(
323: "Command SignatureWithGeneric not implemented.");
324: }
325:
326: private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os)
327: throws JdwpException, IOException
328: {
329:
330: throw new NotImplementedException(
331: "Command executeFieldWithGeneric not implemented.");
332: }
333:
334: private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os)
335: throws JdwpException, IOException
336: {
337:
338: throw new NotImplementedException(
339: "Command executeMethodsWithGeneric not implemented.");
340: }
341: }