1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.DataInputStream ; 15 import java.io.IOException ; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.eclipse.jdi.internal.jdwp.JdwpClassLoaderID; 21 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket; 22 import org.eclipse.jdi.internal.jdwp.JdwpID; 23 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket; 24 25 import com.sun.jdi.ClassLoaderReference; 26 import com.sun.jdi.ClassNotPreparedException; 27 import com.sun.jdi.ReferenceType; 28 29 35 public class ClassLoaderReferenceImpl extends ObjectReferenceImpl implements ClassLoaderReference { 36 37 public static final byte tag = JdwpID.CLASS_LOADER_TAG; 38 39 42 public ClassLoaderReferenceImpl(VirtualMachineImpl vmImpl, JdwpClassLoaderID classLoaderID) { 43 super("ClassLoaderReference", vmImpl, classLoaderID); } 45 46 49 public byte getTag() { 50 return tag; 51 } 52 53 56 public List definedClasses() { 57 List visibleClasses= visibleClasses(); 59 List result = new ArrayList (visibleClasses.size()); 60 Iterator iter = visibleClasses.iterator(); 61 while (iter.hasNext()) { 62 try { 63 ReferenceType type = (ReferenceType)iter.next(); 64 if (type.classLoader() != null && type.classLoader().equals(this)) 66 result.add(type); 67 } catch (ClassNotPreparedException e) { 68 continue; 69 } 70 } 71 return result; 72 } 73 74 77 public List visibleClasses() { 78 initJdwpRequest(); 80 try { 81 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.CLR_VISIBLE_CLASSES, this); 82 defaultReplyErrorHandler(replyPacket.errorCode()); 83 DataInputStream replyData = replyPacket.dataInStream(); 84 int nrOfElements = readInt("elements", replyData); List elements = new ArrayList (nrOfElements); 86 for (int i = 0; i < nrOfElements; i++) { 87 ReferenceTypeImpl elt = ReferenceTypeImpl.readWithTypeTag(this, replyData); 88 if (elt == null) 89 continue; 90 elements.add(elt); 91 } 92 return elements; 93 } catch (IOException e) { 94 defaultIOExceptionHandler(e); 95 return null; 96 } finally { 97 handledJdwpRequest(); 98 } 99 } 100 101 104 public static ClassLoaderReferenceImpl read(MirrorImpl target, DataInputStream in) throws IOException { 105 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 106 JdwpClassLoaderID ID = new JdwpClassLoaderID(vmImpl); 107 ID.read(in); 108 if (target.fVerboseWriter != null) 109 target.fVerboseWriter.println("classLoaderReference", ID.value()); 111 if (ID.isNull()) 112 return null; 113 114 ClassLoaderReferenceImpl mirror = new ClassLoaderReferenceImpl(vmImpl, ID); 115 return mirror; 116 } 117 } 118 | Popular Tags |