KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Yavor Boyadzhiev <yavor.vasilev.boyadzhiev@sap.com> - Bug 162399
11  *******************************************************************************/

12 package org.eclipse.jdi.internal;
13
14
15 import java.io.ByteArrayOutputStream JavaDoc;
16 import java.io.DataInputStream JavaDoc;
17 import java.io.DataOutputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.lang.reflect.Modifier JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Hashtable JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket;
31 import org.eclipse.jdi.internal.jdwp.JdwpFieldID;
32 import org.eclipse.jdi.internal.jdwp.JdwpID;
33 import org.eclipse.jdi.internal.jdwp.JdwpMethodID;
34 import org.eclipse.jdi.internal.jdwp.JdwpReferenceTypeID;
35 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket;
36
37 import com.ibm.icu.text.MessageFormat;
38 import com.sun.jdi.AbsentInformationException;
39 import com.sun.jdi.ClassLoaderReference;
40 import com.sun.jdi.ClassNotLoadedException;
41 import com.sun.jdi.ClassNotPreparedException;
42 import com.sun.jdi.ClassObjectReference;
43 import com.sun.jdi.ClassType;
44 import com.sun.jdi.Field;
45 import com.sun.jdi.InternalException;
46 import com.sun.jdi.NativeMethodException;
47 import com.sun.jdi.ObjectCollectedException;
48 import com.sun.jdi.ReferenceType;
49 import com.sun.jdi.VMDisconnectedException;
50 import com.sun.jdi.Value;
51
52 /**
53  * this class implements the corresponding interfaces
54  * declared by the JDI specification. See the com.sun.jdi package
55  * for more information.
56  *
57  */

58 public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceType, org.eclipse.jdi.hcr.ReferenceType {
59
60     /** ClassStatus Constants. */
61     public static final int JDWP_CLASS_STATUS_VERIFIED = 1;
62     public static final int JDWP_CLASS_STATUS_PREPARED = 2;
63     public static final int JDWP_CLASS_STATUS_INITIALIZED = 4;
64     public static final int JDWP_CLASS_STATUS_ERROR = 8;
65
66     /** Mapping of command codes to strings. */
67     private static String JavaDoc[] fgClassStatusStrings = null;
68
69     /**
70      * Represent the data about one file info contained in one stratum in the SMAP.
71      */

72     protected static class FileInfo {
73         
74         /**
75          * The id.
76          */

77         protected int fFileId;
78
79         /**
80          * The name of the source file.
81          */

82         protected String JavaDoc fFileName;
83
84         /**
85          * The path of the source file.
86          */

87         protected String JavaDoc fAbsoluteFileName;
88         
89         /**
90          * Map line number in the input source file
91          * -> list of [start line in the output source file, range in the output source file].
92          * (Integer -> List of int[2]).
93          */

94         private HashMap JavaDoc fLineInfo;
95
96         /**
97          * FileInfo constructor.
98          *
99          * @param fileId the id.
100          * @param fileName the name of the source file.
101          * @param absoluteFileName the path of the source file (can be <code>null</code>).
102          */

103         public FileInfo(int fileId, String JavaDoc fileName, String JavaDoc absoluteFileName) {
104             fFileId= fileId;
105             fFileName= fileName;
106             fAbsoluteFileName= absoluteFileName;
107             fLineInfo= new HashMap JavaDoc();
108         }
109         
110         /**
111          * Add information about the mapping of one line.
112          * Associate a line in the input source file to a snippet of code
113          * in the output source file.
114          *
115          * @param inputLine the line number in the input source file.
116          * @param outputStartLine the number of the first line of the corresponding snippet in the output source file.
117          * @param outputLineRange the size of the corresponding snippet in the output source file.
118          */

119         public void addLineInfo(int inputLine, int outputStartLine, int outputLineRange) {
120             Integer JavaDoc key= new Integer JavaDoc(inputLine);
121             List JavaDoc outputLines= (List JavaDoc)fLineInfo.get(key);
122             if (outputLines == null) {
123                 outputLines= new ArrayList JavaDoc();
124                 fLineInfo.put(key, outputLines);
125             }
126             outputLines.add(new int[] {outputStartLine, outputLineRange});
127         }
128
129         /**
130          * Return a list of line information about the code in the output source file
131          * associated to the given line in the input source file.
132          *
133          * @param lineNumber the line number in the input source file.
134          * @return a List of int[2].
135          */

136         public List JavaDoc getOutputLinesForLine(int lineNumber) {
137             List JavaDoc list= new ArrayList JavaDoc();
138             List JavaDoc outputLines= (List JavaDoc)fLineInfo.get(new Integer JavaDoc(lineNumber));
139             if (outputLines != null) {
140                 for (Iterator JavaDoc iter = outputLines.iterator(); iter.hasNext();) {
141                     int[] info = (int[])iter.next();
142                     int outputLineNumber= info[0];
143                     int length = info[1];
144                     if (length == 0){
145                         length = length + 1;
146                     }
147                     for (int i= 0; i < length; i++) {
148                         list.add(new Integer JavaDoc(outputLineNumber++));
149                     }
150                 }
151             }
152             return list;
153         }
154
155         /**
156          * @see java.lang.Object#equals(java.lang.Object)
157          */

158         public boolean equals(Object JavaDoc object) {
159             if (!(object instanceof FileInfo)) {
160                 return false;
161             }
162             return fFileId == ((FileInfo)object).fFileId;
163         }
164
165     }
166     
167     /**
168      * Represent the information contained in the SMAP about one stratum.
169      */

170     protected static class Stratum {
171
172         /**
173          * The id of this stratum.
174          */

175         private String JavaDoc fId;
176         
177         /**
178          * The file info data associated to this stratum.
179          */

180         private List JavaDoc fFileInfos;
181     
182         /**
183          * Id of the primary file for this stratum.
184          */

185         private int fPrimaryFileId;
186         
187         /**
188          * Map line number in the output source file -> list of line numbers in the input source file.
189          * (Integer -> List of Integer)
190          */

191         private HashMap JavaDoc fOutputLineToInputLine;
192         
193         /**
194          * Stratum constructor.
195          * @param id The id of this stratum.
196          */

197         public Stratum(String JavaDoc id) {
198             fId= id;
199             fFileInfos= new ArrayList JavaDoc();
200             fOutputLineToInputLine= new HashMap JavaDoc();
201             fPrimaryFileId= -1;
202         }
203         
204         /**
205          * Add a file info to this stratum.
206          *
207          * @param fileId the id.
208          * @param fileName the name of the source file.
209          */

210         public void addFileInfo(int fileId, String JavaDoc fileName) throws AbsentInformationException {
211             addFileInfo(fileId, fileName, null);
212         }
213         
214         /**
215          * Add a file info to this stratum.
216          *
217          * @param fileId the id.
218          * @param fileName the name of the source file.
219          * @param absoluteFileName the path of the source file.
220          */

221         public void addFileInfo(int fileId, String JavaDoc fileName, String JavaDoc absoluteFileName) throws AbsentInformationException {
222             if (fPrimaryFileId == -1) {
223                 fPrimaryFileId= fileId;
224             }
225             FileInfo fileInfo= new FileInfo(fileId, fileName, absoluteFileName);
226             if (fFileInfos.contains(fileInfo)) {
227                 throw new AbsentInformationException(MessageFormat.format(JDIMessages.ReferenceTypeImpl_28, new String JavaDoc[] {Integer.toString(fileId), fId}));
228             }
229             fFileInfos.add(fileInfo);
230         }
231
232         /**
233          * Add line mapping information.
234          *
235          * @param inputStartLine number of the first line in the input source file.
236          * @param lineFileId id of the input source file.
237          * @param repeatCount number of iterations.
238          * @param outputStartLine number of the first line in the output source file.
239          * @param outputLineIncrement number of line to increment at each iteration.
240          * @throws AbsentInformationException
241          */

242         public void addLineInfo(int inputStartLine, int lineFileId, int repeatCount, int outputStartLine, int outputLineIncrement) throws AbsentInformationException {
243             FileInfo fileInfo= null;
244             // get the FileInfo object
245
for (Iterator JavaDoc iter = fFileInfos.iterator(); iter.hasNext();) {
246                 FileInfo element = (FileInfo)iter.next();
247                 if (element.fFileId == lineFileId) {
248                     fileInfo= element;
249                 }
250             }
251             if (fileInfo == null) {
252                 throw new AbsentInformationException(MessageFormat.format(JDIMessages.ReferenceTypeImpl_29, new String JavaDoc[] {Integer.toString(lineFileId)}));
253             }
254             // add the data to the different hash maps.
255
for (int i= 0; i < repeatCount; i++, inputStartLine++) {
256                 fileInfo.addLineInfo(inputStartLine, outputStartLine, outputLineIncrement);
257                 if (outputLineIncrement == 0) {
258                     // see bug 40022
259
addLineInfoToMap(inputStartLine, lineFileId, outputStartLine);
260                 } else {
261                     for (int j= 0; j < outputLineIncrement; j++, outputStartLine++) {
262                         addLineInfoToMap(inputStartLine, lineFileId, outputStartLine);
263                     }
264                 }
265             }
266         }
267
268         /**
269          * Add the data to the map.
270          */

271         private void addLineInfoToMap(int inputStartLine, int lineFileId, int outputStartLine) {
272             Integer JavaDoc key= new Integer JavaDoc(outputStartLine);
273             List JavaDoc inputLines= (List JavaDoc)fOutputLineToInputLine.get(key);
274             if (inputLines == null) {
275                 inputLines= new ArrayList JavaDoc();
276                 fOutputLineToInputLine.put(key, inputLines);
277             }
278             inputLines.add(new int[] {lineFileId, inputStartLine});
279         }
280
281         /**
282          * Return the FileInfo object for the specified source name.
283          * Return <code>null</code> if the specified name is the source name of no file info.
284          * @param sourceName the source name to search.
285          */

286         public FileInfo getFileInfo(String JavaDoc sourceName) {
287             for (Iterator JavaDoc iter = fFileInfos.iterator(); iter.hasNext();) {
288                 FileInfo fileInfo = (FileInfo)iter.next();
289                 if (fileInfo.fFileName.equals(sourceName)) {
290                     return fileInfo;
291                 }
292             }
293             return null;
294         }
295
296         /**
297          * @param outputLineNumber
298          * @return
299          */

300         public List JavaDoc getInputLineInfos(int outputLineNumber) {
301             return (List JavaDoc)fOutputLineToInputLine.get(new Integer JavaDoc(outputLineNumber));
302         }
303
304     }
305     
306
307
308     /** ReferenceTypeID that corresponds to this reference. */
309     private JdwpReferenceTypeID fReferenceTypeID;
310
311     /** The following are the stored results of JDWP calls. */
312     protected List JavaDoc fInterfaces = null;
313     private List JavaDoc fMethods = null;
314     private Hashtable JavaDoc fMethodTable= null;
315     private List JavaDoc fFields = null;
316     private List JavaDoc fAllMethods = null;
317     private List JavaDoc fVisibleMethods = null;
318     private List JavaDoc fAllFields = null;
319     private List JavaDoc fVisibleFields = null;
320     private List JavaDoc fAllInterfaces = null;
321     private Map JavaDoc fStratumAllLineLocations = null;
322     private String JavaDoc fSourceName = null;
323     private int fModifierBits = -1;
324     private ClassLoaderReferenceImpl fClassLoader = null;
325     private ClassObjectReferenceImpl fClassObject = null;
326     
327     private String JavaDoc fGenericSignature; // 1.5 addition
328
private boolean fGenericSignatureKnown; // 1.5 addition
329

330     private boolean fGotClassFileVersion = false; // HCR addition.
331
private int fClassFileVersion; // HCR addition.
332
private boolean fIsHCREligible; // HCR addition.
333
private boolean fIsVersionKnown; // HCR addition.
334

335     private boolean fSourceDebugExtensionAvailable= true; // JSR-045 addition
336

337     /**
338      * The default stratum id.
339      */

340     private String JavaDoc fDefaultStratumId; // JSR-045 addition
341

342     /**
343      * A map of the defined strata.
344      * Map stratum id -> Stratum object.
345      * (String -> Stratum).
346      */

347     private Map JavaDoc fStrata; // JSR-045 addition
348

349     /**
350      * The source map string returned by the VM.
351      */

352     private String JavaDoc fSmap; // JSR-045 addition
353

354     /**
355      * Creates new instance.
356      */

357     protected ReferenceTypeImpl(String JavaDoc description, VirtualMachineImpl vmImpl, JdwpReferenceTypeID referenceTypeID) {
358         super(description, vmImpl);
359         fReferenceTypeID = referenceTypeID;
360     }
361     
362     /**
363      * Creates new instance.
364      */

365     protected ReferenceTypeImpl(String JavaDoc description, VirtualMachineImpl vmImpl, JdwpReferenceTypeID referenceTypeID, String JavaDoc signature, String JavaDoc genericSignature) {
366         super(description, vmImpl);
367         fReferenceTypeID = referenceTypeID;
368         setSignature(signature);
369         setGenericSignature(genericSignature);
370     }
371     
372     /**
373      * @return Returns type tag.
374      */

375     public abstract byte typeTag();
376     
377     /**
378      * Flushes all stored Jdwp results.
379      */

380     public void flushStoredJdwpResults() {
381         Iterator JavaDoc iter;
382     
383         // Flush Methods.
384
if (fMethods != null) {
385             iter = fMethods.iterator();
386             while (iter.hasNext()) {
387                 MethodImpl method = (MethodImpl)iter.next();
388                 method.flushStoredJdwpResults();
389             }
390             fMethods = null;
391             fMethodTable= null;
392         }
393
394         // Flush Fields.
395
if (fFields != null) {
396             iter = fFields.iterator();
397             while (iter.hasNext()) {
398                 FieldImpl field = (FieldImpl)iter.next();
399                 field.flushStoredJdwpResults();
400             }
401             fFields = null;
402         }
403
404         fInterfaces = null;
405         fAllMethods = null;
406         fVisibleMethods = null;
407         fAllFields = null;
408         fVisibleFields = null;
409         fAllInterfaces = null;
410         fStratumAllLineLocations = null;
411         fSourceName = null;
412         fModifierBits = -1;
413         fClassLoader = null;
414         fClassObject = null;
415         fGotClassFileVersion = false;
416         // java 1.5
417
fGenericSignature= null;
418         fGenericSignatureKnown= false;
419         
420         // JSR-045
421
fSourceDebugExtensionAvailable= true;
422         fDefaultStratumId= null;
423         fStrata= null;
424         fSmap= null;
425         
426         // The following cached results are stored higher up in the class hierarchy.
427
fSignature = null;
428         fSourceName = null;
429     }
430     
431     /**
432      * @return Returns the interfaces declared as implemented by this class. Interfaces indirectly implemented (extended by the implemented interface or implemented by a superclass) are not included.
433      */

434     public List JavaDoc allInterfaces() {
435         if (fAllInterfaces != null) {
436             return fAllInterfaces;
437         }
438     
439         /* Recursion:
440          * The interfaces that it directly implements;
441          * All interfaces that are implemented by its interfaces;
442          * If it is a class, all interfaces that are implemented by its superclass.
443          */

444         // The interfaces are maintained in a set, to avoid duplicates.
445
// The interfaces of its own (own interfaces() command) are first inserted.
446
HashSet JavaDoc allInterfacesSet = new HashSet JavaDoc(interfaces());
447         
448         // All interfaces of the interfaces it implements.
449
Iterator JavaDoc interfaces = interfaces().iterator();
450         InterfaceTypeImpl inter;
451         while (interfaces.hasNext()) {
452             inter = (InterfaceTypeImpl)interfaces.next();
453             allInterfacesSet.addAll(inter.allInterfaces());
454         }
455         
456         // If it is a class, all interfaces of it's superclass.
457
if (this instanceof ClassType) {
458             ClassType superclass = ((ClassType)this).superclass();
459             if (superclass != null) {
460                 allInterfacesSet.addAll(superclass.allInterfaces());
461             }
462         }
463                 
464         fAllInterfaces = new ArrayList JavaDoc(allInterfacesSet);
465         return fAllInterfaces;
466     }
467     
468     /**
469      * @return Returns Jdwp Reference ID.
470      */

471     public JdwpReferenceTypeID getRefTypeID() {
472         return fReferenceTypeID;
473     }
474     
475     /**
476      * @return Returns modifier bits.
477      */

478     public int modifiers() {
479         if (fModifierBits != -1)
480             return fModifierBits;
481             
482         initJdwpRequest();
483         try {
484             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_MODIFIERS, this);
485             defaultReplyErrorHandler(replyPacket.errorCode());
486             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
487             fModifierBits = readInt("modifiers", AccessibleImpl.getModifierStrings(), replyData); //$NON-NLS-1$
488
return fModifierBits;
489         } catch (IOException JavaDoc e) {
490             defaultIOExceptionHandler(e);
491             return 0;
492         } finally {
493             handledJdwpRequest();
494         }
495     }
496     
497     /**
498      * Add methods to a set of methods if they are not overridden, add new names+signature combinations to set of names+signature combinations.
499      */

