001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdi.internal;
011:
012: import java.io.DataInputStream;
013: import java.io.IOException;
014:
015: import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket;
016: import org.eclipse.jdi.internal.jdwp.JdwpID;
017: import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket;
018: import org.eclipse.jdi.internal.jdwp.JdwpStringID;
019:
020: import com.sun.jdi.ObjectCollectedException;
021: import com.sun.jdi.StringReference;
022:
023: /**
024: * this class implements the corresponding interfaces
025: * declared by the JDI specification. See the com.sun.jdi package
026: * for more information.
027: *
028: */
029: public class StringReferenceImpl extends ObjectReferenceImpl implements
030: StringReference {
031: /** JDWP Tag. */
032: public static final byte tag = JdwpID.STRING_TAG;
033:
034: /**
035: * Creates new StringReferenceImpl.
036: */
037: public StringReferenceImpl(VirtualMachineImpl vmImpl,
038: JdwpStringID stringID) {
039: super ("StringReference", vmImpl, stringID); //$NON-NLS-1$
040: }
041:
042: /**
043: * @returns Value tag.
044: */
045: public byte getTag() {
046: return tag;
047: }
048:
049: /**
050: * @returns Returns the StringReference as a String.
051: */
052: public String value() {
053: // Note that this information should not be cached.
054: initJdwpRequest();
055: try {
056: JdwpReplyPacket replyPacket = requestVM(
057: JdwpCommandPacket.SR_VALUE, this );
058: defaultReplyErrorHandler(replyPacket.errorCode());
059:
060: DataInputStream replyData = replyPacket.dataInStream();
061: String result = readString("value", replyData); //$NON-NLS-1$
062: return result;
063: } catch (IOException e) {
064: defaultIOExceptionHandler(e);
065: return null;
066: } finally {
067: handledJdwpRequest();
068: }
069: }
070:
071: /**
072: * @return Reads JDWP representation and returns new instance.
073: */
074: public static StringReferenceImpl read(MirrorImpl target,
075: DataInputStream in) throws IOException {
076: VirtualMachineImpl vmImpl = target.virtualMachineImpl();
077: JdwpStringID ID = new JdwpStringID(vmImpl);
078: ID.read(in);
079: if (target.fVerboseWriter != null)
080: target.fVerboseWriter
081: .println("stringReference", ID.value()); //$NON-NLS-1$
082:
083: if (ID.isNull())
084: return null;
085:
086: StringReferenceImpl mirror = new StringReferenceImpl(vmImpl, ID);
087: return mirror;
088: }
089:
090: /**
091: * @return Returns description of Mirror object.
092: */
093: public String toString() {
094: try {
095: return "\"" + value() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
096: } catch (ObjectCollectedException e) {
097: return JDIMessages.StringReferenceImpl__Garbage_Collected__StringReference__3
098: + idString();
099: } catch (Exception e) {
100: return fDescription;
101: }
102: }
103: }
|