FileDocCategorySizeDatePackage
LinkMessage.javaAPI DocphoneME MR2 API (J2ME)4842Wed May 02 18:00:02 BST 2007com.sun.midp.links

LinkMessage

public class LinkMessage extends Object
Encapsulates some data to be sent between Isolates through a Link.

Fields Summary
Object
contents
int
offset
int
length
Constructors Summary
private LinkMessage(Object newContents, int newOffset, int newLength)
Constructs a LinkMessage with the given contents, length, and offset values. Called only by the static factory methods.

        contents = newContents;
        offset = newOffset;
        length = newLength;
    
LinkMessage()
Constructs an empty LinkMessage. This is used only by Link.receive().

        this(null, 0, 0);
    
Methods Summary
public booleancontainsData()
Queries whether the LinkMessage contains data, that is, a byte array.

        return contents instanceof byte[];
    
public booleancontainsLink()
Queries whether the LinkMessage contains a Link.

        return contents instanceof Link;
    
public booleancontainsString()
Queries whether the LinkMessage contains a String.

        return contents instanceof String;
    
public java.lang.Objectextract()
Returns the contents of the LinkMessage as an Object. The caller must test the reference returned using instanceof and cast it appropriately.

        return contents;
    
public byte[]extractData()
Returns the contents of the LinkMessage if it contains a byte array. If the message does not contain a byte array, throws IllegalStateException.

        if (! (contents instanceof byte[])) {
            throw new IllegalStateException();
        }

        byte[] data = (byte[])contents;

        if (offset == 0 && length == data.length) {
            return data;
        }

        // need to copy the subrange

        byte[] newData = new byte[length];
        System.arraycopy(data, offset, newData, 0, length);
        return newData;
    
public LinkextractLink()
Returns the contents of the LinkMessage if it contains is a Link. If the message does not contain a Link, throws IllegalStateException.

        if (contents instanceof Link) {
            return (Link)contents;
        } else {
            throw new IllegalStateException();
        }
    
public java.lang.StringextractString()
Returns the contents of the LinkMessage if it contains is a String. If the message does not contain a String, throws IllegalStateException.

        if (contents instanceof String) {
            return (String)contents;
        } else {
            throw new IllegalStateException();
        }
    
public static com.sun.midp.links.LinkMessagenewDataMessage(byte[] data)

        return new LinkMessage(data, 0, data.length);
    
public static com.sun.midp.links.LinkMessagenewDataMessage(byte[] data, int offset, int length)

        if (offset < 0
                || offset > data.length
                || length < 0
                || offset + length < 0
                || offset + length > data.length) {
            throw new IndexOutOfBoundsException();
        }

        return new LinkMessage(data, offset, length);
    
public static com.sun.midp.links.LinkMessagenewLinkMessage(Link link)

        return new LinkMessage(link, 0, 0);
    
public static com.sun.midp.links.LinkMessagenewStringMessage(java.lang.String string)

        return new LinkMessage(string, 0, 0);