500     private void addVisibleMethods(List JavaDoc inheritedMethods, Set JavaDoc nameAndSignatures, List JavaDoc resultMethods) {
501         Iterator JavaDoc iter = inheritedMethods.iterator();
502         MethodImpl inheritedMethod;
503         while (iter.hasNext()) {
504             inheritedMethod = (MethodImpl)iter.next();
505             if (!nameAndSignatures.contains(inheritedMethod.name() + inheritedMethod.signature())) {
506                 resultMethods.add(inheritedMethod);
507             }
508         }
509     }
510     
511     /**
512      * @return Returns a list containing each visible and unambiguous Method in this type.
513      */

514     public List JavaDoc visibleMethods() {
515         if (fVisibleMethods != null)
516             return fVisibleMethods;
517
518         /* Recursion:
519          * The methods of its own (own methods() command);
520          * All methods of the interfaces it implements;
521          * If it is a class, all methods of it's superclass.
522          */

523         // The name+signature combinations of methods are maintained in a set, to avoid including methods that have been overridden.
524
Set JavaDoc namesAndSignatures = new HashSet JavaDoc();
525         List JavaDoc visibleMethods= new ArrayList JavaDoc();
526         
527         // The methods of its own (own methods() command).
528
for (Iterator JavaDoc iter= methods().iterator(); iter.hasNext();) {
529             MethodImpl method= (MethodImpl) iter.next();
530             namesAndSignatures.add(method.name() + method.signature());
531             visibleMethods.add(method);
532         }
533
534         // All methods of the interfaces it implements.
535
Iterator JavaDoc interfaces = interfaces().iterator();
536         InterfaceTypeImpl inter;
537         while (interfaces.hasNext()) {
538             inter = (InterfaceTypeImpl)interfaces.next();
539             addVisibleMethods(inter.visibleMethods(), namesAndSignatures, visibleMethods);
540         }
541         
542         // If it is a class, all methods of it's superclass.
543
if (this instanceof ClassType) {
544             ClassType superclass = ((ClassType)this).superclass();
545             if (superclass != null)
546                 addVisibleMethods(superclass.visibleMethods(), namesAndSignatures, visibleMethods);
547         }
548         
549         fVisibleMethods= visibleMethods;
550         return fVisibleMethods;
551     }
552
553     /**
554      * @return Returns a list containing each Method declared in this type, and its super-classes, implemented interfaces, and/or super-interfaces.
555      */

