KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > ArrayTypeImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal;
12
13
14 import java.io.ByteArrayOutputStream JavaDoc;
15 import java.io.DataInputStream JavaDoc;
16 import java.io.DataOutputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.eclipse.jdi.internal.jdwp.JdwpArrayID;
24 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket;
25 import org.eclipse.jdi.internal.jdwp.JdwpID;
26 import org.eclipse.jdi.internal.jdwp.JdwpObjectID;
27 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket;
28
29 import com.sun.jdi.AbsentInformationException;
30 import com.sun.jdi.ArrayReference;
31 import com.sun.jdi.ArrayType;
32 import com.sun.jdi.ClassNotLoadedException;
33 import com.sun.jdi.Field;
34 import com.sun.jdi.Type;
35 import com.sun.jdi.Value;
36
37 /**
38  * this class implements the corresponding interfaces
39  * declared by the JDI specification. See the com.sun.jdi package
40  * for more information.
41  *
42  */

43 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
44     /** JDWP Tag. */
45     public static final byte typeTag = JdwpID.TYPE_TAG_ARRAY;
46     /** component type */
47     private Type fComponentType;
48     /** Component type name */
49     private String JavaDoc fComponentTypeName;
50     
51     /**
52      * Creates new ArrayTypeImpl.
53      */

54     public ArrayTypeImpl(VirtualMachineImpl vmImpl, JdwpArrayID arrayID) {
55         super("ArrayType", vmImpl, arrayID); //$NON-NLS-1$
56
}
57
58     /**
59      * Creates new ArrayTypeImpl.
60      */

61     public ArrayTypeImpl(VirtualMachineImpl vmImpl, JdwpArrayID arrayID, String JavaDoc signature, String JavaDoc genericSignature) {
62         super("ArrayType", vmImpl, arrayID, signature, genericSignature); //$NON-NLS-1$
63
}
64
65     /**
66      * @return Returns type tag.
67      */

68     public byte typeTag() {
69         return typeTag;
70     }
71     
72     /**
73      * @return Create a null value instance of the type.
74      */

75     public Value createNullValue() {
76         return new ArrayReferenceImpl(virtualMachineImpl(), new JdwpObjectID(virtualMachineImpl()));
77     }
78
79     /**
80      * @return Returns the JNI signature of the components of this array class.
81      */

82     public String JavaDoc componentSignature() {
83         return signature().substring(1);
84     }
85
86     /**
87      * @return Returns the type of the array components.
88      */

89     public Type componentType() throws ClassNotLoadedException {
90         if (fComponentType == null) {
91             fComponentType = TypeImpl.create(virtualMachineImpl(), componentSignature(), classLoader());
92         }
93         return fComponentType;
94     }
95
96     /**
97      * @return Returns a text representation of the component type.
98      */

99     public String JavaDoc componentTypeName() {
100         if (fComponentTypeName == null) {
101             fComponentTypeName = signatureToName(componentSignature());
102         }
103         return fComponentTypeName;
104     }
105
106     /**
107      * @return Creates and returns a new instance of this array class in the target VM.
108      */

109     public ArrayReference newInstance(int length) {
110         // Note that this information should not be cached.
111
initJdwpRequest();
112         try {
113             ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
114             DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
115             write(this, outData);
116             writeInt(length, "length", outData); //$NON-NLS-1$
117

118             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.AT_NEW_INSTANCE, outBytes);
119             defaultReplyErrorHandler(replyPacket.errorCode());
120     
121             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
122             ArrayReferenceImpl arrayRef = (ArrayReferenceImpl)ObjectReferenceImpl.readObjectRefWithTag(this, replyData);
123             return arrayRef;
124         } catch (IOException JavaDoc e) {
125             defaultIOExceptionHandler(e);
126             return null;
127         } finally {
128             handledJdwpRequest();
129         }
130     }
131     
132     /**
133      * @return Returns a List filled with all Location objects that map to the given line number.
134      */

135     public List JavaDoc locationsOfLine(int line) {
136         // If this reference type is an ArrayType, the returned list is always empty.
137
return Collections.EMPTY_LIST;
138     }
139     
140     /**
141      * @return Reads JDWP representation and returns new instance.
142      */

143     public static ArrayTypeImpl read(MirrorImpl target, DataInputStream JavaDoc in) throws IOException JavaDoc {
144         VirtualMachineImpl vmImpl = target.virtualMachineImpl();
145         JdwpArrayID ID = new JdwpArrayID(vmImpl);
146         ID.read(in);
147         if (target.fVerboseWriter != null)
148             target.fVerboseWriter.println("arrayType", ID.value()); //$NON-NLS-1$
149

150         if (ID.isNull())
151             return null;
152         
153         ArrayTypeImpl mirror = (ArrayTypeImpl)vmImpl.getCachedMirror(ID);
154         if (mirror == null) {
155             mirror = new ArrayTypeImpl(vmImpl, ID);
156             vmImpl.addCachedMirror(mirror);
157         }
158         return mirror;
159      }
160
161     /**
162      * @return Returns modifier bits.
163      */

