1:
39:
40:
41: package ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50:
51: import ;
52: import ;
53: import ;
54: import ;
55:
56:
61: public class ArrayReferenceCommandSet
62: extends CommandSet
63: {
64: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
65: throws JdwpException
66: {
67: try
68: {
69: switch (command)
70: {
71: case JdwpConstants.CommandSet.ArrayReference.LENGTH:
72: executeLength(bb, os);
73: break;
74: case JdwpConstants.CommandSet.ArrayReference.GET_VALUES:
75: executeGetValues(bb, os);
76: break;
77: case JdwpConstants.CommandSet.ArrayReference.SET_VALUES:
78: executeSetValues(bb, os);
79: break;
80: default:
81: throw new NotImplementedException("Command " + command +
82: " not found in Array Reference Command Set.");
83: }
84: }
85: catch (IOException ex)
86: {
87:
88:
89: throw new JdwpInternalErrorException(ex);
90: }
91:
92: return false;
93: }
94:
95: private void executeLength(ByteBuffer bb, DataOutputStream os)
96: throws InvalidObjectException, IOException
97: {
98: ObjectId oid = idMan.readObjectId(bb);
99: Object array = oid.getObject();
100: os.writeInt(Array.getLength(array));
101: }
102:
103: private void executeGetValues(ByteBuffer bb, DataOutputStream os)
104: throws JdwpException, IOException
105: {
106: ObjectId oid = idMan.readObjectId(bb);
107: Object array = oid.getObject();
108: int first = bb.getInt();
109: int length = bb.getInt();
110:
111:
112: Class clazz = array.getClass().getComponentType();
113:
114:
115:
116: if (clazz == byte.class)
117: os.writeByte(JdwpConstants.Tag.BYTE);
118: else if (clazz == char.class)
119: os.writeByte(JdwpConstants.Tag.CHAR);
120: else if (clazz == float.class)
121: os.writeByte(JdwpConstants.Tag.FLOAT);
122: else if (clazz == double.class)
123: os.writeByte(JdwpConstants.Tag.DOUBLE);
124: else if (clazz == int.class)
125: os.writeByte(JdwpConstants.Tag.BYTE);
126: else if (clazz == long.class)
127: os.writeByte(JdwpConstants.Tag.LONG);
128: else if (clazz == short.class)
129: os.writeByte(JdwpConstants.Tag.SHORT);
130: else if (clazz == void.class)
131: os.writeByte(JdwpConstants.Tag.VOID);
132: else if (clazz == boolean.class)
133: os.writeByte(JdwpConstants.Tag.BOOLEAN);
134: else if (clazz.isArray())
135: os.writeByte(JdwpConstants.Tag.ARRAY);
136: else if (String.class.isAssignableFrom(clazz))
137: os.writeByte(JdwpConstants.Tag.STRING);
138: else if (Thread.class.isAssignableFrom(clazz))
139: os.writeByte(JdwpConstants.Tag.THREAD);
140: else if (ThreadGroup.class.isAssignableFrom(clazz))
141: os.writeByte(JdwpConstants.Tag.THREAD_GROUP);
142: else if (ClassLoader.class.isAssignableFrom(clazz))
143: os.writeByte(JdwpConstants.Tag.CLASS_LOADER);
144: else if (Class.class.isAssignableFrom(clazz))
145: os.writeByte(JdwpConstants.Tag.CLASS_OBJECT);
146: else
147: os.writeByte(JdwpConstants.Tag.OBJECT);
148:
149:
150:
151: for (int i = first; i < first + length; i++)
152: {
153: Object value = Array.get(array, i);
154: if (clazz.isPrimitive())
155: Value.writeUntaggedValue(os, value);
156: else
157: Value.writeTaggedValue(os, value);
158: }
159: }
160:
161: private void executeSetValues(ByteBuffer bb, DataOutputStream os)
162: throws IOException, JdwpException
163: {
164: ObjectId oid = idMan.readObjectId(bb);
165: Object array = oid.getObject();
166: int first = bb.getInt();
167: int length = bb.getInt();
168: Class type = array.getClass().getComponentType();
169: for (int i = first; i < first + length; i++)
170: {
171: Object value = Value.getUntaggedObj(bb, type);
172: Array.set(array, i, value);
173: }
174: }
175: }