556     public List JavaDoc allMethods() {
557         if (fAllMethods != null)
558             return fAllMethods;
559
560         /* Recursion:
561          * The methods of its own (own methods() command);
562          * All methods of the interfaces it implements;
563          * If it is a class, all methods of it's superclass.
564          */

565         // The name+signature combinations of methods are maintained in a set.
566
HashSet JavaDoc resultSet = new HashSet JavaDoc();
567         
568         // The methods of its own (own methods() command).
569
resultSet.addAll(methods());
570         
571         // All methods of the interfaces it implements.
572
Iterator JavaDoc interfaces = interfaces().iterator();
573         InterfaceTypeImpl inter;
574         while (interfaces.hasNext()) {
575             inter = (InterfaceTypeImpl)interfaces.next();
576             resultSet.addAll(inter.allMethods());
577         }
578         
579         // If it is a class, all methods of it's superclass.
580
if (this instanceof ClassType) {
581             ClassType superclass = ((ClassType)this).superclass();
582             if (superclass != null)
583                 resultSet.addAll(superclass.allMethods());
584         }
585         
586         fAllMethods = new ArrayList JavaDoc(resultSet);
587         return fAllMethods;
588     }
589
590     /**
591      * @return Returns the interfaces declared as implemented by this class. Interfaces indirectly implemented (extended by the implemented interface or implemented by a superclass) are not included.
592      */

593     public List JavaDoc interfaces() {
594         if (fInterfaces != null) {
595             return fInterfaces;
596         }
597             
598         initJdwpRequest();
599         try {
600             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_INTERFACES, this);
601             switch (replyPacket.errorCode()) {
602                 case JdwpReplyPacket.NOT_FOUND:
603                     // Workaround for problem in J2ME WTK (wireless toolkit)
604
// @see Bug 12966
605
return Collections.EMPTY_LIST;
606                 default:
607                     defaultReplyErrorHandler(replyPacket.errorCode());
608             }
609             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
610             List JavaDoc elements = new ArrayList JavaDoc();
611             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
612
for (int i = 0; i < nrOfElements; i++) {
613                 InterfaceTypeImpl ref = InterfaceTypeImpl.read(this, replyData);
614                 if (ref == null) {
615                     continue;
616                 }
617                 elements.add(ref);
618             }
619             fInterfaces = elements;
620             return elements;
621         } catch (IOException JavaDoc e) {
622             defaultIOExceptionHandler(e);
623             return null;
624         } finally {
625             handledJdwpRequest();
626         }
627     }
628             
629     /**
630      * Add fields to a set of fields if they are not overridden, add new field names to set of field names.
631      */

632     private void addVisibleFields(List JavaDoc newFields, Set JavaDoc names, List JavaDoc resultFields) {
633         Iterator JavaDoc iter = newFields.iterator();
634         FieldImpl field;
635         while (iter.hasNext()) {
636             field = (FieldImpl)iter.next();
637             String JavaDoc name = field.name();
638             if (!names.contains(name)) {
639                 resultFields.add(field);
640                 names.add(name);
641             }
642         }
643     }
644     
645     /**
646      * @return Returns a list containing each visible and unambiguous Field in this type.
647      */

648     public List JavaDoc visibleFields() {
649         if (fVisibleFields != null)
650             return fVisibleFields;
651
652         /* Recursion:
653          * The fields of its own (own fields() command);
654          * All fields of the interfaces it implements;
655          * If it is a class, all fields of it's superclass.
656          */

657         // The names of fields are maintained in a set, to avoid including fields that have been overridden.
658
HashSet JavaDoc fieldNames = new HashSet JavaDoc();
659         
660         // The fields of its own (own fields() command).
661
List JavaDoc visibleFields = new ArrayList JavaDoc();
662         addVisibleFields(fields(), fieldNames, visibleFields);
663         
664         // All fields of the interfaces it implements.
665
Iterator JavaDoc interfaces = interfaces().iterator();
666         InterfaceTypeImpl inter;
667         while (interfaces.hasNext()) {
668             inter = (InterfaceTypeImpl)interfaces.next();
669             addVisibleFields(inter.visibleFields(), fieldNames, visibleFields);
670         }
671         
672         // If it is a class, all fields of it's superclass.
673
if (this instanceof ClassType) {
674             ClassType superclass = ((ClassType)this).superclass();
675             if (superclass != null)
676                 addVisibleFields(superclass.visibleFields(), fieldNames, visibleFields);
677         }
678                 
679         fVisibleFields = visibleFields;
680         return fVisibleFields;
681     }
682
683     /**
684      * @return Returns a list containing each Field declared in this type, and its super-classes, implemented interfaces, and/or super-interfaces.
685      */

686     public List JavaDoc allFields() {
687         if (fAllFields != null)
688             return fAllFields;
689
690         /* Recursion:
691          * The fields of its own (own fields() command);
692          * All fields of the interfaces it implements;
693          * If it is a class, all fields of it's superclass.
694          */

695         // The names of fields are maintained in a set, to avoid including fields that have been inherited double.
696
HashSet JavaDoc resultSet = new HashSet JavaDoc();
697         
698         // The fields of its own (own fields() command).
699
resultSet.addAll(fields());
700         
701         // All fields of the interfaces it implements.
702
Iterator JavaDoc interfaces = interfaces().iterator();
703         InterfaceTypeImpl inter;
704         while (interfaces.hasNext()) {
705             inter = (InterfaceTypeImpl)interfaces.next();
706             resultSet.addAll(inter.allFields());
707         }
708         
709         // If it is a class, all fields of it's superclass.
710
if (this instanceof ClassType) {
711             ClassType superclass = ((ClassType)this).superclass();
712             if (superclass != null)
713                 resultSet.addAll(superclass.allFields());
714         }
715                 
716         fAllFields = new ArrayList JavaDoc(resultSet);
717         return fAllFields;
718     }
719     
720     /**
721      * @return Returns the class loader object which loaded the class corresponding to this type.
722      */

723     public ClassLoaderReference classLoader() {
724         if (fClassLoader != null)
725             return fClassLoader;
726
727         initJdwpRequest();
728         try {
729             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_LOADER, this);
730             defaultReplyErrorHandler(replyPacket.errorCode());
731             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
732             fClassLoader = ClassLoaderReferenceImpl.read(this, replyData);
733             return fClassLoader;
734         } catch (IOException JavaDoc e) {
735             defaultIOExceptionHandler(e);
736             return null;
737         } finally {
738             handledJdwpRequest();
739         }
740     }
741         
742     /**
743      * @return Returns the class object that corresponds to this type in the target VM.
744      */

745     public ClassObjectReference classObject() {
746         if (fClassObject != null)
747             return fClassObject;
748
749         initJdwpRequest();
750         try {
751             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_OBJECT, this);
752             defaultReplyErrorHandler(replyPacket.errorCode());
753             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
754             fClassObject = ClassObjectReferenceImpl.read(this, replyData);
755             return fClassObject;
756         } catch (IOException JavaDoc e) {
757             defaultIOExceptionHandler(e);
758             return null;
759         } finally {
760             handledJdwpRequest();
761         }
762     }
763
764     /**
765      * @return Returns status of class/interface.
766      */

767     protected int status() {
768         // Note that this information should not be cached.
769
initJdwpRequest();
770         try {
771             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_STATUS, this);
772             defaultReplyErrorHandler(replyPacket.errorCode());
773             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
774             int status = readInt("status", classStatusStrings(), replyData); //$NON-NLS-1$
775
return status;
776         } catch (IOException JavaDoc e) {
777             defaultIOExceptionHandler(e);
778             return 0;
779         } finally {
780             handledJdwpRequest();
781         }
782     }
783     
784     /**
785      * @return Returns true if initialization failed for this class.
786      */

787     public boolean failedToInitialize() {
788         return (status() & JDWP_CLASS_STATUS_ERROR) != 0;
789     }
790
791     /**
792      * @return Returns true if this type has been initialized.
793      */

794     public boolean isInitialized() {
795         return (status() & JDWP_CLASS_STATUS_INITIALIZED) != 0;
796     }
797
798     /**
799      * @return Returns true if this type has been prepared.
800      */

801     public boolean isPrepared() {
802         return (status() & JDWP_CLASS_STATUS_PREPARED) != 0;
803     }
804
805     /**
806      * @return Returns true if this type has been verified.
807      */

808     public boolean isVerified() {
809         return (status() & JDWP_CLASS_STATUS_VERIFIED) != 0;
810     }
811
812     /**
813      * @return Returns the visible Field with the given non-ambiguous name.
814      */

815     public Field fieldByName(String JavaDoc name) {
816         Iterator JavaDoc iter = visibleFields().iterator();
817         while (iter.hasNext()) {
818             FieldImpl field = (FieldImpl)iter.next();
819             if (field.name().equals(name))
820                 return field;
821         }
822         return null;
823     }
824     
825     /**
826      * @return Returns a list containing each Field declared in this type.
827      */

828     public List JavaDoc fields() {
829         if (fFields != null) {
830             return fFields;
831         }
832         
833         // Note: Fields are returned in the order they occur in the class file, therefore their
834
// order in this list can be used for comparisons.
835
initJdwpRequest();
836         try {
837             boolean withGenericSignature= virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5);
838             int jdwpCommand= withGenericSignature ? JdwpCommandPacket.RT_FIELDS_WITH_GENERIC : JdwpCommandPacket.RT_FIELDS;
839             JdwpReplyPacket replyPacket = requestVM(jdwpCommand, this);
840             defaultReplyErrorHandler(replyPacket.errorCode());
841             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
842             List JavaDoc elements = new ArrayList JavaDoc();
843             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
844
for (int i = 0; i < nrOfElements; i++) {
845                 FieldImpl elt = FieldImpl.readWithNameSignatureModifiers(this, this, withGenericSignature, replyData);
846                 if (elt == null) {
847                     continue;
848                 }
849                 elements.add(elt);
850             }
851             fFields = elements;
852             return fFields;
853         } catch (IOException JavaDoc e) {
854             defaultIOExceptionHandler(e);
855             return null;
856         } finally {
857             handledJdwpRequest();
858         }
859     }
860     
861     /**
862      * @return Returns FieldImpl of a field in the reference specified by a given fieldID, or null if not found.
863      */