164     public int modifiers() {
165         return MODIFIER_ACC_PUBLIC | MODIFIER_ACC_FINAL;
166     }
167
168     /**
169      * @return Returns a list containing each Field declared in this type.
170      */

171     public List JavaDoc fields() {
172         return Collections.EMPTY_LIST;
173     }
174
175     /**
176      * @return Returns a list containing each Method declared in this type.
177      */

178     public List JavaDoc methods() {
179         return Collections.EMPTY_LIST;
180     }
181
182     /**
183      * @return a Map of the requested static Field objects with their Value.
184      */

185     public Map JavaDoc getValues(List JavaDoc fields) {
186         if (fields.isEmpty()) {
187             return new HashMap JavaDoc();
188         }
189             
190         throw new IllegalArgumentException JavaDoc(JDIMessages.ArrayTypeImpl_getValues_not_allowed_on_array_1);
191     }
192
193     /**
194      * @return Returns a List containing each ReferenceType declared within this type.
195      */

196     public List JavaDoc nestedTypes() {
197         return Collections.EMPTY_LIST;
198     }
199         
200     /**
201      * @return Returns status of class/interface.
202      */

203     protected int status() {
204         return ReferenceTypeImpl.JDWP_CLASS_STATUS_INITIALIZED | ReferenceTypeImpl.JDWP_CLASS_STATUS_PREPARED | ReferenceTypeImpl.JDWP_CLASS_STATUS_VERIFIED;
205     }
206         
207     /**
208      * @return Reads JDWP representation and returns new instance.
209      */

210     public static ArrayTypeImpl readWithSignature(MirrorImpl target, boolean withGenericSignature, DataInputStream JavaDoc in) throws IOException JavaDoc {
211         VirtualMachineImpl vmImpl = target.virtualMachineImpl();
212         JdwpArrayID ID = new JdwpArrayID(vmImpl);
213         ID.read(in);
214         if (target.fVerboseWriter != null)
215             target.fVerboseWriter.println("arrayType", ID.value()); //$NON-NLS-1$
216

217         String JavaDoc signature = target.readString("signature", in); //$NON-NLS-1$
218
String JavaDoc genericSignature= null;
219         if (withGenericSignature) {
220             genericSignature= target.readString("generic signature", in); //$NON-NLS-1$
221
}
222         if (ID.isNull())
223             return null;
224             
225         ArrayTypeImpl mirror = (ArrayTypeImpl)vmImpl.getCachedMirror(ID);
226         if (mirror == null) {
227             mirror = new ArrayTypeImpl(vmImpl, ID);
228             vmImpl.addCachedMirror(mirror);
229         }
230         mirror.setSignature(signature);
231         mirror.setGenericSignature(genericSignature);
232         return mirror;
233      }
234      
235     /**
236      * @see com.sun.jdi.ReferenceType#allLineLocations()
237      */

238     public List JavaDoc allLineLocations() {
239         // If this reference type is an ArrayType, the returned list is always empty.
240
return Collections.EMPTY_LIST;
241     }
242     /**
243      * @see com.sun.jdi.ReferenceType#allMethods()
244      */

245     public List JavaDoc allMethods() {
246         return Collections.EMPTY_LIST;
247     }
248     /**
249      * @see com.sun.jdi.ReferenceType#allFields()
250      */

251     public List JavaDoc allFields() {
252         return Collections.EMPTY_LIST;
253     }
254     
255     /**
256      * @return Returns an identifying name for the source corresponding to the declaration of this type.
257      */

258     public String JavaDoc sourceName() throws AbsentInformationException {
259         throw new AbsentInformationException(JDIMessages.ArrayTypeImpl_No_source_name_for_Arrays_1);
260     }
261     /**
262      * @see com.sun.jdi.ReferenceType#visibleFields()
263      */

264     public List JavaDoc visibleFields() {
265         return Collections.EMPTY_LIST;
266     }
267
268     /**
269      * @see com.sun.jdi.ReferenceType#visibleMethods()
270      */

271     public List JavaDoc visibleMethods() {
272         return Collections.EMPTY_LIST;
273     }
274     /**
275      * @see com.sun.jdi.ReferenceType#fieldByName(String)
276      */

277     public Field fieldByName(String JavaDoc arg1) {
278         return null;
279     }
280     /**
281      * @see com.sun.jdi.ReferenceType#methodsByName(String)
282      */

283     public List JavaDoc methodsByName(String JavaDoc arg1) {
284         return Collections.EMPTY_LIST;
285     }
286
287     /**
288      * @see com.sun.jdi.ReferenceType#methodsByName(String, String)
289      */

290     public List JavaDoc methodsByName(String JavaDoc arg1, String JavaDoc arg2) {
291         return Collections.EMPTY_LIST;
292     }
293 }
294
Popular Tags