1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.DataInputStream ; 15 import java.io.IOException ; 16 17 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket; 18 import org.eclipse.jdi.internal.jdwp.JdwpID; 19 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket; 20 import org.eclipse.jdi.internal.jdwp.JdwpStringID; 21 22 import com.sun.jdi.ObjectCollectedException; 23 import com.sun.jdi.StringReference; 24 25 31 public class StringReferenceImpl extends ObjectReferenceImpl implements StringReference { 32 33 public static final byte tag = JdwpID.STRING_TAG; 34 35 38 public StringReferenceImpl(VirtualMachineImpl vmImpl, JdwpStringID stringID) { 39 super("StringReference", vmImpl, stringID); } 41 42 45 public byte getTag() { 46 return tag; 47 } 48 49 52 public String value() { 53 initJdwpRequest(); 55 try { 56 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.SR_VALUE, this); 57 defaultReplyErrorHandler(replyPacket.errorCode()); 58 59 DataInputStream replyData = replyPacket.dataInStream(); 60 String result = readString("value", replyData); return result; 62 } catch (IOException e) { 63 defaultIOExceptionHandler(e); 64 return null; 65 } finally { 66 handledJdwpRequest(); 67 } 68 } 69 70 73 public static StringReferenceImpl read(MirrorImpl target, DataInputStream in) throws IOException { 74 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 75 JdwpStringID ID = new JdwpStringID(vmImpl); 76 ID.read(in); 77 if (target.fVerboseWriter != null) 78 target.fVerboseWriter.println("stringReference", ID.value()); 80 if (ID.isNull()) 81 return null; 82 83 StringReferenceImpl mirror = new StringReferenceImpl(vmImpl, ID); 84 return mirror; 85 } 86 87 90 public String toString() { 91 try { 92 return "\"" + value() + "\""; } catch (ObjectCollectedException e) { 94 return JDIMessages.StringReferenceImpl__Garbage_Collected__StringReference__3 + idString(); 95 } catch (Exception e) { 96 return fDescription; 97 } 98 } 99 } 100 | Popular Tags |