864     public FieldImpl findField(JdwpFieldID fieldID) {
865         Iterator JavaDoc iter = fields().iterator();
866         while(iter.hasNext()) {
867             FieldImpl field = (FieldImpl)iter.next();
868             if (field.getFieldID().equals(fieldID))
869                 return field;
870         }
871         return null;
872     }
873     
874     /**
875      * @return Returns MethodImpl of a method in the reference specified by a given methodID, or null if not found.
876      */

877     public MethodImpl findMethod(JdwpMethodID methodID) {
878         if (methodID.value() == 0) {
879             return new MethodImpl(virtualMachineImpl(), this, methodID, JDIMessages.ReferenceTypeImpl_Obsolete_method_1, "", null, -1); //$NON-NLS-1$
880
}
881         if (fMethodTable == null) {
882             fMethodTable= new Hashtable JavaDoc();
883             Iterator JavaDoc iter = methods().iterator();
884             while(iter.hasNext()) {
885                 MethodImpl method = (MethodImpl)iter.next();
886                 fMethodTable.put(method.getMethodID(), method);
887             }
888         }
889         return (MethodImpl)fMethodTable.get(methodID);
890     }
891     
892     /**
893      * @return Returns the Value of a given static Field in this type.
894      */

895     public Value getValue(Field field) {
896         ArrayList JavaDoc list = new ArrayList JavaDoc(1);
897         list.add(field);
898         return (ValueImpl)getValues(list).get(field);
899     }
900         
901     /**
902      * @return a Map of the requested static Field objects with their Value.
903      */

904     public Map JavaDoc getValues(List JavaDoc fields) {
905         // if the field list is empty, nothing to do
906
if (fields.isEmpty()) {
907             return new HashMap JavaDoc();
908         }
909         // Note that this information should not be cached.
910
initJdwpRequest();
911         try {
912             ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
913             DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
914             int fieldsSize = fields.size();
915             write(this, outData);
916             writeInt(fieldsSize, "size", outData); //$NON-NLS-1$
917
for (int i = 0; i < fieldsSize; i++) {
918                 FieldImpl field = (FieldImpl)fields.get(i);
919                 checkVM(field);
920                 field.getFieldID().write(outData);
921             }
922     
923             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_GET_VALUES, outBytes);
924             defaultReplyErrorHandler(replyPacket.errorCode());
925             
926             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
927             HashMap JavaDoc map = new HashMap JavaDoc();
928             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
929
if (nrOfElements != fieldsSize)
930                 throw new InternalError JavaDoc(JDIMessages.ReferenceTypeImpl_Retrieved_a_different_number_of_values_from_the_VM_than_requested_3);
931                 
932             for (int i = 0; i < nrOfElements; i++) {
933                 map.put(fields.get(i), ValueImpl.readWithTag(this, replyData));
934             }
935             return map;
936         } catch (IOException JavaDoc e) {
937             defaultIOExceptionHandler(e);
938             return null;
939         } finally {
940             handledJdwpRequest();
941         }
942     }
943     
944     /**
945      * @return Returns the hash code value.
946      */

947     public int hashCode() {
948         return fReferenceTypeID.hashCode();
949     }
950     
951     /**
952      * @return Returns true if two mirrors refer to the same entity in the target VM.
953      * @see java.lang.Object#equals(Object)
954      */

955     public boolean equals(Object JavaDoc object) {
956         return object != null
957             && object.getClass().equals(this.getClass())
958             && fReferenceTypeID.equals(((ReferenceTypeImpl)object).fReferenceTypeID)
959             && virtualMachine().equals(((MirrorImpl)object).virtualMachine());
960     }
961     
962     /**
963      * @return Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
964      */

965     public int compareTo(Object JavaDoc object) {
966         if (object == null || !object.getClass().equals(this.getClass()))
967             throw new ClassCastException JavaDoc(JDIMessages.ReferenceTypeImpl_Can__t_compare_reference_type_to_given_object_4);
968         return name().compareTo(((ReferenceType)object).name());
969     }
970     
971     /**
972      * @return Returns true if the type was declared abstract.
973      */

974     public boolean isAbstract() {
975         return (modifiers() & MODIFIER_ACC_ABSTRACT) != 0;
976     }
977     
978     /**
979      * @return Returns true if the type was declared final.
980      */

981     public boolean isFinal() {
982         return (modifiers() & MODIFIER_ACC_FINAL) != 0;
983     }
984     
985     /**
986      * @return Returns true if the type was declared static.
987      */

988     public boolean isStatic() {
989         return (modifiers() & MODIFIER_ACC_STATIC) != 0;
990     }
991     
992     /**
993      * @return Returns a List filled with all Location objects that map to the given line number.
994      */

995     public List JavaDoc locationsOfLine(int line) throws AbsentInformationException {
996         return locationsOfLine(virtualMachine().getDefaultStratum(), null, line);
997     }
998     
999     /**
1000     * @return Returns a list containing each Method declared directly in this type.
1001     */

1002    public List JavaDoc methods() {
1003        // Note that ArrayReference overwrites this method by returning an empty list.
1004
if (fMethods != null)
1005            return fMethods;
1006        
1007        // Note: Methods are returned in the order they occur in the class file, therefore their
1008
// order in this list can be used for comparisons.
1009
initJdwpRequest();
1010        try {
1011            boolean withGenericSignature= virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5);
1012            int jdwpCommand= withGenericSignature ? JdwpCommandPacket.RT_METHODS_WITH_GENERIC : JdwpCommandPacket.RT_METHODS;
1013            JdwpReplyPacket replyPacket = requestVM(jdwpCommand, this);
1014            defaultReplyErrorHandler(replyPacket.errorCode());
1015            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1016            List JavaDoc elements = new ArrayList JavaDoc();
1017            int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
1018
for (int i = 0; i < nrOfElements; i++) {
1019                MethodImpl elt = MethodImpl.readWithNameSignatureModifiers(this, this, withGenericSignature, replyData);
1020                if (elt == null) {
1021                    continue;
1022                }
1023                elements.add(elt);
1024            }
1025            fMethods = elements;
1026            return fMethods;
1027        } catch (IOException JavaDoc e) {
1028            defaultIOExceptionHandler(e);
1029            return null;
1030        } finally {
1031            handledJdwpRequest();
1032        }
1033    }
1034    
1035    /**
1036     * @return Returns a List containing each visible Method that has the given name.
1037     */

1038    public List JavaDoc methodsByName(String JavaDoc name) {
1039        List JavaDoc elements = new ArrayList JavaDoc();
1040        Iterator JavaDoc iter = visibleMethods().iterator();
1041        while (iter.hasNext()) {
1042            MethodImpl method = (MethodImpl)iter.next();
1043            if (method.name().equals(name)){
1044                elements.add(method);
1045            }
1046        }
1047        return elements;
1048    }
1049
1050    /**
1051     * @return Returns a List containing each visible Method that has the given name and signature.
1052     */

1053    public List JavaDoc methodsByName(String JavaDoc name, String JavaDoc signature) {
1054        List JavaDoc elements = new ArrayList JavaDoc();
1055        Iterator JavaDoc iter = visibleMethods().iterator();
1056        while (iter.hasNext()) {
1057            MethodImpl method = (MethodImpl)iter.next();
1058            if (method.name().equals(name) && method.signature().equals(signature)) {
1059                elements.add(method);
1060            }
1061        }
1062        return elements;
1063    }
1064
1065    /**
1066     * @return Returns the fully qualified name of this type.
1067     */

1068    public String JavaDoc name() {
1069        // Make sure that we know the signature, from which the name is derived.
1070
if (fName == null) {
1071            setName(signatureToName(signature()));
1072        }
1073        return fName;
1074    }
1075    
1076    /**
1077     * @return Returns the JNI-style signature for this type.
1078     */

1079    public String JavaDoc signature() {
1080        if (fSignature != null) {
1081            return fSignature;
1082        }
1083        initJdwpRequest();
1084        try {
1085            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SIGNATURE, this);
1086            defaultReplyErrorHandler(replyPacket.errorCode());
1087            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1088            setSignature(readString("signature", replyData)); //$NON-NLS-1$
1089
return fSignature;
1090        } catch (IOException JavaDoc e) {
1091            defaultIOExceptionHandler(e);
1092            return null;
1093        } finally {
1094            handledJdwpRequest();
1095        }
1096    }
1097
1098    /**
1099     * @return Returns a List containing each ReferenceType declared within this type.
1100     */

1101    public List JavaDoc nestedTypes() {
1102        // Note that the VM gives an empty reply on RT_NESTED_TYPES, therefore we search for the
1103
// nested types in the loaded types.
1104
List JavaDoc result = new ArrayList JavaDoc();
1105        Iterator JavaDoc itr = virtualMachineImpl().allRefTypes();
1106        while (itr.hasNext()) {
1107            try {
1108                ReferenceTypeImpl refType = (ReferenceTypeImpl)itr.next();
1109                String JavaDoc refName = refType.name();
1110                if (refName.length() > name().length() && refName.startsWith(name()) && refName.charAt(name().length()) == '$') {
1111                    result.add(refType);
1112                }
1113            } catch (ClassNotPreparedException e) {
1114                continue;
1115            }
1116        }
1117        return result;
1118    }
1119
1120    /**
1121     * @return Returns an identifying name for the source corresponding to the declaration of this type.
1122     */

1123    public String JavaDoc sourceName() throws AbsentInformationException {
1124        // sourceNames list in never empty, an AbsentInformationException is thrown
1125
// if the source name is not known.
1126
return (String JavaDoc)sourceNames(virtualMachine().getDefaultStratum()).get(0);
1127    }
1128
1129    /**
1130     * @return Returns the CRC-32 of the given reference type, undefined if unknown.
1131     */

