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