KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.jdi.internal;
12
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
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 /**
26  * this class implements the corresponding interfaces
27  * declared by the JDI specification. See the com.sun.jdi package
28  * for more information.
29  *
30  */

31 public class StringReferenceImpl extends ObjectReferenceImpl implements StringReference {
32     /** JDWP Tag. */
33     public static final byte tag = JdwpID.STRING_TAG;
34
35     /**
36      * Creates new StringReferenceImpl.
37      */

38     public StringReferenceImpl(VirtualMachineImpl vmImpl, JdwpStringID stringID) {
39         super("StringReference", vmImpl, stringID); //$NON-NLS-1$
40
}
41
42     /**
43      * @returns Value tag.
44      */

45     public byte getTag() {
46         return tag;
47     }
48     
49     /**
50      * @returns Returns the StringReference as a String.
51      */

52     public String JavaDoc value() {
53         // Note that this information should not be cached.
54
initJdwpRequest();
55         try {
56             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.SR_VALUE, this);
57             defaultReplyErrorHandler(replyPacket.errorCode());
58             
59             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
60             String JavaDoc result = readString("value", replyData); //$NON-NLS-1$
61
return result;
62         } catch (IOException JavaDoc e) {
63             defaultIOExceptionHandler(e);
64             return null;
65         } finally {
66             handledJdwpRequest();
67         }
68     }
69     
70     /**
71      * @return Reads JDWP representation and returns new instance.
72      */

73     public static StringReferenceImpl read(MirrorImpl target, DataInputStream JavaDoc in) throws IOException JavaDoc {
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()); //$NON-NLS-1$
79

80         if (ID.isNull())
81             return null;
82
83         StringReferenceImpl mirror = new StringReferenceImpl(vmImpl, ID);
84         return mirror;
85     }
86     
87     /**
88      * @return Returns description of Mirror object.
89      */

90     public String JavaDoc toString() {
91         try {
92             return "\"" + value() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
93
} catch (ObjectCollectedException e) {
94             return JDIMessages.StringReferenceImpl__Garbage_Collected__StringReference__3 + idString();
95         } catch (Exception JavaDoc e) {
96             return fDescription;
97         }
98     }
99 }
100
Popular Tags