1132    public int getClassFileVersion() {
1133        virtualMachineImpl().checkHCRSupported();
1134        if (fGotClassFileVersion)
1135            return fClassFileVersion;
1136        
1137        initJdwpRequest();
1138        try {
1139            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.HCR_GET_CLASS_VERSION, this);
1140            defaultReplyErrorHandler(replyPacket.errorCode());
1141            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1142            fIsHCREligible = readBoolean("HCR eligible", replyData); //$NON-NLS-1$
1143
fIsVersionKnown = readBoolean("version known", replyData); //$NON-NLS-1$
1144
fClassFileVersion = readInt("class file version", replyData); //$NON-NLS-1$
1145
fGotClassFileVersion = true;
1146            return fClassFileVersion;
1147        } catch (IOException JavaDoc e) {
1148            defaultIOExceptionHandler(e);
1149            return 0;
1150        } finally {
1151            handledJdwpRequest();
1152        }
1153    }
1154    
1155    /**
1156     * @return Returns whether the CRC-32 of the given reference type is known.
1157     */

1158    public boolean isVersionKnown() {
1159        getClassFileVersion();
1160        return fIsVersionKnown;
1161    }
1162    
1163    /**
1164     * @return Returns whether the reference type is HCR-eligible.
1165     */

1166    public boolean isHCREligible() {
1167        getClassFileVersion();
1168        return fIsHCREligible;
1169    }
1170    
1171    /**
1172     * Writes JDWP representation.
1173     */

1174    public void write(MirrorImpl target, DataOutputStream JavaDoc out) throws IOException JavaDoc {
1175        fReferenceTypeID.write(out);
1176        if (target.fVerboseWriter != null)
1177            target.fVerboseWriter.println("referenceType", fReferenceTypeID.value()); //$NON-NLS-1$
1178
}
1179    
1180    /**
1181     * Writes representation of null referenceType.
1182     */

1183    public static void writeNull(MirrorImpl target, DataOutputStream JavaDoc out) throws IOException JavaDoc {
1184        // create null id
1185
JdwpReferenceTypeID ID = new JdwpReferenceTypeID(target.virtualMachineImpl());
1186        ID.write(out);
1187        if (target.fVerboseWriter != null)
1188            target.fVerboseWriter.println("referenceType", ID.value()); //$NON-NLS-1$
1189
}
1190    
1191    /**
1192     * Writes JDWP representation.
1193     */

1194    public void writeWithTag(MirrorImpl target, DataOutputStream JavaDoc out) throws IOException JavaDoc {
1195        target.writeByte(typeTag(), "type tag", JdwpID.typeTagMap(), out); //$NON-NLS-1$
1196
write(target, out);
1197    }
1198    
1199    /**
1200     * @return Reads JDWP representation and returns new or cached instance.
1201     */

1202    public static ReferenceTypeImpl readWithTypeTag(MirrorImpl target, DataInputStream JavaDoc in) throws IOException JavaDoc {
1203        byte typeTag = target.readByte("type tag", JdwpID.typeTagMap(), in); //$NON-NLS-1$
1204
switch (typeTag) {
1205            case 0:
1206                return null;
1207            case ArrayTypeImpl.typeTag:
1208                return ArrayTypeImpl.read(target, in);
1209            case ClassTypeImpl.typeTag:
1210                return ClassTypeImpl.read(target, in);
1211            case InterfaceTypeImpl.typeTag:
1212                return InterfaceTypeImpl.read(target, in);
1213        }
1214        throw new InternalException(JDIMessages.ReferenceTypeImpl_Invalid_ReferenceTypeID_tag_encountered___8 + typeTag);
1215    }
1216    
1217    /**
1218     * @return Returns the Location objects for each executable source line in this reference type.
1219     */

1220    public List JavaDoc allLineLocations() throws AbsentInformationException {
1221        return allLineLocations(virtualMachine().getDefaultStratum(), null);
1222    }
1223    
1224    /**
1225     * @return Reads JDWP representation and returns new or cached instance.
1226     */

1227    public static ReferenceTypeImpl readWithTypeTagAndSignature(MirrorImpl target, boolean withGenericSignature, DataInputStream JavaDoc in) throws IOException JavaDoc {
1228        byte typeTag = target.readByte("type tag", JdwpID.typeTagMap(), in); //$NON-NLS-1$
1229
switch (typeTag) {
1230            case 0:
1231                return null;
1232            case ArrayTypeImpl.typeTag:
1233                return ArrayTypeImpl.readWithSignature(target, withGenericSignature, in);
1234            case ClassTypeImpl.typeTag:
1235                return ClassTypeImpl.readWithSignature(target, withGenericSignature, in);
1236            case InterfaceTypeImpl.typeTag:
1237                return InterfaceTypeImpl.readWithSignature(target, withGenericSignature, in);
1238        }
1239        throw new InternalException(JDIMessages.ReferenceTypeImpl_Invalid_ReferenceTypeID_tag_encountered___8 + typeTag);
1240    }
1241        
1242    /**
1243     * @return Returns new instance based on signature and classLoader.
1244     * @throws ClassNotLoadedException when the ReferenceType has not been loaded by the specified class loader.
1245     */

1246    public static TypeImpl create(VirtualMachineImpl vmImpl, String JavaDoc signature, ClassLoaderReference classLoader) throws ClassNotLoadedException {
1247        ReferenceTypeImpl refTypeBootstrap = null;
1248        List JavaDoc classes= vmImpl.classesBySignature(signature);
1249        ReferenceTypeImpl type;
1250        Iterator JavaDoc iter= classes.iterator();
1251        while (iter.hasNext()) {
1252            // First pass. Look for a class loaded by the given class loader
1253
type = (ReferenceTypeImpl)iter.next();
1254            if (type.classLoader() == null) { // bootstrap classloader
1255
if (classLoader == null) {
1256                    return type;
1257                }
1258                refTypeBootstrap = type;
1259            }
1260            if (classLoader != null && classLoader.equals(type.classLoader())) {
1261                return type;
1262            }
1263        }
1264        // If no ReferenceType is found with the specified classloader, but there is one with the
1265
// bootstrap classloader, the latter is returned.
1266
if (refTypeBootstrap != null) {
1267            return refTypeBootstrap;
1268        }
1269        
1270        List JavaDoc visibleTypes;
1271        iter= classes.iterator();
1272        while (iter.hasNext()) {
1273            // Second pass. Look for a class that is visible to
1274
// the given class loader
1275
type = (ReferenceTypeImpl)iter.next();
1276            visibleTypes= classLoader.visibleClasses();
1277            Iterator JavaDoc visibleIter= visibleTypes.iterator();
1278            while (visibleIter.hasNext()) {
1279                if (type.equals(visibleIter.next())) {
1280                    return type;
1281                }
1282            }
1283        }
1284
1285        throw new ClassNotLoadedException(classSignatureToName(signature), JDIMessages.ReferenceTypeImpl_Type_has_not_been_loaded_10);
1286    }
1287    
1288    /**
1289     * Retrieves constant mappings.
1290     */

1291    public static void getConstantMaps() {
1292        if (fgClassStatusStrings != null) {
1293            return;
1294        }
1295        
1296        java.lang.reflect.Field JavaDoc[] fields = ReferenceTypeImpl.class.getDeclaredFields();
1297        fgClassStatusStrings = new String JavaDoc[32];
1298        
1299        for (int i = 0; i < fields.length; i++) {
1300            java.lang.reflect.Field JavaDoc field = fields[i];
1301            if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0) {
1302                continue;
1303            }
1304                
1305            String JavaDoc name = field.getName();
1306            if (!name.startsWith("JDWP_CLASS_STATUS_")) { //$NON-NLS-1$
1307
continue;
1308            }
1309                
1310            name = name.substring(18);
1311            
1312            try {
1313                int value = field.getInt(null);
1314                
1315                for (int j = 0; j < fgClassStatusStrings.length; j++) {
1316                    if ((1 << j & value) != 0) {
1317                        fgClassStatusStrings[j]= name;
1318                        break;
1319                    }
1320                }
1321            } catch (IllegalAccessException JavaDoc e) {
1322                // Will not occur for own class.
1323
} catch (IllegalArgumentException JavaDoc e) {
1324                // Should not occur.
1325
// We should take care that all public static final constants
1326
// in this class are numbers that are convertible to int.
1327
}
1328        }
1329    }
1330    
1331    /**
1332     * @return Returns a map with string representations of tags.
1333     */

1334     public static String JavaDoc[] classStatusStrings() {
1335        getConstantMaps();
1336        return fgClassStatusStrings;
1337     }
1338     
1339    /**
1340     * @see TypeImpl#createNullValue()
1341     */

1342    public Value createNullValue() {
1343        return null;
1344    }
1345
1346    /**
1347     * @see ReferenceType#sourceNames(String)
1348     */

1349    public List JavaDoc sourceNames(String JavaDoc stratumId) throws AbsentInformationException {
1350        List JavaDoc list= new ArrayList JavaDoc();
1351        Stratum stratum= getStratum(stratumId);
1352        if (stratum != null) {
1353            // return the source names defined for this stratum in the SMAP.
1354
List JavaDoc fileInfos= stratum.fFileInfos;
1355            if (fileInfos.isEmpty()) {
1356                throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_30);
1357            }
1358            for (Iterator JavaDoc iter = stratum.fFileInfos.iterator(); iter.hasNext();) {
1359                list.add(((FileInfo) iter.next()).fFileName);
1360            }
1361            return list;
1362        }
1363        // Java stratum
1364
if (fSourceName == null) {
1365            getSourceName();
1366        }
1367        list.add(fSourceName);
1368        return list;
1369    }
1370
1371    /**
1372     * @see ReferenceType#sourcePaths(String)
1373     */

