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