1374    public List JavaDoc sourcePaths(String JavaDoc stratumId) throws AbsentInformationException {
1375        List JavaDoc list= new ArrayList JavaDoc();
1376        Stratum stratum= getStratum(stratumId);
1377        if (stratum != null) {
1378            // return the source paths defined for this stratum in the SMAP.
1379
for (Iterator JavaDoc iter = stratum.fFileInfos.iterator(); iter.hasNext();) {
1380                FileInfo fileInfo= (FileInfo) iter.next();
1381                String JavaDoc path= fileInfo.fAbsoluteFileName;
1382                if (path == null) {
1383                    path= getPath(fileInfo.fFileName);
1384                }
1385                list.add(path);
1386            }
1387            return list;
1388        }
1389        // Java stratum
1390
if (fSourceName == null) {
1391            getSourceName();
1392        }
1393        list.add(getPath(fSourceName));
1394        return list;
1395    }
1396    
1397    /**
1398     * @see ReferenceType#sourceDebugExtension()
1399     */

1400    public String JavaDoc sourceDebugExtension() throws AbsentInformationException {
1401        if (isSourceDebugExtensionAvailable()) {
1402            return fSmap;
1403        }
1404        if (!virtualMachine().canGetSourceDebugExtension()) {
1405            throw new UnsupportedOperationException JavaDoc();
1406        }
1407        throw new AbsentInformationException();
1408    }
1409
1410    /**
1411     * @see ReferenceType#allLineLocations(String, String)
1412     */

1413    public List JavaDoc allLineLocations(String JavaDoc stratum, String JavaDoc sourceName) throws AbsentInformationException {
1414        Iterator JavaDoc allMethods = methods().iterator();
1415        if (stratum == null) { // if stratum not defined use the default stratum
1416
stratum= defaultStratum();
1417        }
1418        List JavaDoc allLineLocations= null;
1419        Map JavaDoc sourceNameAllLineLocations= null;
1420        if (fStratumAllLineLocations == null) { // the stratum map doesn't exist, create it
1421
fStratumAllLineLocations= new HashMap JavaDoc();
1422        } else {
1423            // get the source name map
1424
sourceNameAllLineLocations= (Map JavaDoc)fStratumAllLineLocations.get(stratum);
1425        }
1426        if (sourceNameAllLineLocations == null) { // the source name map doesn't exist, create it
1427
sourceNameAllLineLocations= new HashMap JavaDoc();
1428            fStratumAllLineLocations.put(stratum, sourceNameAllLineLocations);
1429        } else {
1430            // get the line locations
1431
allLineLocations= (List JavaDoc)sourceNameAllLineLocations.get(sourceName);
1432        }
1433        if (allLineLocations == null) { // the line locations are not know, compute and store them
1434
allLineLocations = new ArrayList JavaDoc();
1435            while (allMethods.hasNext()) {
1436                MethodImpl method = (MethodImpl)allMethods.next();
1437                if (method.isAbstract() || method.isNative()) {
1438                    continue;
1439                }
1440                allLineLocations.addAll(method.allLineLocations(stratum, sourceName));
1441            }
1442            sourceNameAllLineLocations.put(sourceName, allLineLocations);
1443        }
1444        return allLineLocations;
1445    }
1446
1447    /**
1448     * @see ReferenceType#locationsOfLine(String, String, int)
1449     */

1450    public List JavaDoc locationsOfLine(String JavaDoc stratum, String JavaDoc sourceName, int lineNumber) throws AbsentInformationException {
1451        Iterator JavaDoc allMethods = methods().iterator();
1452        List JavaDoc locations= new ArrayList JavaDoc();
1453        boolean hasLineInformation= false;
1454        AbsentInformationException exception= null;
1455        while (allMethods.hasNext()) {
1456            MethodImpl method = (MethodImpl)allMethods.next();
1457            if (method.isAbstract() || method.isNative()) {
1458                    continue;
1459            }
1460            // one line in the input source can be translate in multiple lines in different
1461
// methods in the output source. We need all these locations.
1462
try {
1463                locations.addAll(locationsOfLine(stratum, sourceName, lineNumber, method));
1464                hasLineInformation= true;
1465            } catch (AbsentInformationException e) {
1466                exception= e;
1467            }
1468        }
1469        if (!hasLineInformation && exception != null) {
1470            throw exception;
1471        }
1472        return locations;
1473    }
1474
1475    /**
1476     * @see ReferenceType#availableStrata()
1477     */

1478    public List JavaDoc availableStrata() {
1479        List JavaDoc list= new ArrayList JavaDoc();
1480        // The strata defined in the SMAP.
1481
if (isSourceDebugExtensionAvailable()) {
1482            list.addAll(fStrata.keySet());
1483        }
1484        // plus the Java stratum
1485
list.add(VirtualMachineImpl.JAVA_STRATUM_NAME);
1486        return list;
1487    }
1488
1489    /**
1490     * @see ReferenceType#defaultStratum()
1491     */

1492    public String JavaDoc defaultStratum() {
1493        if (isSourceDebugExtensionAvailable()) {
1494            return fDefaultStratumId;
1495        }
1496        // if not defined, return Java.
1497
return VirtualMachineImpl.JAVA_STRATUM_NAME;
1498    }
1499
1500    /**
1501     * Generate a source path from the given source name.
1502     * The returned string is the package name of this type converted to a platform dependent path
1503     * followed by the given source name.
1504     * For example, on a Unix platform, the type org.my.TestJsp with the source name test.jsp would
1505     * return "org/my/test.jsp".
1506     */

1507    private String JavaDoc getPath(String JavaDoc sourceName) {
1508        String JavaDoc name= name();
1509        int lastDotOffset= name.lastIndexOf('.');
1510        if (lastDotOffset == -1) {
1511            return sourceName;
1512        }
1513        char fileSeparator= System.getProperty("file.separator").charAt(0); //$NON-NLS-1$
1514
return name.substring(0, lastDotOffset).replace('.', fileSeparator) + fileSeparator + sourceName;
1515    }
1516
1517    /**
1518     * Return the stratum object for this stratum Id.
1519     * If the the specified stratum id is not defined for this reference type,
1520     * return the stratum object for the default stratum.
1521     * If the specified stratum id (or the default stratum id, if the specified
1522     * stratum id is not defined) is <code>Java</code>, return <code>null</code>.
1523     */

1524    private Stratum getStratum(String JavaDoc stratumId) {
1525        if (!VirtualMachineImpl.JAVA_STRATUM_NAME.equals(stratumId) && isSourceDebugExtensionAvailable()) {
1526            if (stratumId == null || !fStrata.keySet().contains(stratumId)) {
1527                stratumId= fDefaultStratumId;
1528            }
1529            if (!VirtualMachineImpl.JAVA_STRATUM_NAME.equals(stratumId)) {
1530                return (Stratum)fStrata.get(stratumId);
1531            }
1532        }
1533        return null;
1534    }
1535
1536    /**
1537     * Get the source debug extension from the VM.
1538     * @throws AbsentInformationException
1539     */

1540    private void getSourceDebugExtension() throws AbsentInformationException {
1541        initJdwpRequest();
1542        try {
1543            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SOURCE_DEBUG_EXTENSION, this);
1544            if (replyPacket.errorCode() == JdwpReplyPacket.ABSENT_INFORMATION) {
1545                throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_31);
1546            }
1547            defaultReplyErrorHandler(replyPacket.errorCode());
1548            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1549            fSmap= readString(JDIMessages.ReferenceTypeImpl_32, replyData);
1550        } catch (IOException JavaDoc e) {
1551            defaultIOExceptionHandler(e);
1552        } finally {
1553            handledJdwpRequest();
1554        }
1555        // TODO: remove the workaround when the J9SC20030415 bug is fixed (see bug 96485 of the vendor bug system).
1556
// Workaround to a J9SC bug. It returns an empty string instead of a ABSENT_INFORMATION
1557
// error if the source debug extension is not available.
1558
if ("".equals(fSmap)) { //$NON-NLS-1$
1559
throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_31);
1560        }
1561        // parse the source map.
1562
fStrata= new HashMap JavaDoc();
1563        SourceDebugExtensionParser.parse(fSmap, this);
1564    }
1565    
1566    /**
1567     * Get the name of the Java source file from the VM.
1568     * @throws AbsentInformationException
1569     */

1570    private void getSourceName() throws AbsentInformationException {
1571        if (fSourceName != null || isSourceDebugExtensionAvailable()) {
1572            return;
1573        }
1574        initJdwpRequest();
1575        try {
1576            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SOURCE_FILE, this);
1577            if (replyPacket.errorCode() == JdwpReplyPacket.ABSENT_INFORMATION) {
1578                throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_Source_name_is_not_known_7);
1579            }
1580            
1581            defaultReplyErrorHandler(replyPacket.errorCode());
1582        
1583            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1584            fSourceName = readString("source name", replyData); //$NON-NLS-1$
1585
} catch (IOException JavaDoc e) {
1586            defaultIOExceptionHandler(e);
1587        } finally {
1588            handledJdwpRequest();
1589        }
1590    }
1591
1592    /**
1593     * Check in the source debug extension is available.
1594     * To call before doing operations which need data from the SMAP.
1595     * Return <code>false</code> if the source debug extension is not available
1596     * for any reason. <code>true</code> indicates that the source debug extension
1597     * is available and the information has been parsed and stored in the
1598     * maps and lists.
1599     */

1600    private synchronized boolean isSourceDebugExtensionAvailable() {
1601        if (!fSourceDebugExtensionAvailable) {
1602            return false;
1603        }
1604        if (!virtualMachine().canGetSourceDebugExtension()) {
1605            fSourceDebugExtensionAvailable= false;
1606            return false;
1607        }
1608        if (fSmap == null) {
1609            try {
1610                 getSourceDebugExtension();
1611            } catch (AbsentInformationException e) {
1612                fSourceDebugExtensionAvailable= false;
1613                return false;
1614            }
1615        }
1616        return true;
1617    }
1618
1619    /**
1620     * Set the output file name, i.e. the .java file used to generate
1621     * the bytecode.
1622     */

1623    protected void setOutputFileName(String JavaDoc outputFileName) {
1624        fSourceName= outputFileName;
1625    }
1626    
1627    /**
1628     * Set the default stratum. This stratum will be used for the method
1629     * on strata related data, but with no stratum parameter.
1630     */

1631    protected void setDefaultStratumId(String JavaDoc defaultStratumId) {
1632        fDefaultStratumId= defaultStratumId;
1633    }
1634    
1635    /**
1636     * Add a new stratum to this type.
1637     */

1638    protected void addStratum(Stratum stratum) {
1639        fStrata.put(stratum.fId, stratum);
1640    }
1641
1642    /**
1643     * Return the name of the input source file of which the given code index
1644     * is part of the translation, for this stratum.
1645     * If the code at the given index is not a part of the translation of
1646     * the given stratum code, return the name of the primary input source file.
1647     *
1648     * @param codeIndex the index of the code.
1649     * @param method the method where is the code.
1650     * @param stratumId
1651     */

1652    protected String JavaDoc sourceName(long codeIndex, MethodImpl method, String JavaDoc stratumId) throws AbsentInformationException {
1653        Stratum stratum= getStratum(stratumId);
1654        if (stratum != null) {
1655            FileInfo fileInfo= fileInfo(codeIndex, method, stratum);
1656            if (fileInfo != null) {
1657                return fileInfo.fFileName;
1658            }
1659        }
1660        // Java stratum
1661
if (fSourceName == null) {
1662            getSourceName();
1663        }
1664        return fSourceName;
1665    }
1666    
1667    /**
1668     * Return the FileInfo object of the input source file of which the given code index
1669     * is part of the translation, for this stratum.
1670     * If the code at the given index is not a part of the translation of
1671     * the given stratum code, return the FileInfo of the primary input source file.
1672     *
1673     * @param codeIndex the index of the code.
1674     * @param method the method where is the code.
1675     * @param stratum
1676     */

1677    private FileInfo fileInfo(long codeIndex, MethodImpl method, Stratum stratum) {
1678        int fileId= stratum.fPrimaryFileId;
1679        if (stratum.fFileInfos.size() > 1) {
1680            List JavaDoc lineInfos= null;
1681            try {
1682                lineInfos = lineInfos(codeIndex, method, stratum);
1683            } catch (AbsentInformationException e) {
1684                // nothing to do, use the primary file id.
1685
}
1686            if (lineInfos != null) {
1687                fileId= ((int[])lineInfos.get(0))[0];
1688            }
1689        }
1690        for (Iterator JavaDoc iter = stratum.fFileInfos.iterator(); iter.hasNext();) {
1691            FileInfo fileInfo = (FileInfo)iter.next();
1692            if (fileInfo.fFileId == fileId) {
1693                return fileInfo;
1694            }
1695        }
1696        // should never return null
1697
return null;
1698    }
1699
1700    /**
1701     * Return the list of line number in the input files of the stratum associated
1702     * with the code at the given address.
1703     *
1704     * @param codeIndex the index of the code.
1705     * @param method the method where is the code.
1706     * @param stratum
1707     * @return List of int[2]: [fileId, inputLineNumber]
1708     */

1709    private List JavaDoc lineInfos(long codeIndex, MethodImpl method, Stratum stratum) throws AbsentInformationException {
1710        int outputLineNumber= -1;
1711        try {
1712            outputLineNumber = method.javaStratumLineNumber(codeIndex);
1713        } catch (NativeMethodException e) { // Occurs in SUN VM.
1714
return null;
1715        }
1716        if (outputLineNumber != -1) {
1717            return stratum.getInputLineInfos(outputLineNumber);
1718        }
1719        return null;
1720    }
1721
1722    /**
1723     * Return the path of the input source file of which the given code index
1724     * is part of the translation, for this stratum.
1725     * If the code at the given index is not a part of the translation of
1726     * the given stratum code, return the path of the primary input source file.
1727     *
1728     * @param codeIndex the index of the code.
1729     * @param method the method where is the code.
1730     * @param stratumId
1731     */

1732    protected String JavaDoc sourcePath(long codeIndex, MethodImpl method, String JavaDoc stratumId) throws AbsentInformationException {
1733        Stratum stratum= getStratum(stratumId);
1734        if (stratum != null) {
1735            FileInfo fileInfo= fileInfo(codeIndex, method, stratum);
1736            if (fileInfo != null) {
1737                String JavaDoc path= fileInfo.fAbsoluteFileName;
1738                if (path == null) {
1739                    return getPath(fileInfo.fFileName);
1740                }
1741                return path;
1742            }
1743        }
1744        // Java stratum
1745
if (fSourceName == null) {
1746            getSourceName();
1747        }
1748        return getPath(fSourceName);
1749    }
1750
1751    /**
1752     * Return the number of the line of which the given code index
1753     * is part of the translation, for this stratum.
1754     *
1755     * @param codeIndex the index of the code.
1756     * @param method the method where is the code.
1757     * @param stratumId
1758     */

1759    protected int lineNumber(long codeIndex, MethodImpl method, String JavaDoc stratumId) {
1760        Stratum stratum= getStratum(stratumId);
1761        try {
1762            if (stratum != null) {
1763                List JavaDoc lineInfos = lineInfos(codeIndex, method, stratum);
1764                if (lineInfos != null) {
1765                    return ((int[])lineInfos.get(0))[1];
1766                }
1767                return LocationImpl.LINE_NR_NOT_AVAILABLE;
1768            }
1769            // Java stratum
1770
try {
1771                return method.javaStratumLineNumber(codeIndex);
1772            } catch (NativeMethodException e) { // Occurs in SUN VM.
1773
return LocationImpl.LINE_NR_NOT_AVAILABLE;
1774            }
1775        } catch (AbsentInformationException e) {
1776            return LocationImpl.LINE_NR_NOT_AVAILABLE;
1777        }
1778    }
1779
1780    /**
1781     * Return the location which are part of the translation of the given line,
1782     * in the given stratum in the source file with the given source name.
1783     * If sourceName is <code>null</code>, return the locations for all source file
1784     * in the given stratum.
1785     * The returned location are in the given method.
1786     *
1787     * @param stratumId the stratum id.
1788     * @param sourceName the name of the source file.
1789     * @param lineNumber the number of the line.
1790     * @param method
1791     * @throws AbsentInformationException if the specified sourceName is not valid.
1792     */

1793    public List JavaDoc locationsOfLine(String JavaDoc stratumId, String JavaDoc sourceName, int lineNumber, MethodImpl method) throws AbsentInformationException {
1794        Stratum stratum= getStratum(stratumId);
1795        List JavaDoc javaLines= new ArrayList JavaDoc();
1796        if (stratum != null) {
1797            boolean found= false;
1798            for (Iterator JavaDoc iter = stratum.fFileInfos.iterator(); iter.hasNext() && !found;) {
1799                FileInfo fileInfo = (FileInfo)iter.next();
1800                if (sourceName == null || (found= sourceName.equals(fileInfo.fFileName))) {
1801                    javaLines.addAll(fileInfo.getOutputLinesForLine(lineNumber));
1802                }
1803            }
1804            if (sourceName != null && !found) {
1805                throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_34);
1806            }
1807        } else { // Java stratum
1808
javaLines.add(new Integer JavaDoc(lineNumber));
1809        }
1810        return method.javaStratumLocationsOfLines(javaLines);
1811    }
1812
1813    /**
1814     * Return the locations of all lines in the given source file of the given stratum which
1815     * are included in the given method.
1816     * If sourceName is <code>null</code>, return the locations for all source file
1817     * in the given stratum.
1818     *
1819     * @param stratumId the stratum id
1820     * @param sourceName the name of the source file
1821     * @param method
1822     * @param codeIndexTable the list of code indexes for the method, as get from the VM/JDWP
1823     * @param javaStratumLineNumberTable the list of line numbers in the java stratum for the method, as get from the VM/JDWP
1824     * @return
1825     */

1826    public List JavaDoc allLineLocations(String JavaDoc stratumId, String JavaDoc sourceName, MethodImpl method, long[] codeIndexTable, int[] javaStratumLineNumberTable) throws AbsentInformationException {
1827        Stratum stratum= getStratum(stratumId);
1828        if (stratum != null) {
1829            int[][] lineInfoTable= new int[codeIndexTable.length][];
1830            if (sourceName == null) {
1831                int lastIndex=0;
1832                for (int i = 0, length= javaStratumLineNumberTable.length; i < length; i++) {
1833                    // for each executable line in the java source, get the associated lines in the stratum source
1834
List JavaDoc lineInfos= stratum.getInputLineInfos(javaStratumLineNumberTable[i]);
1835                    if (lineInfos != null) {
1836                        int[] lineInfo= (int[])lineInfos.get(0);
1837                        if (!lineInfo.equals(lineInfoTable[lastIndex])) {
1838                            lineInfoTable[i]= lineInfo;
1839                            lastIndex= i;
1840                        }
1841                    }
1842                }
1843            } else { // sourceName != null
1844
FileInfo fileInfo= stratum.getFileInfo(sourceName);
1845                if (fileInfo == null) {
1846                    throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_34);
1847                }
1848                int fileId= fileInfo.fFileId;
1849                int lastIndex= 0;
1850                for (int i = 0, length= javaStratumLineNumberTable.length; i < length; i++) {
1851                    List JavaDoc lineInfos= stratum.getInputLineInfos(javaStratumLineNumberTable[i]);
1852                    if (lineInfos != null) {
1853                        for (Iterator JavaDoc iter = lineInfos.iterator(); iter.hasNext();) {
1854                            int[] lineInfo= (int[])iter.next();
1855                            if (lineInfo[0] == fileId) {
1856                                if (!lineInfo.equals(lineInfoTable[lastIndex])) {
1857                                    lineInfoTable[i]= lineInfo;
1858                                    lastIndex= i;
1859                                }
1860                                break;
1861                            }
1862                        }
1863                    }
1864                }
1865            }
1866            List JavaDoc locations= new ArrayList JavaDoc();
1867            for (int i = 0, length= lineInfoTable.length; i < length; i++) {
1868                if (lineInfoTable[i] != null) {
1869                    locations.add(new LocationImpl(virtualMachineImpl(), method, codeIndexTable[i]));
1870                }
1871            }
1872            return locations;
1873        }
1874        // Java stratum
1875
List JavaDoc result = new ArrayList JavaDoc();
1876        for (int i = 0; i < codeIndexTable.length; i++) {
1877            result.add(new LocationImpl(virtualMachineImpl(), method, codeIndexTable[i]));
1878        }
1879        return result;
1880    }
1881    
1882    /*
1883     * @since 3.0
1884     * @since java 1.5
1885     */

1886    public String JavaDoc genericSignature() {
1887        if (fGenericSignatureKnown) {
1888            return fGenericSignature;
1889        }
1890        if (virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5)) {
1891            initJdwpRequest();
1892            try {
1893                JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SIGNATURE_WITH_GENERIC, this);
1894                defaultReplyErrorHandler(replyPacket.errorCode());
1895                DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1896                setSignature(readString("signature", replyData)); //$NON-NLS-1$
1897
fGenericSignature= readString("generic signature", replyData); //$NON-NLS-1$
1898
if (fGenericSignature.length() == 0) {
1899                    fGenericSignature= null;
1900                }
1901                fGenericSignatureKnown= true;
1902            } catch (IOException JavaDoc e) {
1903                defaultIOExceptionHandler(e);
1904                return null;
1905            } finally {
1906                handledJdwpRequest();
1907            }
1908        } else {
1909            fGenericSignatureKnown= true;
1910        }
1911        return fGenericSignature;
1912    }
1913    
1914    /**
1915     * if genericSignature is <code>null</code>, the generic signature is set to not-known
1916     * (genericSignature() will ask the VM for the generic signature)
1917     * if genericSignature is an empty String, the generic signature is set to no-generic-signature
1918     * (genericSignature() will return null)
1919     * if genericSignature is an non-empty String, the generic signature is set to the specified value
1920     * (genericSignature() will return the specified value)
1921     * @since 3.0
1922     */

1923    public void setGenericSignature(String JavaDoc genericSignature) {
1924        if (genericSignature == null) {
1925            fGenericSignature= null;
1926            fGenericSignatureKnown= false;
1927        } else {
1928            if (genericSignature.length() == 0) {
1929                fGenericSignature= null;
1930            } else {
1931                fGenericSignature= genericSignature;
1932            }
1933            fGenericSignatureKnown= true;
1934        }
1935    }
1936
1937    /**
1938     * @see com.sun.jdi.ReferenceType#instances(long)
1939     * @since 3.3
1940     */

1941    public List JavaDoc instances(long maxInstances) {
1942        try {
1943            int max = (int)maxInstances;
1944            if (maxInstances >= Integer.MAX_VALUE) {
1945                max = Integer.MAX_VALUE;
1946            }
1947            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1948            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1949            write(this, outData);
1950            writeInt(max, "max instances", outData); //$NON-NLS-1$
1951

1952            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_INSTANCES, outBytes);
1953            switch(replyPacket.errorCode()) {
1954                case JdwpReplyPacket.INVALID_OBJECT:
1955                case JdwpReplyPacket.INVALID_CLASS:
1956                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
1957                case JdwpReplyPacket.NOT_IMPLEMENTED:
1958                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_27);
1959                case JdwpReplyPacket.ILLEGAL_ARGUMENT:
1960                    throw new IllegalArgumentException JavaDoc(JDIMessages.ReferenceTypeImpl_26);
1961                case JdwpReplyPacket.VM_DEAD:
1962                    throw new VMDisconnectedException(JDIMessages.vm_dead);
1963            }
1964            defaultReplyErrorHandler(replyPacket.errorCode());
1965            
1966            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1967            int elements = readInt("element count", replyData); //$NON-NLS-1$
1968
if(max > 0 && elements > max) {
1969                elements = max;
1970            }
1971            ArrayList JavaDoc list = new ArrayList JavaDoc();
1972            for(int i = 0; i < elements; i++) {
1973                list.add(ValueImpl.readWithTag(this, replyData));
1974            }
1975            return list;
1976        }
1977        catch(IOException JavaDoc e) {
1978            defaultIOExceptionHandler(e);
1979            return null;
1980        } finally {
1981            handledJdwpRequest();
1982        }
1983    }
1984    
1985    /**
1986     * @see com.sun.jdi.ReferenceType#majorVersion()
1987     * @since 3.3
1988     */

1989    public int majorVersion() {
1990        try {
1991            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1992            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1993            getRefTypeID().write(outData);
1994            
1995            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_VERSION, outBytes);
1996            switch(replyPacket.errorCode()) {
1997                case JdwpReplyPacket.INVALID_CLASS:
1998                case JdwpReplyPacket.INVALID_OBJECT:
1999                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
2000                case JdwpReplyPacket.ABSENT_INFORMATION:
2001                    return 0;
2002                case JdwpReplyPacket.NOT_IMPLEMENTED:
2003                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_no_class_version_support24);
2004                case JdwpReplyPacket.VM_DEAD:
2005                    throw new VMDisconnectedException(JDIMessages.vm_dead);
2006            }
2007            defaultReplyErrorHandler(replyPacket.errorCode());
2008            
2009            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
2010            return readInt("major version", replyData); //$NON-NLS-1$
2011
}
2012        catch(IOException JavaDoc e) {
2013            defaultIOExceptionHandler(e);
2014            return 0;
2015        } finally {
2016            handledJdwpRequest();
2017        }
2018    }
2019    
2020    /**
2021     * @see com.sun.jdi.ReferenceType#minorVersion()
2022     * @since 3.3
2023     */

2024    public int minorVersion() {
2025        try {
2026            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
2027            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
2028            getRefTypeID().write(outData);
2029            
2030            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_VERSION, outBytes);
2031            switch(replyPacket.errorCode()) {
2032                case JdwpReplyPacket.INVALID_CLASS:
2033                case JdwpReplyPacket.INVALID_OBJECT:
2034                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
2035                case JdwpReplyPacket.ABSENT_INFORMATION:
2036                    return 0;
2037                case JdwpReplyPacket.NOT_IMPLEMENTED:
2038                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_no_class_version_support24);
2039                case JdwpReplyPacket.VM_DEAD:
2040                    throw new VMDisconnectedException(JDIMessages.vm_dead);
2041            }
2042            defaultReplyErrorHandler(replyPacket.errorCode());
2043            
2044            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
2045            readInt("major version", replyData); //$NON-NLS-1$
2046
return readInt("minor version", replyData); //$NON-NLS-1$
2047
}
2048        catch(IOException JavaDoc e) {
2049            defaultIOExceptionHandler(e);
2050            return 0;
2051        } finally {
2052            handledJdwpRequest();
2053        }
2054    }
2055    
2056    /**
2057     * @see com.sun.jdi.ReferenceType#constantPoolCount()
2058     * @since 3.3
2059     */

2060    public int constantPoolCount() {
2061        try {
2062            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
2063            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
2064            this.getRefTypeID().write(outData);
2065            
2066            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CONSTANT_POOL, outBytes);
2067            switch(replyPacket.errorCode()) {
2068                case JdwpReplyPacket.INVALID_CLASS:
2069                case JdwpReplyPacket.INVALID_OBJECT:
2070                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
2071                case JdwpReplyPacket.ABSENT_INFORMATION:
2072                    return 0;
2073                case JdwpReplyPacket.NOT_IMPLEMENTED:
2074                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_no_constant_pool_support);
2075                case JdwpReplyPacket.VM_DEAD:
2076                    throw new VMDisconnectedException(JDIMessages.vm_dead);
2077            }
2078            defaultReplyErrorHandler(replyPacket.errorCode());
2079            
2080            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
2081            return readInt("pool count", replyData); //$NON-NLS-1$
2082
}
2083        catch(IOException JavaDoc e) {
2084            defaultIOExceptionHandler(e);
2085            return 0;
2086        } finally {
2087            handledJdwpRequest();
2088        }
2089    }
2090    
2091    /**
2092     * @see com.sun.jdi.ReferenceType#constantPool()
2093     * @since 3.3
2094     */

2095    public byte[] constantPool() {
2096        try {
2097            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
2098            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
2099            this.getRefTypeID().write(outData);
2100            
2101            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CONSTANT_POOL, outBytes);
2102            switch(replyPacket.errorCode()) {
2103                case JdwpReplyPacket.INVALID_CLASS:
2104                case JdwpReplyPacket.INVALID_OBJECT:
2105                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
2106                case JdwpReplyPacket.ABSENT_INFORMATION:
2107                    return new byte[0];
2108                case JdwpReplyPacket.NOT_IMPLEMENTED:
2109                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_no_constant_pool_support);
2110                case JdwpReplyPacket.VM_DEAD:
2111                    throw new VMDisconnectedException(JDIMessages.vm_dead);
2112            }
2113            defaultReplyErrorHandler(replyPacket.errorCode());
2114            
2115            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
2116            readInt("pool count", replyData); //$NON-NLS-1$
2117
int bytes = readInt("byte count", replyData); //$NON-NLS-1$
2118
byte[] array = new byte[bytes];
2119            for (int i = 0; i < bytes; i++) {
2120                array[i] = readByte("byte read", replyData); //$NON-NLS-1$
2121
}
2122            return array;
2123        }
2124        catch(IOException JavaDoc e) {
2125            defaultIOExceptionHandler(e);
2126            return null;
2127        } finally {
2128            handledJdwpRequest();
2129        }
2130    }
2131}
2132
Popular Tags